Skip to content

Instantly share code, notes, and snippets.

@pstaender
Last active August 29, 2015 14:04
Show Gist options
  • Save pstaender/ba09e3b4121923881fd1 to your computer and use it in GitHub Desktop.
Save pstaender/ba09e3b4121923881fd1 to your computer and use it in GitHub Desktop.
Simple script to backup (many) remote server files. Includes a lock to avoid concurrent execution.
#!/bin/sh
TARGET=/Volumes/Backup/vserver
SOURCE="root@server01:/folder;root@sever02:/folder"
EXCLUDE="--exclude='.DS_Store'"
LOCK="/tmp/backupserver.lock"
if [ -f "$LOCK" ]; then
echo "locked… remove $LOCK to proceed" >&2
exit 1
else
echo $$ > $LOCK
fi
mkdir -p $TARGET
if [ -d "$TARGET" ]; then
for source in $(echo $SOURCE | tr ";" "\n")
do
FOLDERNAME=$(echo $source | sed -E -e 's/[\:\/]/_/g' -e 's/[\_]+/_/g')
FOLDER=$TARGET/$FOLDERNAME
echo "sync $source -> $FOLDER/"
# to avoid problems in filename encoding on a mac use --iconv=UTF8-MAC,UTF-8 (rysnc 3+ required)
rsync $EXCLUDE --include="core" --cvs-exclude --verbose --compress --archive --progress --human-readable --delete $source $FOLDER/
done
fi
rm -f $LOCK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment