Created
March 22, 2011 09:20
-
-
Save kristm/880971 to your computer and use it in GitHub Desktop.
bash script for adhoc deployment and backup to large systems. useful for deploying updates to systems without version control
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 | |
usage="Usage: magback.sh <tarball file> <deploy|restore|clear>" | |
writelog(){ | |
echo $1 >> .magback.log | |
if [ $# -eq 2 ]; | |
then | |
echo $1 | |
fi | |
} | |
if [ $# -lt 2 ]; | |
then | |
echo $usage | |
exit | |
elif [ ! -e $1 ]; | |
then | |
echo "File does not exist" | |
exit | |
elif [ ! -e 'magback.log' ]; | |
then | |
touch .magback.log | |
fi | |
writelog "start magback.sh" | |
writelog "`date`" | |
case "$2" in | |
d | deploy) | |
writelog "deploy operation: $1" | |
;; | |
r | restore) | |
writelog "restore operation: $1" | |
;; | |
c | clear) | |
writelog "clear operation: $1" | |
;; | |
*) | |
writelog "unknown operation $2" | |
writelog "quitting" | |
exit | |
;; | |
esac | |
for i in $(tar tvf $1|awk '{print $9}'); do | |
case "$2" in | |
d | deploy) | |
if [ -e $i ]; | |
then | |
writelog "creating backup: $i.0" "x" | |
cp $i $i.0 | |
fi | |
writelog "deploying $i" "x" | |
tar xzf $1 $i | |
;; | |
r | restore) | |
if [ -e $i.0 ]; | |
then | |
cp $i.0 $i | |
writelog "restored $i" "x" | |
else | |
writelog "backup not found $i.0" "x" | |
fi | |
;; | |
c | clear) | |
if [ -e $i.0 ]; | |
then | |
rm $i.0 | |
writelog "removed $i.0" "x" | |
fi | |
;; | |
*) | |
echo $usage | |
exit | |
;; | |
esac; | |
done | |
writelog "done" "x" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment