Rsync Backups

Friday, December 22 2023

Rsync is a file transfer program capable of efficient remote updates via a fast differencing algorithm. In laymans terms, it allows you to copy data from a source to a destination very quickly. Here is how I perform my backups with it.

rsync -va --delete --exclude "venv" --exclude ".git" --exclude "__pycache__" john@192.168.0.123:/home/john/games :~/Documents :/etc/systemd/system/website.service :/etc/nginx/sites-enabled :~/file.txt ~/backup_john_123/

  • --verbose, -v                   increase verbosity
  • --archive, -a                    archive mode is -rlptgoD (no -A,-X,-U,-N,-H)
  • --recursive, -r                  recurse into directories
  • --links, -l                         copy symlinks as symlinks
  • --perms, -p                     preserve permissions
  • --times, -t                       preserve modification times
  • --group, -g                      preserve group
  • --owner, -o                     preserve owner (super-user only)
  • -D                                   same as --devices --specials
  • --devices                        preserve device files (super-user only)
  • --delete                          delete extraneous files from dest dirs
  • --exclude=PATTERN       exclude files matching PATTERN

If you're trying to connect to a server with a non-standard SSH port (e.g. 5678 and not 22), you can include -e "ssh -p 5678". That is,

rsync -va --delete -e "ssh -p 5678" --exclude "venv" --exclude ".git" --exclude "__pycache__" john@192.168.0.123:/home/john/games :/home/john/photos :/home/john/file.txt ~/backup_john_123/

Comment
Optional
No comments yet...