source: trunk/Mars/datacenter/scripts/budb@ 19270

Last change on this file since 19270 was 11842, checked in by Daniela Dorner, 13 years ago
adapted to allow backup of defined databases
  • Property svn:executable set to *
File size: 4.1 KB
Line 
1#!/bin/bash
2#
3# ========================================================================
4#
5# *
6# * This file is part of MARS, the MAGIC Analysis and Reconstruction
7# * Software. It is distributed to you in the hope that it can be a useful
8# * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9# * It is distributed WITHOUT ANY WARRANTY.
10# *
11# * Permission to use, copy, modify and distribute this software and its
12# * documentation for any purpose is hereby granted without fee,
13# * provided that the above copyright notice appear in all copies and
14# * that both that copyright notice and this permission notice appear
15# * in supporting documentation. It is provided "as is" without express
16# * or implied warranty.
17# *
18#
19#
20# Author(s): Daniela Dorner 10/2006 <mailto:daniela.dorner@unige.ch>
21#
22# Copyright: MAGIC Software Development, 2000-2011
23#
24#
25# ========================================================================
26#
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.
31#
32
33today=`date +%F`
34olday=`date +%F --date="-30day"`
35
36source `dirname $0`/sourcefile
37printprocesslog "INFO starting $0"
38
39set -C
40
41path=/home/`whoami`/DB_Backup
42logpath=$path/log
43filepath=$path/files
44mkdir -pv $logpath
45mkdir -pv $filepath
46logfile=$logpath/budb$today.log
47oldlog=$logpath/budb$olday.log
48
49date > $logfile
50getdbsetup
51
52echo "today: $today" >> $logfile 2>&1
53echo "date to remove: $olday" >> $logfile 2>&1
54
55if ls $oldlog >/dev/null 2>&1
56then
57 echo "removing old logfile..." >> $logfile 2>&1
58 rm -v $oldlog >> $logfile 2>&1
59fi
60
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
70
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
140fi
141
142finish >> $logfile 2>&1
143
Note: See TracBrowser for help on using the repository browser.