This is an old revision of the document!
Rsync
These are my rsync notes. I also used to use rsnapshot, however I was unhappy with the performance of this application and moved to restic. The original rsnapshot notes have been rolled up and moved to the bottom of this page.
Rsync Notes
An Important Notes
A trailing slash (/) at the end of the first argument in the rsync command: rsync -a dir1/ dir2
, mean “the contents of dir1”. The alternative, without the trailing slash, would place dir1, including the directory, within dir2. This would create a hierarchy that looks like: ~/dir2/dir1/[files]
So;
rsync -a dir1/ dir2
copies the contents only of dir1 into dir2rsync -a dir1 dir2
copies dir1 and its contents into dir2
Where
-a
is the flag for archive. Keeps original dates and permissions on copy and also recurses, copied sub-directories and content.-u
only copies source files where they are newer than destination files (based upon file modification dates)–delete
deletes files on the destination where they are not on the source. Use with care!-n
is for dry run, no changes are made, but proposed output is seen-P
keeps partially copies files and reports progress-h
' human readable file sizes-v
increase output verbosity-z
compress files on transfer
Always double-check your arguments before executing an rsync command. Rsync provides a method for doing this by passing the -n
or -–dry-run
options. The -v flag (for verbose) is also necessary to get the appropriate output:
rsync daemon
rsync can be installed as a daemon on a computer instance
To install rsync daemon sudo apt install rsync
sudo vim /etc/rsyncd.conf
# create new # any name you like [all] # destination directory to copy path = / # hosts you allow to access hosts allow = 192.168.1.5 hosts deny = * list = true uid = root gid = root read only = false # auth users = baumkp # secrets file = /etc/rsyncd.secrets
sudo vim /etc/rsyncd.secrets
username:userpassword
sudo systemctl status rsync.service
[status, start, stop, restart, reload, disable, enable]
Compression option -z can slow down file transfer.
export RSYNC_SKIP_COMPRESS=3fr/3g2/3gp/3gpp/7z/aac/ace/amr/apk/appx/appxbundle/arc/arj/arw/asf/avi/bz2/cab/cr2/crypt[5678]/dat/dcr/deb/dmg/drc/ear/erf/flac/flv/gif/gpg/gz/iiq/iso/jar/jp2/jpeg/jpg/k25/kdc/lz/lzma/lzo/m4[apv]/mef/mkv/mos/mov/mp[34]/mpeg/mp[gv]/msi/nef/oga/ogg/ogv/opus/orf/pef/png/qt/rar/rpm/rw2/rzip/s7z/sfx/sr2/srf/svgz/t[gb]z/tlz/txz/vob/wim/wma/wmv/xz/zip
rsync --skip-compress=$RSYNC_SKIP_COMPRESS …..
sudo rsync --dry-run -av -u –delete /media/Disk1/ baumkp@192.168.1.10::all/media/disk1 –exclude=snapraid.* --exclude=.Trash* --exclude=lost* >tmp.txt
sudo rsync -av -Puh --delete /media/Disk1/ baumkp@192.168.1.10::all/media/disk1 --exclude=snapraid.* --exclude=.Trash* --exclude=lost* >tmp.txt
Do not use from old to new on disk 2!
xxx sudo rsync x --dry-run -avz -u --delete /media/Disk2/ baumkp@192.168.1.10::all/media/disk2 --exclude=snapraid.* --exclude=.Trash* >tmp.txt
xxx sudo rsync x -a -Puh --delete /media/Disk2/ baumkp@192.168.1.10::all/media/disk2 --exclude=snapraid.* --exclude=.Trash* >tmp.txt
sudo rsync --dry-run -avz -u --delete /Disk2/ baumkp@192.168.1.10::all/media/disk2 --exclude=snapraid.* --exclude=.Trash* >tmp.txt
sudo rsync --dry-run -avz -u --delete ~/Myscripts/ /home/shared/Myscripts
sudo rsync x --dry-run -avz -u /home/shared/temp/ baumkp@192.168.1.10::all/home/shared/html_kptree.net --exclude=.Trash* >tmp.txt
sudo rsync x -a -Puh /home/shared/temp/ baumkp@192.168.1.10::all/home/shared/html_kptree.net --exclude=.Trash* >tmp.txt
some rsync flag definitions
Flag Short | Flag Long | Description |
---|---|---|
-z | --compress | compress file data during the transfer |
-v | --verbose | increase verbosity |
-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 |
-o | --owner | preserve owner (super-user only) |
-g | --group | preserve group |
-D | same as –devices –specials | |
--devices | preserve device files (super-user only) | |
--specials | preserve special files | |
-H | --hard-links | preserve hard links * |
-A | --acls | preserve ACLs (implies -p) |
-X | --xattrs | preserve extended attributes |
-n | --dry-run | perform a trial run with no changes made |
--delete | delete extraneous files from destination | |
-P | same as --partial --progress | |
--partial | keep partially transferred files | |
--progress | show progress during transfer | |
-h | --human-readable | output numbers in a human-readable format |
-u | --update | skip files that are newer on the receiver |
--exclude=PATTERN | exclude files matching PATTERN | |
--numeric-ids | don't map uid/gid values by user/group name | |
-R | --relative | Use relative paths. This means that the full path names specified on the command line are sent to the server rather than just the last parts of the filenames. |
--delete-excluded | also delete excluded files from dest dirs |
Note(s):
- * preservation of hard links is important when moving across rsnapshots backups between disks.
My web page copy bash batch:
sudo vim Myscripts/rsync_shared.sh
or to run sudo bash Myscripts/rsync_shared.sh
#Note this is a local only script and takes no additional batch inputs when run!
#!/bin/bash wwwpath='/home/shared/www/html' workpath='/home/shared/html_kptree.net/' cmd="rsync -ptoguv --chown=root:www-data --chmod=a+rwx,g+rwx,o-wx" $cmd ${workpath}/styles.css ${wwwpath} $cmd ${workpath}/w3.css ${wwwpath} $cmd ${workpath}/index.html ${wwwpath} $cmd ${workpath}/email_server_w3.html ${wwwpath}
Rsync related links
Rsnapshot
These are some rsnapshot and related rsync notes. They are really long! Sadly the original source was only onlie for a few years.