Rsync User Guide

Source: Internet
Author: User
Tags rsync

Considering the security of server data, I consider adding a backup server to achieve better redundancy through data synchronization.
Linux has a very good command. Rsync can implement differential backups, so let's say how it's used:
The Rsync service is not turned on in the installation of Ubuntu default installation. There are 3 steps to be made:
1, modify the/etc/default/rsync, let the rsync service start when the boot.
$ sudo vi/etc/default/rsync
Change Rsync_enable=false to Rsync_enable=true

2, create a rsyncd.conf, the default installation is not this file.
$ sudo vi/etc/rsyncd.conf
Enter the following lines:
Uid=nobody
Gid=nobody
Max Connections=3
Use Chroot=no
Log File=/var/log/rsyncd.log
PID File=/var/run/rsyncd.pid
Lock File=/var/run/rsyncd.lock
Secrets file=/etc/rsync.pwd

3. Start the rsync service.
$/etc/init.d/rsync Start


Basic command:
Rsync-avz./libserver1.0.1 [Email protected]:/home/cxf/backup directory Upload
Rsync-avz [email protected]:/home/cxf/libserver./backup Catalog Download
Rsync-avz./libserver1.0.1./* [email protected]:/home/cxf/backup file Upload
Rsync-avz [email protected]:/home/cxf/libserver/*./backup File Download

One, through the rsh or SSH command
In the absence of an rsync server, we can use the rsync command to make fast, differential backups directly:
CODE:
Command format:
#rsync [option] Source Path destination Path
which
[option]:
A: Use archive mode, equal to-rlptgod, that is, maintain the original file permissions
Z: Indicates compressed data during transfer
V: Display to screen
E: Using a remote shell program (you can use rsh or SSH)
--delete: The exact save copy, the source host deleted files, the target host will also be deleted synchronously
--include=pattern: Do not exclude files or directories that match the PATTERN
--exclude=pattern: Excludes 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://[[email protected]]host[:P ort]/path <--rsync Server path
[[email protected]] Host: Another representation of the:P Ath <--rsync server
[[email protected]] 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 will be listed.
Example:

CODE:
#rsync-ave ssh test:/home/ftp/pub//home/ftp/pub/

Synchronize the contents of the/home/ftp/pub/directory on the source path's COSCO test machine to the local/home/ftp/pub/directory via rsync.
Be careful at the end of the source path/number, suffix/notify rsync to replicate the contents of the directory, but do not replicate the directory itself. For example:

CODE:
#rsync-ave ssh test:/home/ftp/pub/home/ftp/
The pub directory is synchronized to the local/home/ftp/path.

CODE:
#rsync-azv--delete Rsync://[email protected]2.168.1.100/blog/var/www/html/
Log in to 192.168.1.100 via linuxing, synchronize the blog entries of the rsync server to the local/var/www/html/, and delete files or directories that do not exist on the local source path.
※ Please note the--delete parameter, when using this parameter, we recommend 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 establish the Rsync server, the anonymous data synchronization.
To use the Rsync service, you need to establish the server side and the client:
1. Service Side
Master configuration file:
CODE:
#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 permission
Ignore Errors #忽略错误
Read Only = yes #只读
List = no #不能列表
Auth users = linuxing #连接rsync服务的帐号
Secrets file =/etc/rsyncd.secrets #指定存放帐号密码的位置
Account password File:
CODE:
#vi/etc/rsyncd.secrets
#格式: Account Number: password (one group per line, account number and password separated by:)
Linuxing:backup
After saving, you need to ensure that the user is root, the permission is 600
CODE:
#chown root:root/etc/rsyncd.secrets
#chmod 600/etc/rsyncd.secrets
Start the service:
#rsync--daemon
Guaranteed boot start automatically:
Modify the/etc/xinetd.d/rsync file to change the Disable=yes to Disable=no

CODE:
#sed-i-e "/disable/{s/yes/no/}" /etc/xinetd.d/rsync
#service xinetd.d Restart

2, the Client
Use the method that involves rsync://in the usage one.
If the rsync server requires password validation, you can increase the--password-file parameter:

CODE:
#rsync-azv--delete rsync://[email protected]/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 a timer function, we can implement timed synchronization by adding scheduled tasks in crontab, such as: (Do not use the-v parameter to prevent the brush screen)
CODE:
#crontab-E
0 * * 1-5/usr/bin/rsync-az--delete rsync://[email protected]/test/var/www/html--password-file=/etc/test
#指定星期一到五, synchronized every 10 o'clock in the evening
Iii. Summary
Advantages of using rsync: You can use SSH for network encrypted transmission, or you can use the SSH client key to establish a trust relationship. When synchronizing large, complex directory structures between two computers, it is faster than tar or wget. And can be precisely synchronized.

Iv. Appendices
If you are installing rsync (such as FreeBSD) by compiling, the path is a bit different:
Server configuration file in:/usr/local/etc/rsyncd.conf
Startup file:/usr/local/etc/rc.d/rsyncd.sh
Command file:/usr/local/bin/rsync
System Startup hosting:/etc/rc.conf (Increase rsyncd_enable=" yes")

http://blog.csdn.net/adcxf/article/details/3975119

Rsync User Guide

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.