rsync

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

Options

-a, –archivearchive mode; equals -rlptgoD (no -H,-A,-X)
-r, –recursiverecurse into directories
-l, –linkscopy symlinks as symlinks
-p, –permspreserve permissions
-t, –timespreserve modification times
-g, –grouppreserve group
-o, –ownerpreserve owner (super-user only)
-x, –one-file-systemdon’t cross filesystem boundaries
-Dsame as –devices –specials
–devicespreserve device files (super-user only)
–specialspreserve special files
–no-OPTIONturn off an implied OPTION (e.g. –no-D)
-n, –dry-runperform a trial run with no changes made
–deletedelete extraneous files from dest dirs
–info=FLAGSfine-grained informational verbosity

info flags

DELMention deletions on the receiving side
PROGRESSMention 1) per-file progress or 2) total transfer progress
info FLAGS
rsync --info=help
rsync --info=progress2

Tasks

rsync: failed to set permissions on “somedata”: Operation not permitted (1)

rsync -av --no-perms ...

Synchronize folders over SSH

Copy over SSH

rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /mnt/video/foo.avi admin@server:/tank/
rsync -avzhe ssh /wineprefixes/path/hearthstone leopardb@laptop:/home/user/Wine/

Synchronize (delete on receiver)

First line is with –dry-run to see what would happen, the –delete switch is dangerous.

rsync -avz --update -e ssh --progress --delete user@remote:/home/user/Documents/ /home/user/Documents/ --dry-run
rsync -avz --update -e ssh --progress --delete user@remote:/home/user/Documents/ /home/user/Documents/

Excludes

To exclude the folder /stornext/projects/test from the job:

rsync -avh --exclude=/test /stornext/projects/ /stornext/backup/projects/DATE/

Info: https://unix.stackexchange.com/questions/83394/rsync-exclude-directory-not-working

Exclude from file:

leo@computer:~$ more excludes.txt
*Trash*
*TemporaryItems*
*RECYCLE.BIN*
*DS_Store*
--exclude-from=excludes.txt

rsyncd daemon

rsync://[USER@]HOST[:PORT]/SRC

Test:

rsync -n comp_or_IP::
rsync -av --password-file=/root/rsyncpasswd a_file rsync://user@192.168.0.2/backup/

Synology bug

you have to provide --rsync-path otherwise some random permission denied happens:

rsync --rsync-path=/usr/bin/rsync -avzhe ssh user@synology-nas.lan:/volume1/SHAREDFOLDER/whatever .

Time stuff and send email upon completion

FreeNAS

/usr/bin/time -h rsync -ah --one-file-system --info=progress2 --no-perms /mnt/storage/dataset1/stuff /mnt/storage/dataset2/ ; echo "" | mail -s "rsync finished" root

Linux

/usr/bin/time -f "time used:\t%E" \
rsync -ah --info=progress2 --delete \
/mnt/mirror03/Backup /mnt/mirror02/ ; \
echo -e "Subject:Finished\n\nDone.\n" | sendmail root

Rsync with Android

ls /run/user/$UID/gvfs/mtp*
rsync --verbose --progress --omit-dir-times --no-perms --recursive --inplace ~/Videos/ ./

https://askubuntu.com/questions/343502/how-to-rsync-to-android

Interesting scripts:

/usr/share/rsync/scripts