1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # This script backups the databases give in setup.XXX in the array dbnames
|
---|
4 | #
|
---|
5 |
|
---|
6 | today=`date +%F`
|
---|
7 | olday=`date +%F --date="-30day"`
|
---|
8 |
|
---|
9 | source `dirname $0`/../Sourcefile.sh
|
---|
10 | printprocesslog "INFO starting $0"
|
---|
11 |
|
---|
12 | set -C
|
---|
13 |
|
---|
14 | logfile=$runlogpath"/BackupDatabase-"$datetime".log"
|
---|
15 | date >> $logfile
|
---|
16 |
|
---|
17 | # store files on data
|
---|
18 | path=/users/fact/DB_Backup
|
---|
19 |
|
---|
20 | # getdbsetup
|
---|
21 |
|
---|
22 | echo "today: $today" >> $logfile 2>&1
|
---|
23 | echo "date to remove: $olday" >> $logfile 2>&1
|
---|
24 |
|
---|
25 | printprocesslog "INFO doing backup for the following databases: "${dbnames[@]}
|
---|
26 | echo "doing backup for the following databases: "${dbnames[@]} >> $logfile 2>&1
|
---|
27 | for dbname in ${dbnames[@]}
|
---|
28 | do
|
---|
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 --databases $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 --databases $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
|
---|
74 | done
|
---|
75 |
|
---|
76 | dbdirwue=/home/operator/budb/fact_from_lp
|
---|
77 | echo "" >> $logfile 2>&1
|
---|
78 | echo `date`": rsyncing files in "$path" to Wuerzburg (coma: "$dbdirwue")" >> $logfile 2>&1
|
---|
79 | printprocesslog "INFO rsyncing files in "$path" to Wuerzburg (coma: "$dbdirwue")"
|
---|
80 |
|
---|
81 | #rsync from gate to coma
|
---|
82 | if ! /usr/bin/rsync -avxP $path operator@coma.astro.uni-wuerzburg.de:$dbdirwue >> $logfile 2>&1
|
---|
83 | then
|
---|
84 | echo `date`": problem rsyncing database from LP ("$path") to Wuerzburg (coma:"$dbdirwue")" >> $logfile 2>&1
|
---|
85 | printprocesslog "CONNECTION problem rsyncing database from LP ("$path") to Wuerzburg (coma:"$dbdirwue")"
|
---|
86 | fi
|
---|
87 |
|
---|
88 | finish >> $logfile 2>&1
|
---|
89 |
|
---|