Created
May 26, 2019 18:17
-
-
Save Cactus64k/d79a0a8d4811c643dbc204cf4bc327a1 to your computer and use it in GitHub Desktop.
Backup script
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
#!/bin/bash | |
REMOTE=server.com | |
REMOTE_PATH=/mnt/backup | |
DATE=$(date +%F) | |
LOCAL_PATH="/home/cactus /etc" | |
LOCAL_EXCLUDE=/etc/cron.daily/backup_exclude | |
remote () { | |
ssh $REMOTE $@ | |
} | |
do_backup() { | |
echo 'Do backup' | |
remote mkdir $REMOTE_PATH/$DATE | |
rsync -az --progress --exclude-from=$LOCAL_EXCLUDE --link-dest=$REMOTE_PATH/current $LOCAL_PATH $REMOTE:$REMOTE_PATH/$DATE | |
remote unlink $REMOTE_PATH/current | |
remote ln -s $REMOTE_PATH/$DATE $REMOTE_PATH/current | |
remote "find $REMOTE_PATH -maxdepth 1 -type d -mtime +100 -exec rm -rf {} \;" | |
} | |
do_error() { | |
echo "ERROR: host $REMOTE offline" | |
} | |
if ping -c 1 $REMOTE &> /dev/null | |
then do_backup | |
else do_error | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment