blob: f39aeaafdb8c35439f1aa281fc3ed3bbf6617ae9 (
plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
#!/bin/bash
# This script is used to perform a quick restore of a database that was backed up via the nightly system backup
# The restore only does the database it does NOT restore system files (even if they are in the backup file)
#
# - supplemental web, process.py , lh_system_restore
. /etc/systemconfig
BACKUPDIR=/data/storage/disk0/backup/system_backups
RESTOREDIR=$BACKUPDIR/restore
backupfile=$1
restore_status=0
MYTH_RUN_STATUS="1"
. /etc/profile
function usage(){
echo "------------------------------------------------------"
echo "This program will restore the database from a system backup."
echo "System backup files are expected to be in the $BACKUPDIR"
echo ""
echo "Usage:"
echo ""
echo "lh_system_restore_job \$filename [cleanup partial]"
echo ""
echo "example: lh_system_restore_job backup.2011-12-22_15-34.tgz "
echo ""
echo ""
echo "If the script is called with cleanup, it will cleanup the restore dir."
echo "If the script is called with partial, it will restore the db,"
echo " and then copy back some settings."
echo " partial is intended to be used to restore R7 databases only."
echo "------------------------------------------------------"
exit 1
}
function restore_status_check(){
if [ $1 -ne 0 ]
then
restore_status=1
fi
}
function run_cleanup(){
echo "Cleaning up the restore dir"
rm -rf $RESTOREDIR/$DIR
rm -f $RESTOREDIR/$backupfile
}
function expand_restore_file(){
mkdir -p $RESTOREDIR
DIR=`echo $backupfile |cut -d. -f2`
cp $BACKUPDIR/$backupfile $RESTOREDIR
cd $RESTOREDIR && tar -xf $backupfile && cd $DIR
restore_status_check $?
}
function restore_db(){
CSQL="create database mythconverg;"
DSQL="drop database mythconverg; "
MYSQL="mysql -u mythtv -pmythtv"
if [ -f mythconverg ]
then
#drop the db
$MYSQL -e "$DSQL"
#create the db
$MYSQL -e "$CSQL"
#restore the database_backup
echo "Restoring database $DIR"
$MYSQL mythconverg < mythconverg
rc=$?
restore_status_check $rc
if [ $rc = 0 ]
then
echo "Restore of mythconverg complete"
else
echo "An error occurred restoring mythconverg"
fi
else
echo "Couldn't find file mythconverg to restore"
restore_status=1
fi
}
function restore_ncid(){
CSQL="create database ncid;"
DSQL="drop database ncid; "
MYSQL="mysql -u root "
if [ -f ncid ]
then
#drop the db
$MYSQL -e "$DSQL"
#create the db
$MYSQL -e "$CSQL"
#restore the database_backup
echo "Restoring database $DIR"
$MYSQL ncid < ncid
rc=$?
#restore_status_check $rc
if [ $rc = 0 ]
then
echo "Restore of ncid complete"
else
echo "An error occurred restoring ncid"
fi
else
echo "Couldn't find file ncid to restore"
fi
}
function run_prestore(){
echo "Partial restore of database"
echo "---------------------------------"
echo
#save settings to group
echo " Saving current database settings for selective import"
mythutil --export-settings --outfile $RESTOREDIR/pre_db.exports.xml --tablelist settings --generic 2> /dev/null >> /tmp/prestore.out
#save storage groups
mysqldump mythconverg storagegroup > $RESTOREDIR/sg.sql
#stop mythbackend
echo " Stopping mythbackend"
lh_backend_control.sh stop
# restore mythconverg
restore_db
mysqldump mythconverg storagegroup > $RESTOREDIR/backupfile_sg.sql
mysql mythconverg -e "truncate storagegroup;"
restore_ncid
# restore exported settings
echo " Importing previous settings into settings_pre_db"
mythutil --import-settings --infile $RESTOREDIR/pre_db.exports.xml --hostname `hostname` 2>/dev/null >> /tmp/prestore.out
# restore storage_groups
mysql mythconverg < $RESTOREDIR/sg.sql
#start mythbackend
echo " Starting mythbackend"
lh_backend_control.sh start
echo
echo "Partial restore complete."
echo "All data for `hostname` has been restored except:"
echo "* storage groups definitions"
echo "* service menu settings"
}
function run_full_restore(){
echo "Full restore"
echo "---------------------------------"
echo
cp -f etc/systemconfig /etc/systemconfig
if [ $SystemType = Master_backend -o $SystemType = Standalone ]
then
#stop mythbackend
echo " Stopping mythbackend"
lh_backend_control.sh stop
echo
# restore mythconverg
restore_db
echo
restore_ncid
echo
#start mythbackend
echo " Starting mythbackend"
lh_backend_control.sh start
echo
else
# didn't restore the database, so restore FE settings
if [ -e settings ]
then
rsync -arvp settings/* /usr/MythVantage/templates/settings/
fi
if [ -e /usr/MythVantage/templates/settings/syssettings ]
then
myth_settings_wrapper.sh -c restore -t syssettings
restore_status_check $?
else
echo "Couldn't find syssettings file"
fi
fi
systemconfig.py -m all
echo "Restore complete"
}
#-----------------------Main program --------------------------
if [ x$backupfile = x ]
then
usage
fi
prestore="false"
cleanup="false"
for i in $*; do
#echo $i
if [ $i = "cleanup" ]
then
cleanup="true"
fi
if [ $i = "partial" ]
then
prestore="true"
fi
done
expand_restore_file
if [ $prestore = "true" ]
then
run_prestore
else
run_full_restore
fi
if [ $cleanup = "true" ]
then
run_cleanup
fi
exit $restore_status
|