RYSNC is a data mirroring and backup tool that enables both local and remote host files, directories, fast synchronous mirroring, remote data backup and other functions. In the process of synchronization, Rsync is based on its own unique algorithm, only synchronized with the changes in the file, even in a file only synchronized with the changes in the part, so you can achieve rapid synchronization of data functions.
First: Dependent SSH service sync directory
rsync-asvh/home/n22/test1/*/home/n22/test2/
Parameter explanation:
A is equivalent to the-rlptgod archive mode, which is to keep all attributes of the file, permissions unchanged
S efficient handling of fragmented files
V Verbose mode
H Keep Hard Links
The above indicates that all files in the/home/n22/test1/directory of the machine are synchronized to the/home/n22/test2/directory. This way I can only sync new and updated, can not sync Delete, do not know the reason, modified to
rsync-asvh–delete/home/n22/test1/*/home/n22/test2/
, the deleted file cannot be synchronized while the delete is added.
The account and password are required when synchronizing with other servers: rsync-asvh/home/* root@192.168.1.1:/home/
Second: Server and Client
After testing, this server and client configuration can be a perfect solution to delete files and directories of the synchronization function.
Server-side configuration:
1, RYSNC generally through the xinetd to start.
Modify/etc/xinetd.d/rsync, only one place
# Default:off
# description:the Rsync server is a good addition to AM FTP server, as it
# allows CRC Checksumming etc.
Service rsync
{
Disable = Yes modified to disable = no
Socket_type = Stream
wait = no
user = root
Server =/usr/bin/rsync
Server_args =–daemon
Log_on_failure + + USERID
}
2, next edit the configuration file
[Root@mailsvr ~] # vi/etc/rsyncd.conf
UID = nobody
GID = Nobody
Use chroot = no
Max connections = 4
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsyncd.lock
Log file =/var/log/rsyncd.log
[web]
Path =/opt/web
Ignore errors
Read Only = True
List = False
Hosts allow = 192.168.0.5 # allowed IP address
Hosts deny = 0.0.0.0/32 # banned IP address
Auth users = backup # authenticated username, this example is backup
Secrets file =/etc/backup.pass #认证用户的密码文件
3, edit the server password file/etc/backup.pass
Vi/etc/backup.pass
backup:123456
4, then set permissions chmod 400/etc/backup.pass
Client Configuration
1. Edit the password file at Rsync connection/etc/rsync_client.pass
Vi/etc/rsync_client.pass
123456 # You only need to configure the password to use when connecting, you must be the same as the password defined on server A.
2. chmod 600/etc/rsync_client.pass
3. Use the rsync command to connect to the server to achieve file synchronization
Rsync-vzrtopg–progress–delete–password-file=/etc/rsync_client.pass Backup@192.168.1.2::web/opt/test
4. Use –execlude= to exclude file suffix names that do not need to be synchronized
Rsync-vzrtopg–progress–delete–password-file=/etc/rsync_client.pass–exclude= "*.tmp" Backup@192.168.1.2::web/home /test
5. Use –execlude-from= to exclude directories that do not need to be synchronized
Rsync-vzrtopg–progress–delete–password-file=/etc/rsync_client.pass–exclude-from=/opt/pcdir backup@192.168.1.2:: Web/home/test
6, timing synchronization
#vi rsyncd.sh
Rsync-asvh–delete–password-file=/home/n22/rsync_client.pass backup@192.168.1.252::web/home/n22/test2/
#crontab-E
* * */etc/rsyncd.sh
4:01 A.M. Daily