Last active
January 6, 2023 15:20
-
-
Save SmartFinn/8223cde9592dbe2b088ccfeb8357e042 to your computer and use it in GitHub Desktop.
[Makefile] Yet another wrapper for rsync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/Makefile | |
/.rsyncignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Yet another rsync wrapper | |
# | |
# use the `make dry-run <action>` if you want to know what will happen | |
LOCAL := $(CURDIR) | |
REMOTE := /media/vault/Photos | |
OPTIONS := --recursive --links --times --omit-dir-times --human-readable --progress | |
ifneq ($(wildcard .rsyncignore),) | |
OPTIONS += --exclude-from=".rsyncignore" | |
endif | |
help: | |
@echo "Usage: make [modes] <action> [actions]" | |
@echo | |
@echo "Actions:" | |
@echo | |
@echo " pull" | |
@echo " |- pull-new download missing files" | |
@echo " |- pull-changed update existing files if changed" | |
@echo " \`- pull-deleted delete files that missing on REMOTE" | |
@echo | |
@echo " push" | |
@echo " |- push-new upload new files that missing on REMOTE" | |
@echo " |- push-changed upload existing files if changed" | |
@echo " \`- push-deleted delete files that missing on LOCAL" | |
@echo | |
@echo " sync synchronize LOCAL and REMOTE without deleting" | |
@echo | |
@echo "Modes:" | |
@echo | |
@echo " dry[-run] perform a trial run with no changes made" | |
@echo " lazy transfer files only if size is different" | |
@echo " strict transfer files only if checksum does not match" | |
dry dry-run: | |
$(eval OPTIONS += --dry-run) | |
$(eval _MODE += $@) | |
@true | |
lazy: | |
$(eval OPTIONS += --size-only) | |
$(eval _MODE += $@) | |
@true | |
strict: | |
$(eval OPTIONS += --checksum) | |
$(eval _MODE += $@) | |
@true | |
pull: pull-new pull-changed pull-deleted | |
pull-new: | |
@rsync $(OPTIONS) --ignore-existing "$(REMOTE)/" "$(LOCAL)/" \ | |
| sed -e '1d' -e 's/^/($(strip $(_MODE) $@)) | /' | |
pull-changed: | |
@rsync $(OPTIONS) --update --existing "$(REMOTE)/" "$(LOCAL)/" \ | |
| sed -e '1d' -e 's/^/($(strip $(_MODE) $@)) | /' | |
pull-deleted: | |
@rsync $(OPTIONS) --delete --existing --ignore-existing "$(REMOTE)/" "$(LOCAL)/" \ | |
| sed -e '1d' -e 's/^/($(strip $(_MODE) $@)) | /' | |
push: push-new push-changed push-deleted | |
push-new: | |
@rsync $(OPTIONS) --ignore-existing "$(LOCAL)/" "$(REMOTE)/" \ | |
| sed -e '1d' -e 's/^/($(strip $(_MODE) $@)) | /' | |
push-changed: | |
@rsync $(OPTIONS) --update --existing "$(LOCAL)/" "$(REMOTE)/" \ | |
| sed -e '1d' -e 's/^/($(strip $(_MODE) $@)) | /' | |
push-deleted: | |
@rsync $(OPTIONS) --delete --existing --ignore-existing "$(LOCAL)/" "$(REMOTE)/" \ | |
| sed -e '1d' -e 's/^/($(strip $(_MODE) $@)) | /' | |
sync: push-changed pull-changed push-new pull-new | |
.PHONY: dry dry-run lazy strict pull pull-new pull-changed pull-deleted \ | |
push push-new push-changed push-deleted sync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment