diff options
Diffstat (limited to 'lib/beam')
-rw-r--r-- | lib/beam/Makefile.am | 2 | ||||
-rw-r--r-- | lib/beam/common.in | 9 | ||||
-rwxr-xr-x | lib/beam/fs.sh | 10 | ||||
-rwxr-xr-x | lib/beam/ldap.sh | 164 | ||||
-rwxr-xr-x | lib/beam/mysql.sh | 13 | ||||
-rwxr-xr-x | lib/beam/postgres.sh | 7 | ||||
-rw-r--r-- | lib/beam/s3.sh | 3 |
7 files changed, 205 insertions, 3 deletions
diff --git a/lib/beam/Makefile.am b/lib/beam/Makefile.am index d490acb..22c9a12 100644 --- a/lib/beam/Makefile.am +++ b/lib/beam/Makefile.am @@ -19,12 +19,14 @@ libbackup_SCRIPTS=\ common.sh\ s3.sh\ fs.sh\ + ldap.sh\ mysql.sh\ postgres.sh EXTRA_DIST=\ common.in\ s3.sh\ fs.sh\ + ldap.sh\ mysql.sh\ postgres.sh DISTCLEANFILES=common.sh diff --git a/lib/beam/common.in b/lib/beam/common.in index 6ce25fe..4c6cd21 100644 --- a/lib/beam/common.in +++ b/lib/beam/common.in @@ -71,6 +71,14 @@ load_config() { abend 1 "backup_items not specified" fi + if [ -z "$backup_archive_dir" ]; then + if [ -n "$backup_bucket_name" ]; then + backup_archive_dir=$backup_mp_s3 + else + abend 1 "backup_archive_dir not set" + fi + fi + delayed_exit= loaded_types= for item in $backup_items @@ -198,6 +206,7 @@ rotate 4 cat > $conf <<EOF $backup_logfile { $backup_logrotate_conf +missingok } EOF umask $u diff --git a/lib/beam/fs.sh b/lib/beam/fs.sh index 6c09e61..42da67b 100755 --- a/lib/beam/fs.sh +++ b/lib/beam/fs.sh @@ -15,6 +15,16 @@ # You should have received a copy of the GNU General Public License # along with BEAM. If not, see <http://www.gnu.org/licenses/>. +# Configuration keywords: +# +# item_type=fs [mandatory] +# item_dir=STRING [mandatory] +# item_files=STRING [mandatory] +# item_exclude=STRING [optional] +# item_exclude_from=STRING [optional] +# item_tar_options=STRING [optional internal] +# + # initdb item # Initializes snapshot for the given basename. initdb() { diff --git a/lib/beam/ldap.sh b/lib/beam/ldap.sh new file mode 100755 index 0000000..f6e56b8 --- /dev/null +++ b/lib/beam/ldap.sh @@ -0,0 +1,164 @@ +#! /bin/sh +# 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/>. + +# Configuration keywords: +# +# item_type=ldap [mandatory] +# item_database_directory=string [mandatory] +# item_database_number=n [optional *] +# item_database_suffix=suf [optional *] +# item_uri=str [optional] +# item_user=name [optional] +# item_slapcat_options=string [optional internal] +# item_slapadd_options=string [optional internal] +# +# * - mutually exclusive keywords. + + +# ldap_check item +ldap_check() { + local rc=0 dbno dbsuf dbdir + eval dbno=\$${1}_database_number \ + dbsuf=\$${1}_database_suffix \ + dbdir=\$${1}_database_directory + if test -n "$dbno" && test -n "$dbsuf"; then + error "$1: both ${1}_database_number and ${1}_database_suffix are set" + rc=1 + fi + if test -z "$dbdir"; then + error "${1}_database_directory not configured" + rc=1 + fi + if ! test -d "$dbdir"; then + error "LDAP database directory $dbdir does not exist" + error "(set by ${1}_database_directory)" + fi + return $rc +} + +# ldap_list item prefix +ldap_list() { + local dbid + + eval dbid=\$${1}_database_number + if [ -n "$dbid" ]; then + dbid=" number $dbid" + else + eval dbid=\$${1}_database_suffix + if [ -n "$dbid" ]; then + dbid=" suffixed with $dbid" + fi + fi + + echo "${2}LDAP database"$dbid +} + +# ldap_backup item +ldap_backup() { + local options dbno dbsuf uri + + logit "backing up LDAP database $1" + + eval options=\$${1}_slapcat_options \ + dbno=\$${1}_database_number \ + dbsuf=\$${1}_database_suffix + + if [ -n "$dbno" ]; then + options="$options -n$dbnum" + elif [ -n "$dbsuf" ]; then + options="$options -b$slapcat" + fi + + eval uri=\"\$${1}_uri\" + if [ -n "$uri" ]; then + options="$options -H\"$uri\"" + fi + + if [ -z "$dry_run" ]; then + slapcat $options > $backup_snapshot_dir/$1-$week-$round-$level + else + echo "slapcat $options > $backup_snapshot_dir/$1-$week-$round-$level" + fi + + if [ $? -ne 0 ]; then + tarerror=$((tarerror + 1)) + logit "failed" + else + logit "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/$1-$week-$round-$level + fi +} + +# ldap_restore item +ldap_restore() { + local options dbno dbsuf dbdir u user + + logit "extracting LDAP database dump $1" + + eval options=\$${1}_slapadd_options dbno=\$${1}_database_number \ + dbsuf=\$${1}_database_suffix dbdir=\$${1}_database_directory \ + user=\$${1}_user + + if test -z "$dbdir"; then + error "${1}_database_directory not configured" + tarerror=$((tarerror + 1)) + return + fi + if [ -n "$dbno" ]; then + options="$options -n$dbnum" + elif [ -n "$dbsuf" ]; then + options="$options -b$slapcat" + fi + + 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 + prevdbtar=$backup_snapshot_dir/ldap-$1-$(date +%Y%m%dT%H%M%S).tar + logit "archiving the previous database contents to $prevdbtar" + $dry_run tar $verbose -c -f $prevdbtar $dbdir + e=$? + tarcode $e + umask $u + if [ $e -ne 0 ]; then + error "Failed to backup the prior database contents to $prevdbtar" + return + fi + logit "removing old database files in $dbdir" + $dry_run rm $dbdir/* + logit "restoring database $1 from the dump" + if test -n "$user"; then + su $user -c "$dry_run slapadd $options $verbose -l $1-$week-$round-$level" + su $user -c "$dry_run slapindex" + else + $dry_run slapadd $options $verbose -l $1-$week-$round-$level + $dry_run slapindex + fi + # FIXME: error checking + $dry_run rm $1-$week-$round-$level + fi + umask $u + trap - 1 2 3 13 15 +} diff --git a/lib/beam/mysql.sh b/lib/beam/mysql.sh index c172f44..4ce3a88 100755 --- a/lib/beam/mysql.sh +++ b/lib/beam/mysql.sh @@ -15,6 +15,13 @@ # You should have received a copy of the GNU General Public License # along with BEAM. If not, see <http://www.gnu.org/licenses/>. +# Configuration keywords: +# +# item_type=mysql [mandatory] +# item_database=STRING [optional] +# item_defaults_file=STRING [optional] +# + # mysql_check item mysql_check() { return 0 @@ -36,8 +43,12 @@ mysql_list() { mysql_backup() { local database - logit "backing up MySQL database $1" eval database=\$${1}_database + if [ -z "$database" ]; then + logit "backing up all MySQL databases" + else + logit "backing up MySQL database $database" + fi cmd="mysqldump" eval defaults_file=\$${1}_defaults_file if [ -n "$defaults_file" ]; then diff --git a/lib/beam/postgres.sh b/lib/beam/postgres.sh index 31bf9d6..0eba767 100755 --- a/lib/beam/postgres.sh +++ b/lib/beam/postgres.sh @@ -15,6 +15,11 @@ # You should have received a copy of the GNU General Public License # along with BEAM. If not, see <http://www.gnu.org/licenses/>. +# Configuration keywords: +# +# item_type=postgres [mandatory] +# item_database=STRING [mandatory] + # postgres_check item postgres_check() { local database @@ -36,8 +41,8 @@ postgres_list() { postgres_backup() { local database - logit "backing up PostgreSQL $1" eval database=\$${1}_database + logit "backing up PostgreSQL database $database" test -z "$database" && abend 1 "${1}_database not set" if [ -z "$dry_run" ]; then su postgres -c "pg_dump $verbose $database" > $backup_snapshot_dir/$1-$week-$round-$level diff --git a/lib/beam/s3.sh b/lib/beam/s3.sh index 194e035..de71456 100644 --- a/lib/beam/s3.sh +++ b/lib/beam/s3.sh @@ -1,4 +1,5 @@ -# This file is part of BEAM -*- shell-script -*- +#! /bin/sh +# This file is part of BEAM # Copyright (C) 2012 Sergey Poznyakoff # # BEAM is free software; you can redistribute it and/or modify |