aboutsummaryrefslogtreecommitdiff
path: root/lib/beam/mysql.sh
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-05-29 13:02:40 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-05-29 13:02:40 +0300
commitd669127d2efaf9969b081fbaff47ff8938388750 (patch)
tree1bcfab0a932b717284e67f957deb8506229ac4be /lib/beam/mysql.sh
parent8ceb3484f218d25e025deb618ae3d202e2599dab (diff)
downloadbeam-d669127d2efaf9969b081fbaff47ff8938388750.tar.gz
beam-d669127d2efaf9969b081fbaff47ff8938388750.tar.bz2
Rename project to BEAM (Backup Easy And Manageable).
Diffstat (limited to 'lib/beam/mysql.sh')
-rw-r--r--lib/beam/mysql.sh91
1 files changed, 91 insertions, 0 deletions
diff --git a/lib/beam/mysql.sh b/lib/beam/mysql.sh
new file mode 100644
index 0000000..c33adb0
--- /dev/null
+++ b/lib/beam/mysql.sh
@@ -0,0 +1,91 @@
+#! /bin/bash
+# This file is part of BEAM
+# Copyright (C) 2012 Sergey Poznyakoff
+#
+# BEAM is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# BEAM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with BEAM. If not, see <http://www.gnu.org/licenses/>.
+
+# mysql_check item
+mysql_check() {
+ eval database=\$${1}_database
+ test -z "$database" && error "${1}_database not set" && return 1
+ return 0
+}
+
+# mysql_backup item
+mysql_backup() {
+ local database
+
+ logit "backing up MySQL database $1"
+ eval database=\$${1}_database
+ test -z "$database" && abend 1 "${1}_database not set"
+ cmd="mysqldump"
+ eval defaults_file=\$${1}_defaults_file
+ if [ -n "$defaults_file" ]; then
+ cmd="$cmd --defaults-file=$defaults_file"
+ fi
+ cmd="$cmd --add-drop-database --databases"
+ if [ -z "$dry_run" ]; then
+ $cmd $database > $backup_snapshot_dir/$1-$week-$round-$level
+ else
+ echo "$cmd $database > $backup_snapshot_dir/$1-$week-$round-$level"
+ fi
+
+ if [ $? -ne 0 ]; then
+ tarerror=$((tarerror + 1))
+ echo >&2 "`date`: failed"
+ else
+ echo "`date`: creating $1-$week-$round-$level.$tar_suffix"
+ $dry_run tar $verbose $taroptions \
+ -f $backup_archive_dir/$1-$week-$round-$level.$tar_suffix \
+ -C $backup_snapshot_dir $1-$week-$round-$level
+ tarcode $?
+ $dry_run rm $backup_snapshot_dir/dbdump-$week-$round-$level
+ fi
+}
+
+mysql_restore() {
+ local u database
+
+ eval database=\$${1}_database
+ logit "restoring MySQL database $database"
+ u=$(umask)
+ trap "umask $u" 1 2 3 13 15
+ umask 077
+ $dry_run tar $verbose $taroptions \
+ -f $backup_archive_dir/$1-$week-$round-$level.$tar_suffix
+ e=$?
+ tarcode $e
+ if [ $e -eq 0 ]; then
+ logit "restoring database from the dump"
+ cmd="mysql -A --batch"
+ eval defaults_file=\$${1}_defaults_file
+ if [ -n "$defaults_file" ]; then
+ cmd="$cmd --defaults-file=$defaults_file"
+ fi
+ if [ -n "$dry_run" ]; then
+ echo "$cmd < $1-$week-$round-$level"
+ elif [ -r $1-$week-$round-$level ]; then
+ $cmd < $1-$week-$round-$level > db-$1.log
+ if grep ERROR db-$1.log >/dev/null; then
+ error "errors occurred during restore; see db-$1.log for details"
+ error "dump preserved in file $1-$week-$round-$level"
+ tarerror=$((tarerror + 1))
+ else
+ rm $1-$week-$round-$level
+ fi
+ fi
+ fi
+ umask $u
+ trap - 1 2 3 13 15
+}

Return to:

Send suggestions and report system problems to the System administrator.