projekty: server-backups/backup - add multiple options

wolvverine wolvverine at pld-linux.org
Mon May 7 11:19:57 CEST 2007


Author: wolvverine                   Date: Mon May  7 09:19:57 2007 GMT
Module: projekty                      Tag: HEAD
---- Log message:
- add multiple options

---- Files affected:
projekty/server-backups:
   backup (1.10 -> 1.11) 

---- Diffs:

================================================================
Index: projekty/server-backups/backup
diff -u projekty/server-backups/backup:1.10 projekty/server-backups/backup:1.11
--- projekty/server-backups/backup:1.10	Wed Mar 15 21:56:51 2006
+++ projekty/server-backups/backup	Mon May  7 11:19:52 2007
@@ -2,9 +2,7 @@
 #Michal Panasiewicz "wolvverine"
 #license GPL v2
 #TODO
-# - remove DIRSCRIPTS
 # - add SMB
-# - add multiple option
 # - add error control for config files
 # - add incremental backup
 # - add help option
@@ -12,7 +10,7 @@
 # - remove bashizm
 set -x
 ####################
- DIRSCRIPTS=/root/scripts # TODO - remove this
+ TEMPDIR=/var/tmp/backup-server 
  DIRETC=/etc/backups
  DATA=`date +%Y%m%d`
  TIME=`date +%H%M`
@@ -36,24 +34,50 @@
 TAROPT="-czpf"
 # TAROPT=" a -ed -ag -dh -m5 -v1140000 -x@/etc/backups/exclude"
 [ -f ${DIRETC}/backups.conf ] && . ${DIRETC}/backups.conf
-#[! -f ${DIRETC}/backdir ] 
-#[! -f ${DIRETC}/backsubdir ] 
-#[! -f ${DIRETC}/exclude ]
+[ ! -f ${DIRETC}/backdir ]  && echo " ${DIRETC}/backdir  not exist" && exit ;
+[ ! -f ${DIRETC}/backsubdir ] && echo " ${DIRETC}/backsubdir  not exist" && exit ;
+[ ! -f ${DIRETC}/exclude ] && echo " ${DIRETC}/exclude  not exist" && exit ;
+
+see_help=0
+bck_mysql=0
+use_dvd=0
+use_rsync=0
+up_backup_host=0
+
+BACKUP_ARGS="$*"
+for i in $BACKUP_ARGS; do
+	case "$i" in
+		--help | -h ) see_help=1 ;;
+		--mysql ) bck_mysql=1 ;;
+		--dvd ) use_dvd=1 ;;
+		--rsync) use_rsync=1 ;;
+		--upbckhost ) up_backup_host=1 ;;
+	esac
+done
+
+# help message
+if [ $see_help -eq 1 ]; then
+	echo "help" ;
+	exit;
+fi
 
-mkdir -p $BCK_HOME/$DATA-$TIME ;
+[ -f  $BCK_HOME/$DATA-$TIME ] && echo "$BCK_HOME/$DATA-$TIME exist" && stop ;
+[ ! -f  $BCK_HOME/$DATA-$TIME ] && mkdir -p $BCK_HOME/$DATA-$TIME ;
+[ ! -f  $TEMPDIR ] && mkdir -p $TEMPDIR ;
 touch /tmp/$DATA-$TIME-backup ;
 
-#TODO - optional this
-#obudzenie kompa skladujacego
-MACSTORHOST=`arp -a $STORHOST | awk '{print $4};'`
-wakelan -b $BRODCASTIP -m $MACSTORHOST > /tmp/$DATA-$TIME-error 2>&1
+# up backup-host
+if [ $up_backup_host -eq 1 ]; then
+	MACSTORHOST=`arp -a $STORHOST | awk '{print $4};'`
+	wakelan -b $BRODCASTIP -m $MACSTORHOST > /tmp/$DATA-$TIME-error 2>&1
 ERROR=$? ;	
-if [ ! ${ERROR} -eq 0 ];
-    then
-	echo "backup error ${ERROR}- wake host  - $DATA-$TIME !!!!" >> "/tmp/$DATA-$TIME-backup-error"
-	"cat /tmp/$DATA-$TIME-error" >> "/tmp/$DATA-$TIME-backup-error"
-	"cat /tmp/$DATA-$TIME-error" | ${PROGMAIL} -s "backup error ${ERROR}- wake host  - $DATA-$TIME !!!!" $RECIPIENT
+	if [ ! ${ERROR} -eq 0 ]; then
+		echo "backup error ${ERROR}- wake host  - $DATA-$TIME !!!!" >> "/tmp/$DATA-$TIME-backup-error"
+		"cat /tmp/$DATA-$TIME-error" >> "/tmp/$DATA-$TIME-backup-error"
+		"cat /tmp/$DATA-$TIME-error" | ${PROGMAIL} -s "backup error ${ERROR}- wake host  - $DATA-$TIME !!!!" $RECIPIENT
+	fi
 fi
