Web site incremental backup configuration for rsync in Linux

Source: Internet
Author: User
Tags chmod file copy zip ssh vps file permissions rsync

Using Linux's rsync can be very simple to the incremental backup operation of the VPS, today I will write a tutorial for everyone to use.

First need to download two packets, one for the server side, one for the client, server-side VPS for the data source, the client for backup VPS, note: Only support one-way synchronization, that is, backup function.


First, configure the server side, such as ip:111.111.111.111 download rsync-server.zip files, after decompression, upload to the/etc directory, you need to set 4 places:

1. Set the IP of server-side IP for your VPS in/etc/rsyncd/rsyncd.conf

The code is as follows Copy Code

Address = 111.111.111.111

2. Set/etc/rsyncd/rsyncd.conf to allow synchronization of client IP, multiple IP separated by space:

The code is as follows Copy Code

Hosts allow=222.222.222.222

3. Set the directory in the/etc/rsyncd/rsyncd.conf that needs to be synchronized

The code is as follows Copy Code

Path =/home/wwwroot

4. Set the username and password in the/etc/rsyncd/rsyncd.secrets and give 600 permissions with the command

The code is as follows Copy Code
chmod 600/etc/rsyncd/rsyncd.secrets

5. Open the server side

The code is as follows Copy Code

/wp-content/bin/rsync--daemon--config=/etc/rsyncd/rsyncd.conf

Second, configure backup clients, such as ip:222.222.222.222 download rsync-root.zip files, after decompression, upload to the/root directory:

1. Set the rsync password/root/pass file (no user name), consistent with the server side, and give 600 permissions, command:

The code is as follows Copy Code

chmod 600/root/pass

2. Set rsync path/root/rs.sh, consistent with server side, and give executable permission, command:

The code is as follows Copy Code

Rsync-avzp--delete--password-file=/root/pass username@111.111.111.111::p rofilename/home/backup

User name in #其中username为服务器端/etc/rsyncd/rsyncd.secrets

#其中111.111.111.111 for server-side IP

#其中profilename为 the configuration name defined in/etc/rsyncd/rsyncd.conf

#其中/home/backup to the client path that needs to be synchronized

The code is as follows Copy Code
chmod +x/root/rs.sh

Third, you can use the Crontab function, every 1 hours, or daily synchronization data:

The code is as follows Copy Code

Crontab-e

*/1 * * */root/rs.sh

Run automatically every 25th minute of the hour

The code is as follows Copy Code

*/1 * */root/rs.sh

Automatically run once every 25 minutes, 04 times a day

Iv. Common Error Solutions

1. Server-side/etc/rsyncd/rsyncd.secrets and backup-side/root/pass require 600 permissions

2. Can manually perform/root/rs.sh to see if it can be synchronized successfully

3. Keep in mind that this synchronization is a full data synchronization that deletes the files on the backup side that are not on the server side

4. This is an incremental backup, only synchronized modified or no files, the original file will not be downloaded, saving time and traffic

V. Rsync Reference Notes

The command format for rsync can be in the following six ways:
rsync [OPTION] ... SRC DEST
rsync [OPTION] ... SRC [User@]host:dest
rsync [OPTION] ... [user@] HOST:SRC DEST
rsync [OPTION] ... [user@] HOST::SRC DEST
rsync [OPTION] ... SRC [user@]host::D EST
rsync [OPTION] ... rsync://[user@]host[:P ort]/src [DEST]
For each of the above six command formats, Rsync has six different working modes:
1 Copy Local files. This mode of operation is initiated when both SRC and des path information do not contain a single colon ":" delimiter. such as: Rsync-a/data/backup
2 Use a remote shell program (such as rsh, SSH) to copy the contents of the local machine to the remote machine. This mode is started when the DST path address contains a single colon ":" Separator. such as: Rsync-avz *.c foo:src
3 Use a remote shell program (such as rsh, SSH) to copy the contents of the remote machine to the local machine. This mode is started when the SRC address path contains a single colon ":" Separator. such as: Rsync-avz Foo:src/bar/data
4 Copy files from remote rsync server to local machine. This mode is started when the SRC path information contains the "::" delimiter. such as: Rsync-av Root@172.16.78.192::www/databack
5 copy files from local machine to remote rsync server. This mode is started when the DST path information contains the "::" separator. such as: Rsync-av/databack root@172.16.78.192::www
6 The list of files for the remote machine. This is similar to rsync transmission, but simply omitting the local machine information in the command. such as: Rsync-v rsync://172.16.78.192/www
The specific explanation for the rsync parameter is as follows:
-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 the use of rsh, SSH mode for data synchronization
--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

The AZV option is generally used

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.