Skip to content

Instantly share code, notes, and snippets.

@dusenberrymw
Last active December 20, 2022 13:27
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dusenberrymw/5e25024fdf70ae3fc860682f4051b710 to your computer and use it in GitHub Desktop.
Save dusenberrymw/5e25024fdf70ae3fc860682f4051b710 to your computer and use it in GitHub Desktop.
Rsync Tips & Tricks

Rsync Tips & Tricks

  • rsync -auzPhv --delete --exclude-from=rsync_exclude.txt SOURCE/ DEST/ -n
    • -a -> --archive; recursively sync, preserving symbolic links and all file metadata
    • -u -> --update; skip files that are newer on the receiver; sometimes this is inaccurate (due to Git, I think...)
    • -z -> --compress; compression
    • -P -> --progress + --partial; show progress bar and resume interupted transfers
    • -h -> --human-readable; human-readable format
    • -v -> --verbose; verbose output
    • -n -> --dry-run; dry run; use this to test, and then remove to actually execute the sync
    • --delete -> delete files from destination if removed in source
    • --exclude-from -> file containing file patterns to exclude, one per line
  • Great resource: https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories-on-a-vps
.PHONY: send-dry send get-dry get copy-exp-dry copy-exp copy-master-dry copy-master
BASE = rsync
OPTIONS_SERVER = -auzPhv --delete
OPTIONS_EXPERIMENTAL = -azPhv
OPTIONS_MASTER = -azPhv
EXCLUDE_SERVER = --exclude-from=bin/rsync_exclude.txt
EXCLUDE_EXPERIMENTAL = --exclude-from=bin/rsync_exclude-experimental.txt
EXCLUDE_MASTER = --exclude-from=bin/rsync_exclude-master.txt
DRY = -n
LOCAL = ./
SERVER = UPDATE_SERVER_URL_HERE:~/path/to/project/on/server
REPO = /path/to/another/local/folder/to/copy/to/
SEND = $(BASE) $(OPTIONS_SERVER) $(EXCLUDE_SERVER) $(LOCAL) $(SERVER)
GET = $(BASE) $(OPTIONS_SERVER) $(EXCLUDE_SERVER) $(SERVER) $(LOCAL)
COPY_TO_EXPERIMENTAL = $(BASE) $(OPTIONS_EXPERIMENTAL) $(EXCLUDE_EXPERIMENTAL) $(LOCAL) $(REPO)
COPY_TO_MASTER = $(BASE) $(OPTIONS_MASTER) $(EXCLUDE_MASTER) $(LOCAL) $(REPO)
send-dry:
$(SEND) $(DRY)
send:
$(SEND)
get-dry:
$(GET) $(DRY)
get:
$(GET)
copy-exp-dry:
$(COPY_TO_EXPERIMENTAL) $(DRY)
copy-exp:
$(COPY_TO_EXPERIMENTAL)
copy-master-dry:
$(COPY_TO_MASTER) $(DRY)
copy-master:
$(COPY_TO_MASTER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment