Created
December 19, 2010 22:15
-
-
Save starenka/747751 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
TAR_MAC="00:1f:d0:**:**:**" | |
TAR_HOST="bedna" | |
TAR_USER="starenka" | |
MAX_BW=400 #KB/s | |
MAX_TRIES=5 | |
INTERVAL_TRIES=30 | |
DIALOG_TITLE="--display :0 --title Backup" | |
DIRS=('/photo' '/www' '/prac' '/home/starenka/.scripts' '/home/starenka/bin' '/mail' '/home/starenka/.opera' '/home/starenka/jobs' '/home/starenka/.purple ' | |
) | |
EXCLUDE=('.opera/cache/' '.bzr' '.svn' '.git' | |
) | |
kdialog --passivepopup 'Starting regular backup batch' 5 | |
if [ `ping -s 1 -c 1 $TAR_HOST > /dev/null; echo $?` -eq 1 ]; then | |
kdialog $DIALOG_TITLE --passivepopup "$TAR_HOST is down, sending magic packet" 5 | |
wakeonlan $TAR_MAC | |
TRIES=0 | |
until [ `ping -s 1 -c 1 $TAR_HOST > /dev/null; echo $?` -eq 0 ]; do | |
let TRIES=TRIES+1 | |
if [ $TRIES -eq $MAX_TRIES ]; then | |
kdialog $DIALOG_TITLE --sorry "$TAR_HOST not responding, giving up..." 5 | |
exit 1 | |
fi | |
kdialog $DIALOG_TITLE --passivepopup "$TAR_HOST not responding, waiting for ping ($TRIES)..." 5 | |
sleep $INTERVAL_TRIES | |
done | |
fi | |
for db in ${DIRS[@]} | |
do | |
kdialog $DIALOG_TITLE --passivepopup "Starting $db" 5 | |
rsync -Prazvh --delete "${EXCLUDE[@]/#/--exclude=}" --copy-links --bwlimit=$MAX_BW -e ssh "$db" ${TAR_USER}@${TAR_HOST}:/backups | |
kdialog $DIALOG_TITLE --passivepopup "Backup of $db has finished" 5 | |
done | |
kdialog $DIALOG_TITLE --passivepopup 'Backup finished' 5 | |
kdialog $DIALOG_TITLE --yesno "Backup has finished. Shoudl I halt the remote machine ($TAR_HOST)?" | |
if [ $? -eq 0 ]; then | |
kdialog $DIALOG_TITLE --passivepopup "Halting $TAR_HOST" 5 | |
echo 'sudo halt' | ssh ${TAR_USER}@${TAR_HOST} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment