Skip to content

Instantly share code, notes, and snippets.

@dimkouv
Created February 11, 2019 09:38
Show Gist options
  • Save dimkouv/d4c394041ee8af9b063ec42103c274af to your computer and use it in GitHub Desktop.
Save dimkouv/d4c394041ee8af9b063ec42103c274af to your computer and use it in GitHub Desktop.
Sync directories and files between two servers
#!/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