Rsync ssh Data Synchronization command

Source: Internet
Author: User


Rsync ssh Data Synchronization command 1. differences between rsync and ssh remote synchronization command 1 Command Format: 2 # rsync [option] Source Path target path 3 where: 4 [option]: 5 a: Use archive mode, equal to-rlptgoD, that is to say, keep the original File Permission 6 z: indicates the compressed data during transmission 7 v: displayed to the screen 8 e: Use a remote shell program (you can use rsh or ssh) 9 -- delete: precisely Save the copy, and delete the files from the source host. The target host will also delete 10 -- include = PATTERN: do not exclude files or directories conforming to PATTERN 11 -- exclude = PATTERN: exclude all files or directories that match the PATTERN 12 -- password-file: Specify the user authentication password for the rsync server 13 14 Source Path and target path can use the following format: 15 rsync: // [USER @] Host [: Port]/Path <-- rsync Server Path 16 [USER @] Host: Path <-- another representation of rsync server 17 [USER @] Host: path <-- remote Path 18 LocalPath <-- local Path www.2cto.com ※note that at least one source or destination Path must be a local Path. If you ignore the local Path, only the list of remote files is listed. Example: mkdir test_new; // create a local test directory ssh ljz@192.168.1.109: /home/ljz/test // This is the svn server account directory to svn on the test directory of the content updated to the local test_new directory rsync-ave ssh ljz@192.168.1.109: /home/ljz/test/home/ljz/test_new/※note that if/home/ljz/test/is used, /home/ljz/test indicates that the local content is synchronized to the remote directory together with all the content in the directory already exists? 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/synchronize the content of the test directory on 109 to the local New_Test directory, and delete files or directories that do not exist in the Local Source Path. ※Always pay attention to the -- delete parameter. When using this parameter, we recommend that you specify the local directory with an absolute path to avoid clearing the current directory. 2. Create an rsync server. When the server does not activate ssh or the backup party does not have the ssh permission, we can create an rsync server to perform anonymous data synchronization. To use the rsync service, you need to establish the server and client: 1. The server master configuration file: www.2cto.com 1 # vi/etc/rsyncd. conf 2 log file =/var/log/rsyncd. log 3 pid file =/var/run/rsyncd. pid 4 lock file =/var/run/rsync. lock 5 [test] # rsync section name 6 path =/var/www/html/test # data storage path to be synchronized 7 comment = test folder # comment 8 uid = apache # identity used for File Reading 9 gid = apache # Same as above, must be a user with the permission to read the path, group 10 ignore errors # ignore error 11 read only = yes # read-only 12 list = no # cannot list 13 auth us Ers = linuxing # Account 14 secrets file connecting to the rsync service =/etc/rsyncd. secrets # specify the location where the account password is stored. Account Password File: # vi/etc/rsyncd. secrets # format: Account: Password (one group per line, separate account and password with: Number) linuxing: backup www.2cto.com after saving, ensure that the user is root and the permission is 600 # chown root: root/etc/rsyncd. secrets # chmod 600/etc/rsyncd. secrets start service: # rsync -- daemon ensures automatic start upon startup: Modify/etc/xinetd. d/rsync file, change disable = yes to disable = no # sed-I-e "/disable/{s/yes/no/}"/etc/xinetd. d/rsync # service x Inetd. d restart 2. Use the rsync: // method in the client. If the rsync server requires password verification, you can add the -- password-file parameter: # rsync-azv -- delete rsync: // linuxing@192.168.1.100/test/var/www/html -- password-file =/etc/test # vi/etc/test # specify the access password bakcup # chmod 600/etc/test 3, timing In addition, because the rsync client does not have the timing function, we can add scheduled tasks to the crontab to implement timed synchronization, for example: (do not use the-v parameter to prevent screen flushing) # crontab-e0 22 ** 1-5/usr/bin/rsync-az -- delete rsync: // linuxing@192.168.1.100/test/var/www/html -- password-file =/etc/test # specify Monday to Friday for synchronization at ten o'clock every night Www.2cto.com 3. Summary advantages of using rsync: You can use ssh for encrypted network transmission, or use ssh client keys to establish trust relationships. It is faster than tar or wget to synchronize large and complex directory structures between two computers. In addition, it can achieve precise synchronization. 4. If the appendix is installed by compiling rsync (such as FreeBSD), the path is a bit different: the server configuration file is:/usr/local/etc/rsyncd. conf Startup File:/usr/local/etc/rc. d/rsyncd. sh command file:/usr/local/bin/rsync system start hosting:/etc/rc. conf (Added rsyncd_enable = "YES") prepared by the Barefoot fairy ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.