Get the App
SLTechnology News&Howtos  ›  Servers  › 

Rsync configuration and Automation execution

Shulou Source: shulou.com Published: 2022-06-03 06:54:40 09月21日 Update

Rsync is a data mirroring backup tool-remote sync under unix-like systems. A fast incremental backup tool Remote Sync, remote synchronization supports local replication, or synchronization with other SSH, rsync hosts. Let's first understand the syntax of rsync, and then configure rsync+ssh+crontab to automate backup.

Yum install rsync-y # installation service

Local directory synchronization (do you think local synchronization or cp is useful)

Rsync-avz / tang / home # copy the files in the / tang directory to / home. The parameter description is shown below.

Experimental environment:

Because I want to record the experiment as gif effect, I installed an image interface, with the main server on the left and the ssh remote backup server on the right.

Back up the / tang/ directory of the primary server to the / home of the backup server, and the IP of the backup server is 192.168.23.35

Rsync-avz / tang/ root@192.168.23.35:/home/ # back up the local / tang/ directory to the / home directory of the remote backup server

If both the primary server and the backup server want to be consistent, you can add-- delete to let the backup server synchronize the primary server, and delete if there is any excess. On the left is the primary server and on the right is the ssh remote backup server.

Rsync-- delete-avz / tang/ root@192.168.23.35:/home/

Synchronizes the specified folder name. Here are folders that start with b that match.

Rsync-avz-- include 'baked'-- exclude'*'/ tang root@192.168.23.35:/home

Explanation:-- include means to include. -- exclude means to exclude, and * indicates that the preceding (left neighbor) character has 0 or more.

If you want to accurately synchronize a folder,-include 'here is the name of the folder without the * key'.

On the left is the primary server and on the right is the ssh remote backup server.

-a,-the properties of permissions remain unchanged

-v.-verbose mode output

-z.-Compression during transmission

-e,-- rsh=COMMAND specifies to use rsh and ssh methods for data synchronization

The basic operation should be demonstrated above. I believe you should know that you have to enter the password of the backup server every time you synchronize. Now configure ssh password-free login, and then write a script in crontab-e that can be executed automatically. The experiments are as follows:

Generate a key on the primary server

Ssh-keygen # (if you choose enter directly, you can choose the default)

Use ssh-copy-id to send the public key to the backup server

Ssh-copy-id 192.168.23.35

Then test again, whether remote login requires a password, not just OK!

Manually test whether synchronization requires a password

Rsync-avz-e ssh / tang root@192.168.23.35:/home

Ssh password-free login to OK, now let's write this sentence into a script

Echo "rsync-avz-e ssh / tang root@192.168.23.35:/home" > / etc/tang.sh

Crontab-e # is written to execute tasks regularly, once in the fifth minute of each hour.

5 * sh / etc/tang.sh

* * sh / etc/tang.sh

Explanation:

Column 1 represents minutes 1: 59 per minute is represented by * or * / 1.

The second column represents the hour 1: 23 (0 means 0 o'clock)

The third column represents the date 1: 31

The fourth column represents the month from January to December.

The fifth column identification number is 0006 (0 means Sunday)

The above experiments have been configured.

Tags: Services servers backup synchronization passwords files directories folders labs configurations right login automation backup tools hours tools meaning data week scripts Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn macOS Shulou Tech Info OPPO Reno MariaDB