Ignore:
Timestamp:
08/08/11 10:46:05 (13 years ago)
Author:
Daniela Dorner
Message:
adapted to allow backup of defined databases
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/datacenter/scripts/budb

    r9291 r11842  
    1818#
    1919#
    20 #   Author(s): Daniela Dorner  10/2006 <mailto:dorner@astro.uni-wuerzburg.de>
     20#   Author(s): Daniela Dorner  10/2006 <mailto:daniela.dorner@unige.ch>
    2121#
    22 #   Copyright: MAGIC Software Development, 2000-2008
     22#   Copyright: MAGIC Software Development, 2000-2011
    2323#
    2424#
    2525# ========================================================================
    2626#
    27 # This script backups the Magic Database.
    28 # In addition it writes out the commands how to create the database.
     27# This script backups the databases give in setup.XXX in the array dbnames
     28#
     29# In addition, it writes out the commands how to create the database
     30# MyMagic, in case all databases are backuped.
    2931#
    3032
     
    3739set -C
    3840
    39 path=/home/`whoami`/budb
     41path=/home/`whoami`/DB_Backup
    4042logpath=$path/log
     43filepath=$path/files
    4144mkdir -pv $logpath
     45mkdir -pv $filepath
    4246logfile=$logpath/budb$today.log
    4347oldlog=$logpath/budb$olday.log
    44 file=$path/alldatabases
    45 end=.sql.bz2
    46 zipfile=$file$today$end
    47 oldzip=$file$olday$end
    48 
    49 dbname=MyMagic
    50 command=$path/Create$dbname$today.txt
    51 oldcommand=$path/Create$dbname$olday.txt
    5248
    5349date > $logfile
     
    5753echo "date to remove: $olday" >> $logfile 2>&1
    5854
    59 echo "removing old files..." >> $logfile 2>&1
    60 rm -v $oldzip >> $logfile 2>&1
    61 rm -v $oldlog >> $logfile 2>&1
    62 rm -v $oldcommand >> $logfile 2>&1
     55if ls $oldlog >/dev/null 2>&1
     56then
     57   echo "removing old logfile..." >> $logfile 2>&1
     58   rm -v $oldlog >> $logfile 2>&1
     59fi
    6360
    64 echo "writing all databases to $zipfile..." >> $logfile 2>&1
     61if [ "${dbnames[0]}" == "all" ]
     62then
     63   dbname=MyMagic
     64   command=$filepath/Create$dbname$today.txt
     65   oldcommand=$filepath/Create$dbname$olday.txt
     66   file=$filepath/alldatabases
     67   end=.sql.bz2
     68   zipfile=$file$today$end
     69   oldzip=$file$olday$end
    6570
    66 # complete databases
    67 if ! mysqldump --host=$ho --all-databases -u dump | bzip2 -9 -c >| $zipfile 2>> $logfile
    68 then
    69    printprocesslog "ERROR mysqldump failed "
    70    echo "ERROR mysqldump failed " >> $logfile 2>&1
    71 fi
    72 echo "writing create commands to $command..." >> $logfile 2>&1
    73 # commands to create MyMagic
    74 if ! mysqldump --host=$ho --database $dbname -u dump --no-data >| $command 2>> $logfile
    75 then
    76    printprocesslog "ERROR mysqldump failed "
    77    echo "ERROR mysqldump failed " >> $logfile 2>&1
     71   echo "removing old files..." >> $logfile 2>&1
     72   if ls $oldzip >/dev/null 2>&1
     73   then
     74      rm -v $oldzip >> $logfile 2>&1
     75   fi
     76   if ls $oldcommand >/dev/null 2>&1
     77   then
     78      rm -v $oldcommand >> $logfile 2>&1
     79   fi
     80 
     81   echo "writing create commands to $command..." >> $logfile 2>&1
     82   # commands to create MyMagic
     83   if ! mysqldump --host=$ho --database $dbname -u dump --no-data >| $command 2>> $logfile
     84   then
     85      printprocesslog "ERROR mysqldump failed "
     86      echo "ERROR mysqldump failed " >> $logfile 2>&1
     87   fi
     88
     89   echo "writing all databases to $zipfile..." >> $logfile 2>&1
     90   # complete databases
     91   if ! mysqldump --host=$ho --all-databases -u dump | bzip2 -9 -c >| $zipfile 2>> $logfile
     92   then
     93     printprocesslog "ERROR mysqldump failed "
     94     echo "ERROR mysqldump failed " >> $logfile 2>&1
     95   fi
     96else
     97   echo "doing backup for the following databases: "${dbnames[@]}  >> $logfile 2>&1
     98   for dbname in ${dbnames[@]}
     99   do
     100      filepath2=$filepath/$dbname
     101      command=$filepath2"/Create_"$dbname"_"$today".txt"
     102      oldcommand=$filepath2"/Create_"$dbname"_"$olday".txt"
     103      mkdir -pv $filepath2
     104
     105      file=$filepath2/$dbname
     106      end=.sql.bz2
     107      zipfile=$file"_"$today$end
     108      oldzip=$file"_"$olday$end
     109
     110      echo "removing old files..." >> $logfile 2>&1
     111      if ls $oldzip >/dev/null 2>&1
     112      then
     113         rm -v $oldzip >> $logfile 2>&1
     114      fi
     115      if ls $oldlog >/dev/null 2>&1
     116      then
     117         rm -v $oldlog >> $logfile 2>&1
     118      fi
     119      if ls $oldcommand >/dev/null 2>&1
     120      then
     121         rm -v $oldcommand >> $logfile 2>&1
     122      fi
     123
     124      echo "writing create commands to $command..." >> $logfile 2>&1
     125      # commands to create db
     126      if ! mysqldump --host=$ho --database $dbname -u dump --no-data >| $command 2>> $logfile
     127      then
     128         printprocesslog "ERROR mysqldump failed "
     129         echo "ERROR mysqldump failed " >> $logfile 2>&1
     130      fi
     131
     132      echo "writing database $dbname to $zipfile..." >> $logfile 2>&1
     133     
     134      if ! mysqldump --host=$ho --database $dbname -u dump | bzip2 -9 -c >| $zipfile 2>> $logfile
     135      then
     136        printprocesslog "ERROR mysqldump failed "
     137        echo "ERROR mysqldump failed " >> $logfile 2>&1
     138      fi
     139   done
    78140fi
    79141
Note: See TracChangeset for help on using the changeset viewer.