Created
January 18, 2019 19:45
-
-
Save francisco-perez-sorrosal/8c9fb906c2e943fd96dff6b0325070f4 to your computer and use it in GitHub Desktop.
Makefile for Rsync
This file contains 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
# Local-Remote synchronization of directories/files | |
# NOTE: Deletions are NOT considered yet. | |
# Usage | |
# ----- | |
# Local-remote sync: | |
# make -f Makefile.rsync lrsync SERVER=my_host PROJECT=project_name LOCAL_BASEDIR=/Users/my_name/dev REMOTE_BASEDIR=/home/my_name/dev | |
# | |
# Remote-local sync: | |
# make -f Makefile.rsync rlsync SERVER=my_host PROJECT=project_name LOCAL_BASEDIR=/Users/my_name/dev REMOTE_BASEDIR=/home/my_name/dev | |
REMOTE_DIR := $(REMOTE_BASEDIR)/$(PROJECT) | |
LOCAL_DIR := $(LOCAL_BASEDIR)/$(PROJECT) | |
get-remote-changes: | |
echo "Creating remote dir ($(REMOTE_DIR)) if it doesn't exist" | |
ssh -t $(SERVER) "mkdir -p $(REMOTE_DIR)" | |
rsync -avzru $(SERVER):$(REMOTE_DIR) $(LOCAL_BASEDIR) | |
put-local-changes: | |
echo "Creating local dir ($(LOCAL_DIR)) if it doesn't exist" | |
mkdir -p $(LOCAL_DIR) | |
rsync -avzru $(LOCAL_DIR) $(SERVER):$(REMOTE_BASEDIR) | |
lrsync: put-local-changes get-remote-changes | |
rlsync: get-remote-changes put-local-changes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment