1.rsync and SSH differential remote sync command
Copy Code code as follows:
Command format:
#rsync [option] Source path target path
which
[option]:
A: Use archive mode, equal to-rlptgod, that is, maintain the original file permissions
Z: Compress data on transfer
V: Display to the screen
E: Use a remote shell program (you can use rsh or SSH)
--delete: Exact save copy, source host deleted files, target host will also be deleted synchronously
--include=pattern: Do not exclude files or directories that match pattern
--exclude=pattern: Exclude all pattern-compliant files or directories
--password-file: Specifies the user authentication password for the rsync server
The source and destination paths can use the following format:
rsync://[user@]host[:P ort]/path <--rsync Server path
[user@] Host::P Another representation of the ATH <--rsync server
[user@] Host:path <--Remote Path
LocalPath <--Local Path
※ Note that the source or destination path must have at least one local path, and if the local path is omitted, only the remote file list is listed.
Example:
mkdir test_new; Set up a test directory locally
SSH ljz@192.168.1.109:/home/ljz/test///This is the account directory in the SVN server
Update the contents of the SVN test directory to the local test_new directory
Rsync-ave ssh ljz@192.168.1.109:/home/ljz/test//home/ljz/test_new/
※ Note that if the/home/ljz/test/representation is all of the contents of the test directory,/home/ljz/test represents all the contents of the directory
Synchronize local content to a remote directory?
Rsync-ave ssh/home/ljz/test_new/ljz@192.168.1.109:/home/ljz/test/
1#rsync-avz--delete ljz@192.168.1.109:/home/ljz/test//home/ljz/new_test/
Synchronizes the contents of the test directory on 109 to the local new_test directory and deletes files or directories that do not exist on the local source path.
※ You must pay attention to the--delete parameters, when using this parameter, we recommend that the absolute path to specify the local directory, to prevent emptying the current directory.
second, the establishment of Rsync server
When the server does not have SSH, or the backup party does not have SSH permissions, we can create an rsync server, anonymous data synchronization.
To use the Rsync service, you need to set up the server and the client:
1. Service End
Main configuration file:
Copy Code code as follows:
#vi/etc/rsyncd.conf
Log file =/var/log/rsyncd.log
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsync.lock
[Test] #rsync区段的设定名称
Path =/var/www/html/test #需要同步的数据存放路径
Comment = Test folder #注释
UID = Apache #采用什么身份进行文件读取
GID = Apache #同上, must be a user, group with Read path permissions
Ignore Errors #忽略错误
Read Only = yes #只读
List = no #不能列表
Auth users = linuxing #连接rsync服务的帐号
Secrets file =/etc/rsyncd.secrets #指定存放帐号密码的位置
Account password File:
#vi/etc/rsyncd.secrets
#格式: Account Number: password (one group per line, account number and password are separated by:)
Linuxing:backup
After saving, you need to ensure that the user is root, permission is 600
#chown root:root/etc/rsyncd.secrets
#chmod 600/etc/rsyncd.secrets
To start the service:
#rsync--daemon
Ensure that the boot automatically starts:
Revise the/etc/xinetd.d/rsync file and change the Disable=yes to Disable=no
#sed-i-E "/disable/{s/yes/no/}"/etc/xinetd.d/rsync
#service xinetd.d Restart
2. Client
Use a method that involves rsync://in the usage one.
If the rsync server requires password authentication, you can increase the--password-file parameters:
#rsync-azv--delete rsync://linuxing@192.168.1.100/test/var/www/html--password-file=/etc/test
#vi/etc/test
#指定访问密码
Bakcup
#chmod 600/etc/test
3, timing
In addition, because the Rsync client does not have the timing function, we can achieve timed synchronization by increasing the scheduled task in crontab, such as: (Do not use the-v parameter to prevent the brush screen)
#crontab-E
0 * * * 1-5/usr/bin/rsync-az--delete rsync://linuxing@192.168.1.100/test/var/www/html--password-file=/etc/test
#指定星期一到五, sync every 10 o'clock in the evening
Third, summary
Advantages of using rsync: Network encrypted transmission via SSH, or the use of SSH client keys to establish trust relationships. When keeping a large, complex directory structure synchronized between two computers, it is faster than either tar or wget. And you can do exact synchronization.
Iv. Appendix
If you compile the installed rsync (such as FreeBSD), the path is somewhat different:
The server's configuration file is:/usr/local/etc/rsyncd.conf
Startup file:/usr/local/etc/rc.d/rsyncd.sh
Command file:/usr/local/bin/rsync
System Boot hosting:/etc/rc.conf (add rsyncd_enable= "YES")