source: trunk/DataCheck/Transfer/BackupDatabase.sh@ 17298

Last change on this file since 17298 was 13305, checked in by Daniela Dorner, 13 years ago
added (script to backup databases)
  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#!/bin/bash
2#
3# This script backups the databases give in setup.XXX in the array dbnames
4#
5
6today=`date +%F`
7olday=`date +%F --date="-30day"`
8
9source `dirname $0`/../Sourcefile.sh
10printprocesslog "INFO starting $0"
11
12set -C
13
14logfile=$runlogpath"/BackupDatabase-"$datetime".log"
15date >> $logfile
16
17# store files on data
18path=/users/fact/DB_Backup
19
20# getdbsetup
21
22echo "today: $today" >> $logfile 2>&1
23echo "date to remove: $olday" >> $logfile 2>&1
24
25printprocesslog "INFO doing backup for the following databases: "${dbnames[@]}
26echo "doing backup for the following databases: "${dbnames[@]} >> $logfile 2>&1
27for dbname in ${dbnames[@]}
28do
29 filepath=$path/$dbname
30 command=$filepath"/Create_"$dbname"_"$today".txt"
31 oldcommand=$filepath"/Create_"$dbname"_"$olday".txt"
32 mkdir -pv $filepath >> $logfile 2>&1
33
34 file=$filepath/$dbname
35 sqlfile=$file"_"$today".sql"
36 oldzip=$file"_"$olday".sql.bz2"
37
38 printprocesslog "INFO removing old files..."
39 echo "removing old files..." >> $logfile 2>&1
40 if ls $oldzip >/dev/null 2>&1
41 then
42 rm -v $oldzip >> $logfile 2>&1
43 fi
44 if ls $oldcommand >/dev/null 2>&1
45 then
46 rm -v $oldcommand >> $logfile 2>&1
47 fi
48
49 printprocesslog "INFO writing create commands for database '"$dbname"' to "$command
50 echo "writing create commands for database '"$dbname"' to "$command >> $logfile 2>&1
51 # commands to create db
52 if ! mysqldump --host=localhost --database $dbname -u dump --no-data >| $command 2>> $logfile
53 then
54 printprocesslog "ERROR mysqldump failed for database '"$dbname"'"
55 echo "ERROR mysqldump failed for "$dbname >> $logfile 2>&1
56 rm -v $command >> $logfile 2>&1
57 fi
58
59 printprocesslog "INFO writing database '"$dbname"' to "$sqlfile
60 echo "writing database '"$dbname"' to "$sqlfile >> $logfile 2>&1
61 # mysqldump of full DB
62 if ! mysqldump --host=localhost --database $dbname -u dump >| $sqlfile 2>> $logfile
63 then
64 printprocesslog "ERROR mysqldump failed for database '"$dbname"'"
65 echo "ERROR mysqldump failed for database '"$dbname"'" >> $logfile 2>&1
66 rm -v $sqlfile >> $logfile 2>&1
67 else
68 if ! bzip2 -9 $sqlfile >> $logfile 2>&1
69 then
70 printprocesslog "ERROR zipping of "$sqlfile" failed."
71 echo "ERROR zipping of "$sqlfile" failed." >> $logfile 2>&1
72 fi
73 fi
74done
75
76dbdirwue=/home/operator/budb/fact_from_lp
77echo "" >> $logfile 2>&1
78echo `date`": rsyncing files in "$path" to Wuerzburg (coma: "$dbdirwue")" >> $logfile 2>&1
79printprocesslog "INFO rsyncing files in "$path" to Wuerzburg (coma: "$dbdirwue")"
80
81#rsync from gate to coma
82if ! /usr/bin/rsync -avxP $path operator@coma.astro.uni-wuerzburg.de:$dbdirwue >> $logfile 2>&1
83then
84 echo `date`": problem rsyncing database from LP ("$path") to Wuerzburg (coma:"$dbdirwue")"
85 printprocesslog "WARN problem rsyncing database from LP ("$path") to Wuerzburg (coma:"$dbdirwue")"
86fi
87
88finish >> $logfile 2>&1
89
Note: See TracBrowser for help on using the repository browser.