-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackup.sh
More file actions
executable file
·118 lines (105 loc) · 2.85 KB
/
backup.sh
File metadata and controls
executable file
·118 lines (105 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
if [ "$1" = "?" -o "$1" = "-?" ] ; then
echo "First argument should be level (day|week|db|conf|all), second - target directory"
exit 0
fi
if [ -z $CONFIGDIR ] ; then
if [ "`uname -s`" = "Darwin" ] ; then
CONFIGDIR=/Library/WebObjects/Configuration/rujel
if ! which -s mysqldump ; then
alias mysqldump=/usr/local/mysql/bin/mysqldump
fi
else
CONFIGDIR=$NEXT_ROOT/Local/Library/WebObjects/Configuration/rujel
fi
fi
CONF=$CONFIGDIR/modules/database.plist
if [ ! -e $CONF ] ; then
echo "DataBase configuration file not found"
exit 1
fi
USERNAME=`sed -n "s/.*<key>username<\/key>[^a-z]*<string>\(.*\)<\/string>.*/\1/p" $CONF`
if [ -z $USERNAME ] ; then
USERNAME=`sed -n "/<key>username<\/key>/,/<\/string>/ s/.*<string>\(.*\)<\/string>.*/\1/p" $CONF`
fi
PASSWORD=`sed -n "s/.*<key>password<\/key>[^a-z]*<string>\(.*\)<\/string>.*/\1/p" $CONF`
if [ -z $PASSWORD ] ; then
PASSWORD=`sed -n "/<key>password<\/key>/,/<\/string>/ s/.*<string>\(.*\)<\/string>.*/\1/p" $CONF`
fi
if [ ! -z $PASSWORD ] ; then
PASSWORD="--password=$PASSWORD"
fi
PWD=`pwd`
if [ -n "$2" ] ; then
# mkdir -p $2
if [ ! -d $2 ] ; then
echo "First argument should be level (day|week|db|conf|all), second - target directory"
exit 1
fi
cd $2
fi
if [ "`uname -s`" = "Darwin" ] ; then
FILE="RujelBackup_`date -j -v -1m +%F`_$KEY.sql.bz2"
else
FILE="RujelBackup_`date -d \"1 month ago\" +%F`_$KEY.sql.bz2"
fi
KEY=$1
if [ "$1" != "week" ] ; then
CONF=$CONFIGDIR/rujel.plist
if [ -e $CONF ] ; then
NYM=`sed -n "s/.*<key>newYearMonth<\/key>[^a-z]*<[a-z]*>\([0-9]*\)<\/[a-z]*>.*/\1/p" $CONF`
if [ -z $NYM ] ; then
NYM=`sed -n "/<key>newYearMonth<\/key>/,/<\/[a-z]*>/ s/.*<[a-z]*>\([0-9]*\)<\/[a-z]*>.*/\1/p" $CONF`
fi
fi
if [ -z $NYM ] ; then
NYM=7
else
NYM=$(($NYM+1))
fi
BASE="RujelStatic"
YEAR=`date +%Y`
if [ $NYM -gt `date +%m` ] ; then
YEAR=$(($YEAR-1))
fi
if [ $NYM -eq `date +%m` ] ; then
BASE="$BASE RujelYear$YEAR"
YEAR=$(($YEAR-1))
fi
BASE="$BASE RujelYear$YEAR RujelSync"
if [ "$1" = "day" ] ; then
for f in RujelBackup_*_$KEY.sql.bz2 ; do
if [ -e $f -a "$FILE" \> "$f" ] ; then
rm $f
fi
done
elif [ "$1" = "conf" ] ; then
BASE=
else
BASE="$BASE VseLists RujelUsers Contacts"
fi
else
BASE="VseLists RujelUsers Contacts"
for f in RujelBackup_*_$KEY.sql.bz2 ; do
if [ -e $f -a "$FILE" \> "$f" ] ; then
rm $f
fi
done
fi
if [ ! -z "$BASE" ] ; then
echo "Backing up databases: $BASE ..."
FILE="RujelBackup_`date +%F`_$KEY.sql"
if mysqldump -u $USERNAME $PASSWORD -r $FILE --single-transaction -B $BASE ; then
echo "Compressing $FILE ..."
bzip2 -f $FILE
echo "Backup saved $FILE.bz2"
else
rm $FILE
echo "Database backup failed"
fi
fi
if [ "$1" = "all" -o "$KEY" = "conf" ] ; then
echo "Backing up Rujel configuration: RujelConfig_`date +%F`_conf.tar.bz2"
tar -cj -f "RujelConfig_`date +%F`.tar.bz2" -C $CONFIGDIR/.. rujel
fi
cd $PWD