Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rmi1974/326225f20d298d0f7ba30fd6def65134 to your computer and use it in GitHub Desktop.
Save rmi1974/326225f20d298d0f7ba30fd6def65134 to your computer and use it in GitHub Desktop.
How to use rsync tool to synchronize directories #rsync #commandlinefu

Use rsync to synchronize directories

# -a  : all files, with permissions, etc..
# -x  : stay on one file system
# -H  : preserve hard links (not included with -a)
# -A  : preserve ACLs/permissions (not included with -a)
# -W  : copy files whole (w/o delta-xfer algorithm) - usually faster
# -X  : preserve extended attributes (not included with -a)
# -S  : handle sparse files efficiently
# --numeric-ids : avoid mapping uid/gid values by user/group name
# --info=progress2 : overall progress, instead for individual files, useful for large transfers
# --delete : delete extraneous files from dest dir(s)

sudo rsync -axHAWXS --numeric-ids --info=progress2 $SOURCE_DIR/ $TARGET_DIR --delete

To preserve the target ownership:

sudo rsync -axHAWXS --numeric-ids --no-owner --no-group --info=progress2 $SOURCE_DIR/ $TARGET_DIR --delete 

Make sure to not include source directory in target path and also beware of trailing slashes.

rsync -avhW --delete --times --no-compress --progress --exclude=Cache $SOURCE_DIR $TARGET_DIR/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment