rsync Sync Backup Server files Detailed method

Source: Internet
Author: User
Tags auth file copy relative file permissions iptables rsync


Rsync is a fast incremental file transfer tool that can be used for backup within the same host and as a different host network

Backup, because the server generally takes the Rsync tool, so it is more convenient to use.

Now there is a need for the LAN a machine 200G files back to the B machine, and timed synchronization, the program is as follows:

1, first configure Rsync server in Machine A:

Vi/etc/rsyncd.conf

UID = root

GID = root

Use chroot = no

Strict modes = yes

Address = 10.6.207.14//Specify native IP addresses, can not be set

Port = 873//Specify Rsync service ports, default is 873

Max connections = 10//maximum number of connections

MOTD FILE=/ETC/RSYNCD.MOTD//server information files, you need to calculate their own creation, can not be set

Lock file =/var/run/rsync.lock

Log file =/var/log/rsyncd.log

[Backup]//module name, that is, the directory that synchronizes or backs up, the client uses this keyword to connect

Path=/data/need-to-backup//Specify the location of the file directory

Comment = This is a test

Ignore errors//Ignore IO error

Read Only = yes/reading only, do not let the client upload files to the server side, rsync synchronization does not allow file modification

List = no

Auth users = root//logon user must be a real user present on the server, with multiple users separated by commas

Secrets file =/etc/rsyncd.pas//password files, need to create

Hosts allow = 10.6.207.216//Allow access to clients

Hosts deny=*//non-access clients

2, new and edit the Rsyncd.pas file, used to store the login password of the logged-in user, the properties of the file should be the main readable, format:

Username:password, for example: Note that the Rsyncd.pas file cannot have a #-like annotation

Vi/etc/rsyncd.pas

Root:test #root即为上面设置的auth users,test User Client B machine to connect a machine's password

Save exit, and set 600 permissions: chmod 600/etc/rsyncd.pas

If you do not modify permissions, the client will attempt to connect with an error similar to the following:

@ERROR: Auth failed on module home
Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1296) [receiver=2.6.8]

3, firewall settings

If a firewall is installed on the server, set the iptables on the server to open the 837 port.

Iptables-a input-p TCP--dport 873-j ACCEPT

4, the server side will be rsync in the form of daemon launch

Rsync--daemon--config=/etc/rsyncd.conf

5, on the B machine will be the rsync password written to the file, on the client, only need to enter a password, for example:

Vi/etc/rsyncd.pas

Test #与上面服务端设置的root密码一致

6, test the Sync command on the B machine:

Rsync-avzp--delete--password-file=/etc/rsyncd.pas root@10.6.207.14::backup/data/webroot/rsynctest/|grep-v "files "> imgcache_backup_logs/imgcache_htdocs$ (date-d today +"%y%m%d "). Log 2 > Imgcache_backup_logs/error/imgcache_ htdocs$ (date-d today +%y%m%d) Error.log

Where backup is the server-side configuration of the module name, the server-side configuration of the PATH=/DATA/NEED-TO-BACKUPG synchronization

To/data/webroot/rsynctest/, and will synchronize the information to exclude "files" such as information, the other imported into the log, log name based on the date of the day to create

, the error message is redirected to the error log. Because you do not need to lose the password, you can synchronize the files by crontab timing.

The remaining parameters are detailed in the following parameters:

-V,--verbose verbose mode output
-Q,--quiet thin output mode
-C,--checksum Open the check switch to force the file transfer to verify
-A,--archive archive mode, which represents the transfer of files recursively and maintains all file attributes equal to-rlptgod
-R,--recursive the subdirectory in recursive mode
-R,--relative using relative path information
-B,--backup creates a backup, which means that the old file is renamed to ~filename for the same file name already exists for the purpose. You can use the--suffix option to specify different backup file prefixes.
--backup-dir store backup files (such as ~filename) in the directory.
-suffix=suffix defines the backup file prefix
-U,--update only updates, skipping all files that already exist in DST, and the file time is later than the file you want to back up. (Do not overwrite the updated file)
-L,--links retention soft link knot
-L,--copy-links to treat soft links like regular files
--copy-unsafe-links only copies links that point beyond the src Path directory tree
--safe-links ignores links to the SRC path tree
-H,--hard-links keep hard links
-P,--perms keep file permissions
-O,--owner keep file owner information
-G,--group keep file group information
-D,--devices maintain device file information
-T,--times keep file time information
-S,--sparse special handling of sparse files to save DST space
-N,--dry-run which files will be transmitted
-W,--whole-file copy files without incremental detection
-X,--one-file-system do not cross file system boundaries
-B, the block size used by the--block-size=size test algorithm is 700 bytes by default
-E,--rsh=command specifies a shell program that replaces rsh
--RSYNC-PATH=PATH Specifies the path information for the rsync command on the remote server
-C,--cvs-exclude use the same method as CVs to automatically ignore files to exclude files that you do not want to transfer
--existing updates only those files that already exist in DST, not the newly created files
--delete Delete files that are not in the DST SRC
--delete-excluded also deletes the receiving end of files that are excluded by the option specified
--delete-after after transmission is over
--ignore-errors in time IO errors are also deleted
--max-delete=num Delete NUM files up to
--partial retains files that are not fully transmitted for some reason, to expedite subsequent transmissions
--force forcibly deletes a directory, even if it is not empty
--numeric-ids does not match the user and group IDs of numbers to user and group names
--timeout=time IP timeout time in seconds
-I,--ignore-times not skip those files that have the same time and length
--size-only when deciding whether to back up a file, just look at the file size without considering the file time
--modify-window=num the time stamp window that determines whether a file is in the same time, default is 0
-t--temp-dir=dir create temporary files in dir
--compare-dest=dir also compares files in DIR to determine whether a backup is required
-P equals to--partial
--progress Display backup process
-Z,--compress compression of backed-up files on transfer
--EXCLUDE=PATTERN Specifies to exclude file modes that do not require transfer
--INCLUDE=PATTERN Specifies the file mode that is not excluded and needs to be transferred
--exclude-from=file exclude files in the specified mode in file
--include-from=file does not exclude files that match the file-specified pattern
--version Print version Information
--address bound to a specific address
--CONFIG=FILE specifies a different profile and does not use the default rsyncd.conf file
--PORT=PORT Specifies the other rsync service ports
--blocking-io blocking IO for a remote shell
-stats gives the transfer status of some files
--progress transmission process in real time
--log-format=format Specify log file format
--password-file=file gets the password from file
--bwlimit=kbps limit I/O bandwidth, Kbytes per second
-H,--help display Help information

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.