Created
February 11, 2019 09:38
-
-
Save dimkouv/d4c394041ee8af9b063ec42103c274af to your computer and use it in GitHub Desktop.
Sync directories and files between two servers
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
#!/bin/bash | |
# sync.sh | |
# Syncs directories and files between two servers | |
MAIN_SERVER_IP='12.34.56.78' | |
REMOTE_KEY='/home/ubuntu/key.pem' | |
REMOTE_USER='ubuntu' | |
# from:to pairs | |
BACKUP_DIRS=( | |
"/home/ubuntu/downloads:/home/ubuntu/" | |
"/home/ubuntu/uploads:/home/ubuntu/" | |
) | |
for entry in "${BACKUP_DIRS[@]}" ; do | |
KEY="${entry%%:*}" | |
VALUE="${entry##*:}" | |
rsync -vrh $REMOTE_USER@$MAIN_SERVER_IP:$KEY $VALUE -e "ssh -i $REMOTE_KEY" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment