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:dorner@astro.uni-wuerzburg.de>
|
---|
21 | #
|
---|
22 | # Copyright: MAGIC Software Development, 2000-2008
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | # This script backups the Magic Database.
|
---|
28 | # In addition it writes out the commands how to create the database.
|
---|
29 | #
|
---|
30 |
|
---|
31 | today=`date +%F`
|
---|
32 | olday=`date +%F --date="-30day"`
|
---|
33 |
|
---|
34 | source `dirname $0`/sourcefile
|
---|
35 | printprocesslog "INFO starting $0"
|
---|
36 |
|
---|
37 | set -C
|
---|
38 |
|
---|
39 | path=/home/`whoami`/budb
|
---|
40 | logpath=$path/log
|
---|
41 | mkdir -pv $logpath
|
---|
42 | logfile=$logpath/budb$today.log
|
---|
43 | oldlog=$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
|
---|
52 |
|
---|
53 | date > $logfile
|
---|
54 | getdbsetup
|
---|
55 |
|
---|
56 | echo "today: $today" >> $logfile 2>&1
|
---|
57 | echo "date to remove: $olday" >> $logfile 2>&1
|
---|
58 |
|
---|
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
|
---|
63 |
|
---|
64 | echo "writing all databases to $zipfile..." >> $logfile 2>&1
|
---|
65 |
|
---|
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
|
---|
78 | fi
|
---|
79 |
|
---|
80 | finish >> $logfile 2>&1
|
---|
81 |
|
---|