Detailed explanation of how rsync synchronizes backup server files

Source: Internet
Author: User

Rsync is a foreign synchronization tool, which can be synchronized between platforms. Next I will introduce you to rsync in detail how to synchronize backup server files, for more information, see.


Rsync is a fast incremental file transfer tool. It can be used for internal backup of the same host. It can also be used as a network of different hosts.

Backup, because the server generally comes with rsync tools, it is easier to use.

There is A need to back up the GB file of machine A in the LAN to machine B and synchronize it regularly. The solution is as follows:

1. First configure the rsync server on machine:

Vi/etc/rsyncd. conf

Uid = root

Gid = root

Use chroot = no

Strict modes = yes

Address = 10.6.207.14 // specify the local IP address.

Port = 873 // specify the rsync service port. The default value is 873.

Max connections = 10 // maximum number of connections

Motd file =/etc/rsyncd. motd // server information file, which must be created by yourself.

Lock file =/var/run/rsync. lock

Log file =/var/log/rsyncd. log

[Backup] // Module name, that is, the directory for synchronization or backup. 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 errors

Read only = yes // read-only. The client is not allowed to upload files to the server. Files cannot be modified during rsync.

List = no

Auth users = root // login user, which must be real users on the server and separated by commas

Secrets file =/etc/rsyncd. pas // password file, which must be created by yourself

Hosts allow = 10.6.207.216 // client to be accessed

Hosts deny = * // the client to which access is prohibited

2. Create and edit the rsyncd. pas file to store the logon password of the logon user. The file attribute must be subject-readable. format:

Username: password. For example, note that the rsyncd. pas file cannot contain # Similar annotations.

Vi/etc/rsyncd. pas

Root: test # root is the auth users set above. The password for user test client machine B to connect to machine

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

If you do not modify the permission, an error similar to the following will occur when the client tries to connect:

@ ERROR: auth failed on module home
Rsync error: error starting client-server protocol (code 5) at main. c (1296) [handler ER = 2.6.8]

3. Firewall settings

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

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

4. Start rsync on the server as a daemon

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

5. Write the rsync password to the file on machine B. On the client, you only need to enter the password, for example:

Vi/etc/rsyncd. pas

Test # consistent with the root password set on the server above

6. Test the synchronization command on machine B:

Rsync-avzP -- delete -- password-file =/etc/rsyncd. 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
 
Here, backup is the module name configured by the server, that is, the path =/data/need-to-backupg synchronization configured by the server
 
To/data/webroot/rsynctest/, and exclude the synchronized information such as "files". Other information is imported into the log. The log name is created based on the date of the current day.
 
The error message is redirected to the error log. Because you do not need to enter a password, you can use crontab to regularly synchronize files.
 
For details about other parameters, see the following parameters:
 
-V, -- verbose detailed mode output
-Q, -- quiet simplified output mode
-C, -- checksum: enable the verification switch to force file transfer verification
-A, -- archive mode, indicating that the file is transmitted recursively and all file attributes are kept, equal to-rlptgoD.
-R, -- recursive processes subdirectories in recursive Mode
-R, -- relative uses relative path information
-B, -- backup creates a backup, that is, if the object already has the same file name, rename the old file ~ Filename. You can use the -- suffix option to specify different backup file prefixes.
-- Backup-dir: backs up files (for example ~ Filename) is stored in the directory.
-Suffix = SUFFIX defines the backup file prefix.
-U, -- update only performs updates, that is, skipping all files that already exist in DST and whose file time is later than the time to be backed up. (Do not overwrite the updated file)
-L, -- links retains soft links
-L, -- copy-links: process soft links like regular files
-- Copy-unsafe-links: only copies links other than the SRC path directory tree.
-- Safe-links ignores links other than the SRC path directory tree
-H, -- hard-links
-P, -- perms to keep File Permissions
-O, -- owner keeps file owner information
-G, -- group: Keep file group information
-D, -- devices: Keep Device File Information
-T, -- times preserve the file time information
-S, -- sparse performs special processing on 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 span the boundaries of the file system
-B, -- block-size = SIZE indicates the block size used by the algorithm. The default value is 700 bytes.
-E, -- rsh = COMMAND specifies the shell program to replace rsh
-- Rsync-path = PATH specifies the path of the rsync command on the remote server
-C, -- cvs-exclude automatically ignores files in the same way as CVS to exclude files that do not want to be transmitted
-- Existing only updates the files that already exist in DST, instead of backing up the new files.
-- Delete: delete the files that are not in the SRC file in DST.
-- Delete-excluded: delete Files specified by this option at the receiving end.
-- Delete-after: delete after transmission
-- Ignore-errors is deleted when an IO error occurs in a timely manner.
-- Max-delete = NUM: a maximum of NUM files can be deleted.
-- Partial retains the files that are not completely transferred for any reason, so as to speed up subsequent re-transmission.
-- Force directory deletion, even if not empty
-- Numeric-ids does not match the number user and group ID with the user name and group name.
-- Timeout = time ip timeout, in seconds
-I, -- ignore-times do not skip files with the same time and length
-- Size-only: when determining whether to back up a file, only check the file size, regardless of the file time
-- Modify-window = NUM determines whether the timestamp window of the file is used at the same time. The default value is 0.
-T -- temp-dir = DIR create a temporary file in DIR
-- Compare-dest = DIR: compare the files in DIR to determine whether to back up data.
-P is equivalent to -- partial
-- Progress displays the backup process
-Z, -- compress compresses backup files during transmission
-- Exclude = PATTERN specifies to exclude file modes that do not need to be transmitted
-- Include = PATTERN specifies the file mode to be transmitted without exclusion
-- Exclude-from = FILE: exclude files in the specified mode in the FILE.
-- Include-from = FILE: files with the specified FILE pattern matching are not excluded.
-- Version: prints version information.
-- Address: bind to a specific address
-- Config = FILE: specify other configuration files. The default rsyncd. conf FILE is not used.
-- Port = PORT specify other rsync service ports
-- Blocking-io: block IO for remote shell
-Stats indicates the transmission status of some files.
-- SS actual transmission process during transmission
-- Log-format = FORMAT specifies the log file format
-- Password-file = FILE get password from FILE
-- Bwlimit = KBPS limits I/O bandwidth, KBytes per second
-H, -- help: displays help information

Related Article

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.