rsync
a fast, versatile, remote (and local) file-copying tool
Options
-a, –archive | archive mode; equals -rlptgoD (no -H,-A,-X) |
-r, –recursive | recurse into directories |
-l, –links | copy symlinks as symlinks |
-p, –perms | preserve permissions |
-t, –times | preserve modification times |
-g, –group | preserve group |
-o, –owner | preserve owner (super-user only) |
-x, –one-file-system | don’t cross filesystem boundaries |
-D | same as –devices –specials |
–devices | preserve device files (super-user only) |
–specials | preserve special files |
–no-OPTION | turn off an implied OPTION (e.g. –no-D) |
-n, –dry-run | perform a trial run with no changes made |
–delete | delete extraneous files from dest dirs |
–info=FLAGS | fine-grained informational verbosity |
info flags
DEL | Mention deletions on the receiving side |
PROGRESS | Mention 1) per-file progress or 2) total transfer progress |
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