summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/LinHES-system/bin/backupcommon
diff options
context:
space:
mode:
Diffstat (limited to 'abs/core-testing/LinHES-system/bin/backupcommon')
-rw-r--r--[-rwxr-xr-x]abs/core-testing/LinHES-system/bin/backupcommon143
1 files changed, 98 insertions, 45 deletions
diff --git a/abs/core-testing/LinHES-system/bin/backupcommon b/abs/core-testing/LinHES-system/bin/backupcommon
index a5ed7c0..9b75db3 100755..100644
--- a/abs/core-testing/LinHES-system/bin/backupcommon
+++ b/abs/core-testing/LinHES-system/bin/backupcommon
@@ -1,12 +1,16 @@
#!/bin/bash
+. /usr/LH/bin/library.sh || {
+ echo 1>&2 "Can not load common library!"
+ exit 1
+}
+
#----------------------------------------------------------------------------
DATABASE="mythconverg"
-DATABASE_DIR="/var/lib/mysql/$DATABASE"
+DATABASE_DIR="/data/srv/mysql/$DATABASE"
BACKUP_LIST="./root ./home ./etc
- ./var/www/mythweb/.htaccess ./var/lib/alsa/asound.state"
-RESTORE_LIST="./root ./home ./etc/mythtv/modules ./etc/lirc ./etc/htdigest
- ./etc/apache2/apache2.conf ./var/www/mythweb/.htaccess
+ ./var/lib/alsa/asound.state"
+RESTORE_LIST="./root ./home ./etc/mythtv/modules ./etc/lirc
./etc/X11/xorg.conf ./etc/asound.conf ./etc/default/aumix
./var/lib/alsa/asound.state ./etc/mplayer/mplayer.conf
./etc/localtime ./etc/timezone"
@@ -41,14 +45,54 @@ BACKUP_EXTRAS="$BACKUP_DIR/backup.list"
RESTORE_EXTRAS="$BACKUP_DIR/restore.list"
BACKUP_TAR="$BACKUP_DIR/savedfiles.tar"
BACKUP_SQL="$BACKUP_DIR/$DATABASE.sql"
-DROP_SQL="/usr/local/share/knoppmyth/drop.sql"
+#DROP_SQL="/usr/local/share/knoppmyth/drop.sql"
+UTIL_DIR="/usr/LH/bin"
# Do we really still need to update from myth-0.11 to myth-0.12 ?
UPDATE_SQL="/usr/share/mythtv/sql/0.11-to-0.12.sql"
-UPDATE_FILES="/usr/local/bin/restore_fixups.sh"
+UPDATE_FILES="$UTIL_DIR/restore_fixups.sh"
COMPRESSION=".gz"
SOUNDS="/usr/share/sounds"
PLAYER="/usr/bin/aplay"
#----------------------------------------------------------------------------
+AWK=/bin/awk
+BASH=/bin/bash
+BUNZIP2=/bin/bunzip2
+BZIP2=/bin/bzip2
+CAT=/bin/cat
+CHMOD=/bin/chmod
+CHOWN=/bin/chown
+EGREP=/bin/egrep
+GREP=/bin/grep
+GUNZIP=/bin/gunzip
+GZIP=/bin/gzip
+LS=/bin/ls
+MV=/bin/mv
+RM=/bin/rm
+SED=/bin/sed
+TAR=/bin/tar
+TR=/bin/tr
+DIFF=/usr/bin/diff
+FIND=/usr/bin/find
+MD5SUM=/usr/bin/md5sum
+MYISAMCHK=/usr/bin/myisamchk
+MYSQL=/usr/bin/mysql
+MYSQLADMIN=/usr/bin/mysqladmin
+MYSQLDUMP=/usr/bin/mysqldump
+MYTHSHUTDOWN=/usr/bin/mythshutdown
+SORT=/usr/bin/sort
+WC=/usr/bin/wc
+SV=/sbin/sv
+
+#----------------------------------------------------------------------------
+
+require file+r+x $AWK $BASH $BUNZIP2 $BZIP2 $CAT $CHMOD $CHOWN $EGREP $GREP \
+ $GUNZIP $GZIP $LS $MV $RM $SED $TAR $TR $DIFF $FIND $MD5SUM \
+ $MYISAMCHK $MYSQL $MYSQLADMIN $MYSQLDUMP $MYTHSHUTDOWN \
+ $SORT $WC $SV
+
+#require file+r "$DROP_SQL"
+
+require dir+r+w+x /tmp "$BACKUP_DIR" "$DATABASE_DIR"
play_sound () {
($PLAYER $SOUNDS/$1 >& /dev/null)&
@@ -56,26 +100,26 @@ play_sound () {
# Filter against an exclude list like the black list or the ignore list above
filter_list () {
- /bin/grep -vxF "$*" |
- /usr/bin/sort -u
+ $GREP -vxF "$*" |
+ $SORT -u
}
# Some people just can't read or follow directions... :-/
# This should track the directory names in the default backup list above
# We also use this to short circuit a certain incredibly dumb stunt
filter_redundant () {
- filter_list "$(echo $BACKUP_LIST ./myth | /usr/bin/tr -s ' ' '\n')" |
- /bin/egrep -v '^\./(root|home|etc|myth)/' |
- /usr/bin/sort -u
+ filter_list "$($TR -s ' ' '\n' <<<"$BACKUP_LIST ./myth")" |
+ $EGREP -v '^\./(root|home|etc|myth)/' |
+ $SORT -u
}
get_extras () {
# One entry per line, and normalize the prefix
- /usr/bin/tr ' ' '\n' <"$1" |
- /usr/bin/awk '/^$/ {next}
- /^\.\// {print $0 ; next}
- /^\// {print "." $0 ; next}
- { print "./" $0}'
+ $TR ' ' '\n' <"$1" |
+ $AWK '/^$/ {next}
+ /^\.\// {print $0 ; next}
+ /^\// {print "." $0 ; next}
+ { print "./" $0}'
}
[ -f "$BACKUP_EXTRAS" ] &&
@@ -101,10 +145,10 @@ esac
shrink () {
case "$COMPRESSION" in
.gz)
- /bin/gzip -9 "$@"
+ $GZIP -9 "$@"
;;
.bz2)
- /bin/bzip2 -9 "$@"
+ $BZIP2 -9 "$@"
;;
*)
;;
@@ -114,13 +158,13 @@ shrink () {
expand () {
case "$*" in
*.gz)
- /bin/gunzip "$@"
+ $GUNZIP "$@"
;;
*.bz2)
- /bin/bunzip2 "$@"
+ $BUNZIP2 "$@"
;;
-c\ *)
- /bin/cat $2 /dev/null
+ $CAT $2 /dev/null
;;
-t\ *)
return 0
@@ -133,8 +177,8 @@ expand () {
}
single_format () {
- candidates=$(/bin/ls -1 "$1.gz" "$1.bz2" "$1" 2>/dev/null)
- case $(echo "$candidates" | /usr/bin/wc -l) in
+ candidates=$($LS -1 "$1.gz" "$1.bz2" "$1" 2>/dev/null)
+ case $($WC -l <<<"$candidates") in
1) return 0 # One is good!
;;
0) echo "Error, no $1 found!"
@@ -161,10 +205,10 @@ backup_roller () { # Gets the rollover sequence to use.
for i in "$@" ; do
for c in .gz .bz2 "" ; do
for f in $BACKUP_SQL $BACKUP_TAR ; do
- /bin/rm -f $f$c$prev_i
+ $RM -f $f$c$prev_i
if [ -f "$f$c$i" ] ; then
echo "Moving $f$c$i to $f$c$prev_i"
- /bin/mv -f $f$c$i $f$c$prev_i
+ $MV -f $f$c$i $f$c$prev_i
fi
done
done
@@ -174,17 +218,17 @@ backup_roller () { # Gets the rollover sequence to use.
# Given "subset A B" return true if is A a subset of B
subset () {
- cnt=$(/usr/bin/diff $1 $2 | /bin/grep '^<' | /usr/bin/wc -l)
+ cnt=$($DIFF $1 $2 | $GREP '^<' | $WC -l)
[ "$cnt" -eq 0 ] && return 0
- /usr/bin/diff $1 $2
+ $DIFF $1 $2
}
mysql_cmd () {
- /usr/bin/mysql -u root $DATABASE -sBe "$*"
+ $MYSQL -u root $DATABASE -sBe "$*"
}
mysql_stdin () {
- /usr/bin/mysql -u root $DATABASE -sB
+ $MYSQL -u root $DATABASE -sB
}
check_files () {
@@ -205,14 +249,14 @@ check_files () {
echo "Generating a list of the backup contents..."
{
expand -c $BACKUP_TAR$c |
- /bin/tar tf - $OBJECT_LIST $EXCLUSION |
- /bin/sed '/\/$/s///' |
+ $TAR tf - $OBJECT_LIST $EXCLUSION |
+ $SED '/\/$/s///' |
filter_list "$IGNORE_LIST" >$SAVED_FILES
- } 2>&1 | /bin/sed -e '/Error exit delayed from previous errors/d'
+ } 2>&1 | $SED -e '/Error exit delayed from previous errors/d'
echo "Generating a list of the directory contents..."
cd /
- /usr/bin/find $OBJECT_LIST \( -type d -or -type f -or -type l \) -print |
+ $FIND $OBJECT_LIST \( -type d -or -type f -or -type l \) -print |
filter_list "$IGNORE_LIST" >$LIVE_FILES
echo "Comparing directory versus backup contents..."
@@ -224,11 +268,11 @@ check_files () {
subset $SAVED_FILES $LIVE_FILES
;;
*)
- /usr/bin/diff $LIVE_FILES $SAVED_FILES
+ $DIFF $LIVE_FILES $SAVED_FILES
;;
esac
FILE_STATUS=$?
- /bin/rm $LIVE_FILES $SAVED_FILES
+ $RM $LIVE_FILES $SAVED_FILES
if [ $FILE_STATUS -eq 0 ] ; then
echo "Live and saved file lists match."
else
@@ -240,11 +284,11 @@ check_files () {
has_records () {
filename="$1"
description="$2"
- if [ $(/usr/bin/wc -l < "$filename") -eq 0 ] ; then
+ if [ $($WC -l < "$filename") -eq 0 ] ; then
echo "Warning, could not get record counts from $description!"
return 1
fi
- if [ $(/usr/bin/awk '{cnt+=$2} END {print cnt}' < "$filename") -eq 0 ] ; then
+ if [ $($AWK '{cnt+=$2} END {print cnt}' < "$filename") -eq 0 ] ; then
echo "Warning, total record count from $description is zero!"
return 1
fi
@@ -267,22 +311,22 @@ check_tables () {
echo "Generating a list of tables and record counts in the DB dump..."
expand -c "$BACKUP_SQL$c" |
- /usr/bin/awk '/CREATE TABLE/ { tbl = $3; gsub("`","",tbl); records[tbl] = 0; } \
+ $AWK '/CREATE TABLE/ { tbl = $3; gsub("`","",tbl); records[tbl] = 0; } \
/INSERT INTO/ { tbl = $3; gsub("`","",tbl); \
n = split(substr($0,index($0,"VALUES (")+7),vals,"\\),\\("); \
records[tbl] += n; } \
END { for (tbl in records) print tbl, records[tbl]; }' |
- /bin/sed 's/mythlog [0-9]*/mythlog 0/' |
- /usr/bin/sort >$SAVED_TABLES
+ $SED 's/mythlog [0-9]*/mythlog 0/' |
+ $SORT >$SAVED_TABLES
has_records "$SAVED_TABLES" "DB dump" || return 1
echo "Generating a list of tables and record counts in the live DB..."
for tbl in $(mysql_cmd "show tables") ; do
mysql_cmd "select '$tbl', count(*) from $tbl"
done |
- /usr/bin/tr -s '\t' ' ' |
- /bin/sed 's/mythlog [0-9]*/mythlog 0/' |
- /usr/bin/sort >$LIVE_TABLES
+ $TR -s '\t' ' ' |
+ $SED 's/mythlog [0-9]*/mythlog 0/' |
+ $SORT >$LIVE_TABLES
has_records "$LIVE_TABLES" "live DB" || return 1
echo "Comparing live versus saved tables..."
@@ -291,11 +335,11 @@ check_tables () {
subset $SAVED_TABLES $LIVE_TABLES
;;
*) # backup must exactly match the database
- /usr/bin/diff $LIVE_TABLES $SAVED_TABLES
+ $DIFF $LIVE_TABLES $SAVED_TABLES
;;
esac
TABLE_STATUS=$?
- /bin/rm $LIVE_TABLES $SAVED_TABLES
+ $RM $LIVE_TABLES $SAVED_TABLES
if [ $TABLE_STATUS -eq 0 ] ; then
echo "Live and saved table lists match."
else
@@ -314,4 +358,13 @@ check_files_and_tables () {
return $STATUS
}
+stop_mysqld () { $SV stop mysql ; }
+start_mysqld () { $SV start mysql ; }
+
+stop_mythbackend () { $SV stop mythbackend ; }
+start_mythbackend () { $SV start mythbackend ; }
+
+lock_myth () { $MYTHSHUTDOWN --lock ; }
+unlock_myth () { $MYTHSHUTDOWN --unlock ; }
+
true # Make sure that this shows success