rsync command detailed explanation and additional backup scripts

Source: Internet
Author: User
Tags file copy ssh disk usage file permissions rsync
Rsync is a very powerful tool, and its commands have many feature options, and we'll analyze all of its options below. The command format for Rsync can be the following six: 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]
  corresponds to the above six command formats, Rsync has six different modes of operation: 1 copy Local files. This mode of operation is initiated when both SRC and des path information do not contain a single colon ":" delimiter. For example: Rsync-a/data/backup 2 uses 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. For example: Rsync-avz *.c FOO:SRC 3 uses 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. For example: Rsync-avz foo:src/bar/data 4) copies files from a remote rsync server to the 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 the local machine to the remote rsync server. This mode is started when the DST path information contains the "::" separator. For example: Rsync-av/databack root@172.16.78.192::www 6) lists the files for the remote machine. This is similar to rsync transmission, but simply omitting the local machine information in the command. For example: rsync-v rsync://172.16.78.192/www rsync parameters are explained as follows:-V,--verbose verbose mode output-Q,--quiet compact output mode-C,--checksum turn on the checksum switch to force file transfer Verify-A,--archive archive mode, represents the transfer of files recursively, and maintains all file attributes, equal to-rlptgod-r,--recursive subdirectories in recursive mode-R,--relative using relative path information-B,--backup Create a backup, which is to rename the old file to ~filename for the same file name that 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, that is, skipping all files that already exist in DST, and the file time is later than the file to be backed up. (Does not overwrite the updated file)-L,--lInks retain the soft link-L,--copy-links want to treat a regular file like a soft link--copy-unsafe-links only copy points outside the SRC Path directory tree--safe-links ignore links to the src path tree-H,- Hard-links keep hard link-p,--perms keep file Permissions-O,--owner keep file owner-G,--group keep file group information-D,--devices keep device file information-T,--times keep file time information -S,--sparse special processing of sparse files to save DST space-N,--dry-run which files will be transferred-W,--whole-file copy files, no incremental detection-X,--one-file-system not across file system boundaries -B, the--block-size=size test algorithm uses block size, default is 700 bytes-E,--rsh=command specifies the use of rsh, SSH mode for data synchronization--rsync-path=path Specify 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 just update those files that already exist in DST without backing up those newly created files --delete Delete files that are not in the DST src--delete-excluded also delete the receiver those files that are excluded by this option are deleted after the--delete-after transfer is over--ignore-errors In-time IO errors are also deleted--max-delete=num up to delete NUM files--partial retain those files that are not fully transmitted for some reason, in order to speed up the subsequent transfer--force forcibly delete the directory, even if it is not empty--numeric-ids Do not match the user and group IDs of numbers to the user name and group name--timeout=time IP Timeout, in seconds I,--ignore-times do not skip files that have the same time and length--size-only when deciding whether to back up files, Just look at the file size, regardless of the file time--modify-window=num determines whether the file time is used concurrently with the timestamp window, by default 0-t--temp-dir=dir creates a temporary file in Dir--compare-dest=dir also compares files in DIR to determine whether a backup-p equivalent to--partial--progress displays the backup process-Z,--compress to compress the backed-up files during transmission--exclude= pattern specifies that you exclude file schemas 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 File--version print version information--address bind to a specific address--config=file specify a different profile, do not use the default rsyncd.conf file--port=port Specifies that the other rsync service ports--blocking-io to the remote shell using blocking io-stats gives the transmission status of certain files--progress the actual transfer process--log-format=format the specified log file format when transmitting-- Password-file=file get password from file--bwlimit=kbps limit I/O bandwidth, Kbytes per second-h,--help display Help information   generally use AZV option rsync-daily.sh  
#! /bin/sh user= "Rsync"
Src= "192.168.1.100"
Dst= "192.168.1.200"
srcdir=/db/
dstdir=/nfs/192.168.1.202.nfs/
adir= $CDIR/today/
bdir= $CDIR/' Date +%w '/# Day of week (0..6); 0 represents Sunday
Excludes=/root/bin/rsync-daily-excludes echo "* * * Check the network situation * * * *
Ping $DST-C 2
If [$?-ne 0]
Then
Echo.
Echo ' Ping $DST host connection failed!
Exit 1
fi ssh $USER @ $DST "[-D $BDIR] | RM-FR $BDIR "
If [$?-ne 0]
Then
echo "Delete failed!"
Exit 1
Fi
echo "starts backup with the time:" ' Date ' RSYNC-QLZRTP--stats--force--ignore-errors--delete-excluded--exclude-from= $EXCLUDES-- Delete--backup--backup-dir= $BDIR-e ssh $SRCDIR $USER @ $DST: $ADIR if [$-ne 0]
Then
Echo.
echo "Backup failed!"
Echo.
Fi echo "Backup ended:" ' Date ' can check for disk usage with the previous command! Df-h

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.