Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Rsync configuration and Automation execution

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report