Skip to content

Instantly share code, notes, and snippets.

@sageworksstudio
Last active July 17, 2020 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sageworksstudio/d58822998a30fa9c3e6eae3f68d004cf to your computer and use it in GitHub Desktop.
Save sageworksstudio/d58822998a30fa9c3e6eae3f68d004cf to your computer and use it in GitHub Desktop.
rsync cheatsheet

rsync

TFM https://linux.die.net/man/1/rsync

Copy a directory and it's contents

$rsync -av --progress /folder/to/backup/* /destination/of/backup/

Log results

To log results add the log flag

--log-file=/path/to/rlogfile

Copy a directory and it's content, but exclude a sub-directory

$rsync -av --progress --exclude="dir" /folder/to/backup/* /destination/of/backup/

Copy a directory and it's content, but exclude multiple sub-directories

$rsync -av --progress --exclude="dir" --exclude="dir2" --exclude="dir3" /folder/to/backup/* /destination/of/backup/

Sync a directory (incremental backups)

Note1: The --delete option. If a file is deleted in the source it will be deleted in the backup as well.

Note2: The trailing slash on the source tells rsync to backup the contents of that directory. If you also want the directory itself to be backed up, remove the trailing slash.

$ rsync -avzhP --log-file=/path/to/rlogfile --delete --exclude='node_modules' --exclude='vendor' /path/to/source/ /path/to/backup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment