20+ Rsync command’s switches and common usages with example
reference:http://crybit.com/rsync-commands-switches/ The “rsync” is a powerful command under the Linux environment. The rsync stands for Remote Sync. Normally rsync is used to transfer file from one server(source) to another server(destination). rsync has a lot of switches or option for managing the command much usefully. Here I am explaining the switches of rsync command with examples. Rsync will actually look and see what in the file has changed and upload only the part of the file that has changed. Unlike ftp and other transfer solutions rsync doesn’t simply re-upload the entire file. Common Syntax for Rsync: # rsync [options] Source Destinations.
Switches of rsync: 1,-v,–verboseIncrease verbosity. Example:I’ve created a file ‘rsync’ under ‘/root/Rsync/’ for testing purpose. root@server [~]# rsync -v /root/Rsync/rsync .
rsync
2,-r,–recursiveRecurse into directories. 3,-l,–linksCopy symlinks as symlinks. 4,-p,–permsPreserve permissions. 5,-t,–timesPreserve modification times. 6,-g,–groupPreserve group. 7,-o,–ownerpreserve owner (super-user only) 8,-DSame as –devices –specials.–devices :?preserve device files (super-user only).–specials :?preserve special files. 9,-H,–hard-linksPreserve hard links 10,-A,–aclsPreserve ACLs (implies –perms) 11,-X,–xattrsPreserve extended attributes 12,-a,–archiveThis is very important rsync switch,because it can be done the functions of some other switches combinations.Archive mode; equals -rlptgoD (no -H,-X) 13,-q,–quietSuppress non-error messages. 14,To specify the file size for sync:–max-size=SIZEDon’t transfer any file larger than SIZE–min-size=SIZEDon’t transfer any file smaller than SIZE 15,–deleteDelete extraneous files from destination dirs. 16,W,–whole-fileCopy files whole (without delta-xfer algorithm) 17,-u,–updateSkip files that are newer on the receiver. Means,Do Not Overwrite the Modified Files at the Destination. 18,–progressView the rsync Progress during Transfer. 19,Include and Exclude Pattern.–include–excludePatterns are expressed in single quote. Examples: [root@ser crybit]# rsync -avz --include 'c*' --exclude '*' /root/crybit/ 109.200.11.67:/root/Rsinc101
root@109.200.11.67's password:
stdin: is not a tty
sending incremental file list
cry1.doc
cry2.doc
cry3.doc
cry4.doc
cry5.doc
In the above example files starting with ‘c’ are included for Rsync and all other files are excluded on Rsync operation. 20 -e : Rsync over Shell(SSH)Syntax: # rsync -avz -e ssh Source Destination
Some useful switches combinations and Useful “Rsync” examples: 1,How to Sync two directories in the same machine ?I have created two directories(also some files inside each dir) under /root location to check the rsync usages. /root/Rsync1/
/root/Rsync2/
Example: root@server [~]# rsync -zvr /root/Rsync1/ /root/Rsync2/
sending incremental file list
rsync1.txt
rsync10.txt
rsync2.txt
rsync3.txt
......
......
sent 502 bytes received 202 bytes 1408.00 bytes/sec
total size is 0 speedup is 0.00
Where,-z?is to enable compression-v?verbose-r?indicates recursive 2,Preserve the following option while Sync files using -a switch. r,l,p,t,g,o,D : Switch details are mentioned in the above section.
Recursive mode,symbolic links,permissions,timestamp,owner and group
See the example below: root@server [~]# ll /root/Rsync1/rsync10.txt
-rw-r--r-- 1 root root 0 Feb 17 07:40 /root/Rsync1/rsync10.txt
root@server [~]# ll /root/Rsync2/rsync10.txt
-rw-r--r-- 1 root root 0 Feb 17 07:40 /root/Rsync2/rsync10.txt
3,How to Rsync files from remote server to local ?It is quit similar to SCP,the syntax for doing the same is pasted below: # rsync -azv Remote-IP:/path/for/Sync /Path/to/Sync
Some examples:Sync the directory from remote to local [root@ser crybit]# rsync -azv MY.SERVER.IP:/root/Rsync1 /root/crybit/
root@109.200.11.67's password:
stdin: is not a tty
receiving incremental file list
Rsync1/
Rsync1/rsync1.txt
Rsync1/rsync10.txt
Rsync1/rsync2.txt
Rsync1/rsync3.txt
.....
.....
sent 205 bytes received 527 bytes 77.05 bytes/sec
total size is 0 speedup is 0.00
Sync all files from remote to local [root@ser crybit]# rsync -azv 109.200.11.67:/root/Rsync1/* /root/crybit/
root@109.200.11.67's password:
stdin: is not a tty
receiving incremental file list
rsync1.txt
rsync10.txt
rsync2.txt
rsync3.txt
...
...
sent 201 bytes received 499 bytes 93.33 bytes/sec
total size is 0 speedup is 0.00
4,How to sync files from local to remote server ?Syntax: # rsync -azv /local-path/for/Sync/ Remote-IP:/path/to/Sync
Examples: [root@support crybit]# rsync -avz /root/crybit/ 109.200.11.67:/root/Rsinc101
root@109.200.11.67's password:
stdin: is not a tty
sending incremental file list
created directory /root/Rsinc101
./
rsync1.txt
rsync10.txt
rsync2.txt
rsync3.txt
...
...
sent 1028 bytes received 399 bytes 190.27 bytes/sec
total size is 0 speedup is 0.00
Note 1 : In example 3 and 4 you can use user@IP:/path format,if you have only the user privilege on server
Note 2 : The rsync will automatically create the destination directory/location if it isn't there.
That’s it !!? Related:,?,?,?,?,?,?,?,?,?,?,?,?,,?,?,?, (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |