Usage of Rsync

       Rsync is much faster than scp. 

So whether it is a local file/directory copy or a remote copy, it is better to use rsync.

Basic parameters of Rsync

  • -a : Archive mode, recursive copy, with attributes.
  • -v : show detailed information
  • -r : recursive copy without attributes
  • -z : compress
  • -h : show friendly information

Notice:

The basic usage of rsync is:

rsync source destination

  • If there is a / at the end of the source, which means /*, it means that only the files in the directory are copied, excluding the directory itself
  • If there is no / in the source, it means that the directory and the files in the directory are copied to the destination.

First, the operation of local files and directories

rsync -zvh backup.tar /tmp/backups/  
rsync -avzh /root/rpmpkgs /tmp/backups/  

Second, the operation of remote files

rsync -avz rpmpkgs/ root@192.168.0.101:/home/  
rsync -avzh root@192.168.0.100:/home/tarunika/rpmpkgs /tmp/myrpms  

3. Execute rsync through ssh, -e parameter

rsync -avzhe ssh root@192.168.0.100:/root/install.log /tmp/  
rsync -avzhe ssh backup.tar root@192.168.0.100:/backups/  

Fourth, display the transmission process

rsync -avzhe ssh --progress /home/rpmpkgs root@192.168.0.100:/root/rpmpkgs  

5. Exclusion and inclusion of files

rsync -avze ssh --include 'R*' --exclude '*' root@192.168.0.101:/var/lib/rpm/ /root/rpm  

6. Complete synchronization --delete, the source and destination remain exactly the same

rsync -avz --delete root@192.168.0.100:/var/lib/rpm/ .  

7. Limit the maximum size of files to be transferred, files larger than 200k will not be transferred

rsync -avzhe ssh --max-size='200k' /var/lib/rpm/ root@192.168.0.100:/root/tmprpm  

8. Delete the source file after the transfer is complete

rsync --remove-source-files -zvh backup.tar /tmp/backups/  

9. Necessary for novices, do not actually do any operation, only display the process

rsync --dry-run --remove-source-files -zvh backup.tar /tmp/backups/  

10. Speed ​​limit, 500kb*8=4M, speed limit is 4MB.

rsync --bwlimit=500 -avzhe ssh  /var/lib/rpm/  root@192.168.0.100:/root/tmprpm/  
rsync只同步变动的部分,如果要同步整个部分,用W参数  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326530927&siteId=291194637