RSync

Abdun Nihaal
https://nihaal.me
12 June 2021 at ILUGC
Creative Commons License

You need a backup

  • 3-2-1 Backup Strategy
    • Your working copy
    • Local backup (for quick access)
    • Remote backup (if we lose both local copy)
  • Set a system in place

RSync

  • Written in C
  • Supports Windows, Linux, OS X, BSD
  • Multiple GUI Frontends available (GSync, QSync, Zynk, etc)
  • General format

    rsync options /path/to/source/folder /path/to/backup/folder
    

What's good?

  • Uses a diff based transfer algorithm to reduce bandwidth usage
  • Works over SSH to backup remote files
  • Good for unidirectional static backups

What's not good?

  • Cannot be used easily for bi directional transfers
    • If you modify both copies simultaneously, try Syncthing instead
  • Moved and renamed files will be treated like new files and will be copied again. Some workarounds:
  • Diff based algorithm does not work well for compressed files

Things to note

  • RSync has different behaviour with and without trailing backslash
  • Databases need to be dumped to files for RSync to backup
  • Can be automated using crontab or SystemD timers
  • Always do a dry run before executing (especially with –delete)

Options

Option Used for
-a preserve user permissions, modified times
-r to copy recursively
-z transfers data in compressed format
-vhP verbose, human-readable, show progress
-e ssh transfer over ssh
-W whole file transfer (instead of diff based)

More options

Option Used for
–dry-run, -n does not modify filesystem
–delete removes files (in remote) that does not exist at source
–include="" –exclude="" to specify which files to include/exclude
–exclude-from=file exclude glob patterns specified in a file

Common uses

  • Full system backup (For more info)

    sudo rsync -aAXv \
    --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*",\
               "/run/*","/mnt/*","/media/*","/lost+found"} \
    / /path/to/backup/folder
    
  • Backup remote folder using ssh

    rsync -ave ssh /path/to/source/folder user@remote:~/backup/folder
    
  • Incremental backup

    rsync -arvhP --delete /path/to/source/folder /path/to/backup/folder