+
 ##################
 # backup katalogow
 ##################
@@ -103,11 +127,11 @@
 #	cat /tmp/$DATA-$TIME-backup | ${PROGMAIL} -s "backup error ${ERROR} - tar.gz  - ${DATA-$TIME} !!!!" ${RECIPIENT} ;
 #fi
 
-###################
-#BACKUP bazy Mysql
-###################
+#######################
+# backup Mysql database
+#######################
 
-if [ $2 = mysql ]; then
+if [ $bck_mysql -eq 1 ]; then
     mysqldump -u ${MYSQLUSER}  --password=${MYSQLPASSWORD} -A | gzip -c9 > "${BCK_HOME}/${DATA}-${TIME}/mysql_base_full-${DATA}-${TIME}.gz" 
    #> "/tmp/$DATA-$TIME-error" 2>&1
     ERROR=$?
@@ -119,13 +143,13 @@
 fi
 
 #################
-# zapis backupu
+# write backups to:
 ##################
 ########################################
-# Wysłanie na dysk innego hosta po rsync
+# send to another host -  rsync
 ########################################
 
-if [ $1 = rsync ]; then
+if [ $use_rsync -eq 1 ]; then
     nice -n $NICELEVEL rsync -avzrp --stats  --password-file="${DIRETC}/rsyncpasswd" "${BCK_HOME}/$DATA-$TIME" $USERSTORHOST@$STORHOST::$DIRSTORHOST > "/tmp/$DATA-$TIME-error" 2>&1
     ERROR=$?
     if [ ! ${ERROR} -eq 0 ]; then
@@ -137,10 +161,10 @@
 ########################### END rsync
 
 #########################
-# Nagranie na plytke DVD
+# burn DVD 
 #########################
 
-if [ $1 = dvd ]; then
+if [ $use_dvd -eq 1 ]; then
     mkisofs -o "/var/tmp/backup-${DATA}-${TIME}.iso" -J -r -V "Backup_${DATA}-${TIME}" "/var/kopie/${DATA}-${TIME}" > /tmp/$DATA-$TIME-error 2>&1
     ERROR=$?;
         if [ ! ${ERROR} -eq 0 ]; then
@@ -148,7 +172,7 @@
 	    cat /tmp/$DATA-$TIME-error >> /tmp/$DATA-$TIME-backup-error
 	    cat /tmp/$DATA-$TIME-error | ${PROGMAIL} -s "backup error ${ERROR} - mkiso - $DATA-$TIME !!!!" $RECIPIENT ;
         fi
-    du -h /tmp/backup-$DATA-$TIME.iso >> $DIRSCRIPTS/backup-usage 
+    du -h /tmp/backup-$DATA-$TIME.iso >> $TEMPDIR/backup-usage 
 #TODO - configure drive and options
     dvdrecord -dao speed=2 dev=ATAPI:0,1,0 driveropts=burnfree /var/tmp/backup-$DATA-$TIME.iso > /tmp/$DATA-$TIME-error 2>&1
     ERROR=$?;
@@ -162,15 +186,15 @@
 ######################## END dvd
 
 ##TODO clean this
-    du -h ${BCK_HOME}/*${DATA}-${TIME}* > ${DIRSCRIPTS}/backup-usage
-    echo "$DATA-$TIME" > $DIRSCRIPTS/backup-date
+    du -h ${BCK_HOME}/*${DATA}-${TIME}* > ${TEMPDIR}/backup-usage
+    echo "$DATA-$TIME" > $TEMPDIR/backup-date
 
 ###reports backup OK or ERRORS
 if  [ -f /tmp/$DATA-$TIME-backup-error ]; then
-	cat "${DIRSCRIPTS}/backup-usage" >> /tmp/$DATA-$TIME-backup-error
+	cat "${TEMPDIR}/backup-usage" >> /tmp/$DATA-$TIME-backup-error
 	cat /tmp/$DATA-$TIME-backup-error | ${PROGMAIL} -s "backup ERROR !!! - $DATA-$TIME" $RECIPIENT
     else
-        cat "${DIRSCRIPTS}/backup-usage" >> /tmp/$DATA-$TIME-backup
+        cat "${TEMPDIR}/backup-usage" >> /tmp/$DATA-$TIME-backup
 	echo "$DATA-$TIME - ok" >> /var/log/backups
 	cat /tmp/$DATA-$TIME-backup | ${PROGMAIL} -s "backup OK - $DATA-$TIME" $RECIPIENT
 fi
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/projekty/server-backups/backup?r1=1.10&r2=1.11&f=u



More information about the pld-cvs-commit mailing list