Build Rsync service under Ubuntu 14.04 and set timed file synchronization

The Rsync service is used to synchronize files between two Linux hosts. The client automatically synchronizes the files in the path specified by the server according to the configuration to achieve the purpose of backing up files. The Rsync service uses an incremental update algorithm. When a file changes some areas, the entire file will not be transferred, so the synchronization efficiency is high. The following are the simple installation steps.

1. Install the rsync package

apt-get install rsync

2. Modify the rsyncd.conf configuration file
Check the location of the configuration file in /etc/init.d/rsync, generally: /etc/rsyncd.conf
vi /etc/rsyncd.conf
Write:
motd file = /etc/rsyncd.motd
secrets file = /etc/rsyncd.scrt
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log

port = 873
use chroot = yes
hosts allow=120.26.224.51
max connections = 5

[software]
path = /home/deploy/software
comment = This is the web app dir.
uid = root
gid = root
read only = false
auth users = root
transfer logging = yes
exclude = dir1/

3. Modify the /etc/rsyncd.motd configuration file and write the server welcome message
vi /etc/rsyncd.motd
Welcome to my rsync server!

4. Modify the /etc/rsyncd.scrt password configuration file
vi /etc/rsyncd.scrt
user1 :password1
user2:password2

Change the password file permission to 600
chmod 600 /etc/rsyncd.scrt

5. Modify the /etc/default/rsync configuration and set enable
RSYNC_ENABLE=true

6. The server restarts
service rsync restart

7. The client tests the connection
rsync - -list-only [email protected]::software

8. Synchronize data
rsync -avzp --delete [email protected]::software dir

9. Synchronize data without entering password
Create password file
vi rsyncd.scrt
write Enter the user password: password
modify the permission to 600
chmod 600 rsyncd.scrt
synchronization
rsync -avzp --delete --password-file=rsyncd.scrt [email protected]::software dir

10. Use crontab to set up timed synchronization Write
the synchronization command into the shell script
vi rsync.sh

to start synchronization at 3 am every day
crontab -e
00 3 * * * /data/aliyun/rsync.sh >> /data/aliyun/log.log


Note: all paths in the script must be written as absolute paths, the default current directory is the user's home directory

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324601024&siteId=291194637