cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Cloud



Etc


Reference














.

os:linux:command:rsync.html



Linux Commands#network

rsync - How to use rsync command in Linux

rsync Options

# man rsync

rsync(1)

NAME
       rsync - a fast, versatile, remote (and local) file-copying tool

OPTIONS SUMMARY
        -e, --rsh=COMMAND           specify the remote shell to use
            --delete                delete extraneous files from dest dirs
        -n, --dry-run               perform a trial run with no changes made
        -r, --recursive             recurse into directories
        --stats

The '-a' is equals '-rlptgoD'. But General user cannot use 'goD' option. So General user must use -rlpt.


Local

rsync -avzh --stats /tmp/test1/ /tmp/test2.bk
rsync -avzh --stats /tmp/test1/ /tmp/test2.bk/

rsync -avzh --stats --delete /home/user1/ /tmp/user1.bk/


Remote

rsync -e ssh -avzh --stats --delete /home/user1/ user2@192.168.0.2:/home/backup/server1/home/user1/
rsync -e "ssh -i /home/user1/.ssh/nopass" -avzh --stats --delete /home/user1/ user1@192.168.0.2:/home/user1/backup/server1/home/user1/


Tips

Speed limit(--bwlimit)

rsync -e ssh -avzh --stats –-bwlimit=1250 FILE  user@192.168.0.2:/DIR/
--bwlimit=12500   # 100Mbps = 12500KBps = 12.5MB/s
--bwlimit=1250   # 10Mbps = 1250KBps = 1.25MB/s
--bwlimit=125    # 1Mbps = 125KBps
--bwlimit=62   # 500kbps = 62.5KBps


wildcard, include/exclude

rsync -avzh --stats --include='*.log' --exclude='*' srcdir/ dstdir/

rsync -avzh --stats --exclude='*.gz' srcdir/ dstdir/
rsync -avzh --stats --exclude='.*' srcdir/ dstdir/

rsync -avzh --stats --progress --partial  src:/path/to/log/2020-09\*.log  ./log


resume

$ rsyc -avzh --stats -e ssh   --progress --partial --append SOURCE-FILE xx.xx.xx:/DESTINATION/

$ nohup rsyc -avzh --stats -e ssh   --progress --partial --append SOURCE-FILE xx.xx.xx:/DESTINATION/ &


rsync as root

/etc/sudoers
user01 ALL= NOPASSWD:/usr/bin/rsync

rsync -a -e "ssh" --rsync-path="sudo rsync" user01@192.168.0.11:/root/test/ /test/tmp


etc

  • The '-a' is equals '-rlptgoD'. But General user cannot use 'goD' option. So General user must use -rlpt.


Linux Commands#network




os/linux/command/rsync.html.txt · Last modified: 2022/09/27 by admin

Page Tools