rsync Automatic incremental backup

Hello World 2021-11-06 AM 141℃ 0条

The RSYNC configuration script is widely used, such as incremental backup of VPS hosts or file synchronization between SLBs.

For example: server IP: 111.111.111.111; Client IP: 222.222.222.222

Configure the server side

Download the rsync-server.zip file, unzip it, and upload it to the /etc directory. You need to set four places:

Download rsync-server

Set the server-side IP (line 7) in /etc/rsyncd/rsyncd.conf as the IP of your VPS

address = 111.111.111.111

Set the client IP allowed to synchronize in /etc/rsyncd/rsyncd.conf (line 20), and multiple IPS are separated by spaces

hosts allow=222.222.222.222

Set the directory to be synchronized in /etc/rsyncd/rsyncd.conf (line 35)

path = /home/wwwroot

Set the user name and password in /etc/rsyncd/rsyncd.secrets, and give 600 permissions with the command

chmod 600 /etc/rsyncd/rsyncd.secrets

Set server side

Set the IP, allowed client IP, user name and password. After setting, run rsync on the server. The command is:

/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf

Configure backup client

Download the rsync-root.zip file, unzip it and upload it to the /root directory:
Download rsync-client

Set the Rsync password /root/pass file (no user name is required), connect with the server, and give 600 permission. The command is:

chmod 600 /root/pass

Set the Rsync path /root/rs.sh, connect with the server side, and give the executable permission. The command is:

rsync -avzP --delete  --password-file=/root/pass [email protected]::vpsmmhome/home/wwwroot

//Where vpsmuser is the server-side /etc/rsyncd/rsyncd.secrets user name

//Where 111.111.111.111 is the server IP address

//Where vpsmhome is the custom name in line 34 of / etc / rsyncd / rsyncd.conf

//Where / home / wwwroot is the website directory to be synchronized

chmod +x /root/rs.sh

You can use the crontab function to synchronize data every hour or every day:

25 */1 * * * /root/rs.sh

//It runs automatically every 25th minute of every hour

25 04 */1 * * /root/rs.sh

//It runs automatically at 25:04 every day

Common errors

  1. Server side /etc/rsyncd/rsyncd.secrets and backup side /root/pass require 600 permissions
  2. You can manually execute /root/rs.sh to see if the synchronization is successful
  3. Remember that this synchronization is a complete data synchronization, which will delete files on the backup side but not on the server side
  4. This is an incremental backup, which only synchronizes the modified or missing files, and the original files will not be downloaded, which saves time and traffic
标签: rsync, backup

非特殊说明,本博所有文章均为博主原创。

评论啦~