diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-07-04 13:30:27 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-07-04 13:30:27 +0300 |
commit | ccb9742c80519ef29d2a529397011dd718613005 (patch) | |
tree | f9d1df7ca884f0c4570bb2573023a9c4f1a0fd2b | |
parent | 919b830afdd005d5b3c5af7004af0d85599e4ae1 (diff) | |
download | beam-ccb9742c80519ef29d2a529397011dd718613005.tar.gz beam-ccb9742c80519ef29d2a529397011dd718613005.tar.bz2 |
Implement list command.
* list.in: New file.
* .gitignore: Add list.sh
* Makefile.am: Build and install list.sh
* lib/beam/fs.sh: Implement list method.
* lib/beam/mysql.sh: Likewise.
* lib/beam/postgres.sh: Likewise.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 14 | ||||
-rwxr-xr-x | lib/beam/fs.sh | 18 | ||||
-rwxr-xr-x | lib/beam/mysql.sh | 12 | ||||
-rwxr-xr-x | lib/beam/postgres.sh | 10 | ||||
-rw-r--r-- | list.in | 101 |
6 files changed, 148 insertions, 8 deletions
@@ -17,6 +17,7 @@ config.log config.status configure core +list.sh backup.sh restore.sh s3mount.sh diff --git a/Makefile.am b/Makefile.am index 685624c..3a5be3f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,13 +3,13 @@ if COND_S3MOUNT S3MOUNT=s3 S3MOUNT_SH=s3.sh endif -noinst_SCRIPTS=build.sed backup.sh restore.sh cleaner.sh $(S3MOUNT_SH) +noinst_SCRIPTS=build.sed backup.sh restore.sh cleaner.sh list.sh $(S3MOUNT_SH) bin_SCRIPTS=beam -CLEANFILES=beam beam.sh backup.sh restore.sh cleaner.sh $(S3MOUNT_SH) +CLEANFILES=beam beam.sh backup.sh restore.sh cleaner.sh list.sh $(S3MOUNT_SH) install-exec-hook: test -z "$(DESTDIR)$(libexecdir)" || \ $(mkdir_p) "$(DESTDIR)$(libexecdir)"; \ - for file in backup restore cleaner $(S3MOUNT); \ + for file in backup restore cleaner list $(S3MOUNT); \ do \ ${INSTALL} $(top_builddir)/$$file.sh \ $(DESTDIR)$(libexecdir)/beam-$$file; \ @@ -21,12 +21,12 @@ install-data-hook: ${INSTALL} -m 644 $(top_srcdir)/beam.conf $(DESTDIR)$(sysconfdir);\ fi uninstall-hook: - for file in backup restore cleaner $(S3MOUNT); \ + for file in backup restore cleaner list $(S3MOUNT); \ do \ rm -f "$(DESTDIR)$(libexecdir)/beam-$$file"; \ done -beam.sh backup.sh restore.sh cleaner.sh $(S3MOUNT_SH): build.sed -EXTRA_DIST=beam.in backup.in restore.in beam.conf cleaner.in s3.in +beam.sh backup.sh restore.sh cleaner.sh list.sh $(S3MOUNT_SH): build.sed +EXTRA_DIST=beam.in backup.in restore.in beam.conf cleaner.in list.in s3.in distuninstallcheck_listfiles=find $(DESTDIR)$(prefix) -type f -not -wholename '$(DESTDIR)$(sysconfdir)/beam.conf' $(top_builddir)/build.sed: Makefile @@ -44,7 +44,7 @@ $(top_builddir)/build.sed: Makefile echo 's|@''PACKAGE_URL''@|$(PACKAGE_URL)|g';\ echo 's|@''PACKAGE_VERSION''@|$(PACKAGE_VERSION)|g';\ } > $(top_builddir)/build.sed -DISTCLEANFILES=build.sed backup.sh restore.sh +DISTCLEANFILES=build.sed backup.sh restore.sh list.sh include $(top_srcdir)/Make.rules .PHONY: ChangeLog diff --git a/lib/beam/fs.sh b/lib/beam/fs.sh index 74553e3..28f4855 100755 --- a/lib/beam/fs.sh +++ b/lib/beam/fs.sh @@ -45,7 +45,7 @@ initdb() { # fs_check item fs_check() { - local rc=0 + local rc=0 root files eval root=\$${1}_dir eval files=\$${1}_files @@ -55,6 +55,22 @@ fs_check() { return $rc } +# fs_list item prefix +fs_list() { + local dir files lsf= + + eval dir=\$${1}_dir files=\$${1}_files + for file in $files + do + if [ -d "$dir/$file" ]; then + lsf="$lsf $file/" + else + lsf="$lsf $file" + fi + done + echo "${2}Files and directories in $dir:$lsf" +} + # fs_backup item fs_backup() { local basename text root files exclude addopts s e diff --git a/lib/beam/mysql.sh b/lib/beam/mysql.sh index 09b2ef4..c172f44 100755 --- a/lib/beam/mysql.sh +++ b/lib/beam/mysql.sh @@ -20,6 +20,18 @@ mysql_check() { return 0 } +# mysql_list item prefix +mysql_list() { + local database + + eval database=\$${1}_database + if [ -z "$database" ]; then + echo "${2}all MySQL databases" + else + echo "${2}MySQL database $database" + fi +} + # mysql_backup item mysql_backup() { local database diff --git a/lib/beam/postgres.sh b/lib/beam/postgres.sh index f49967e..31bf9d6 100755 --- a/lib/beam/postgres.sh +++ b/lib/beam/postgres.sh @@ -17,11 +17,21 @@ # postgres_check item postgres_check() { + local database + eval database=\$${1}_database test -z "$database" && error "${1}_database not set" && return 1 return 0 } +# postgres_list item prefix +postgres_list() { + local database + + eval database=\$${1}_database + echo "${2}PostgreSQL database $database" +} + # postgres_backup item postgres_backup() { local database @@ -0,0 +1,101 @@ +#! /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/>. + +libdir=@LIBDIR@/beam +set -e +. $libdir/common.sh +set +e + +if [ "$1" = "--wtf" ]; then + wtf $(basename $0) list what is included in backups + exit 0 +fi + +help() { + cat <<EOF +usage: $0 +list what is included in backups + +OPTIONS: + + -l, --number produce a numbered list + + -h, --help produce this help list + -V, --version print program version + +Report bugs to <@PACKAGE_BUGREPORT@> +EOF + exit 0 +} + +########################################################### +# Main +########################################################### + +numbered_list= +while [ $# -ne 0 ] +do + case $1 in + -l|--number) numbered_list=1;; + -h|--help) help;; + -V|--version) print_version;; + *) echo >&2 "$0: unrecognized option $1"; exit 1;; + esac + shift +done + +load_config + +if [ -z "$backup_items" ]; then + echo "Nothing is being backed up" +fi + +delayed_exit= +loaded_types= +if test -n "$numbered_list"; then + n=0 +fi +prefix= +for item in $backup_items +do + eval type=\$${item}_type + if [ -z "$type" ]; then + error "${item}_type not set" + delayed_exit=1 + continue + fi + if echo "$loaded_types" | grep -wq $type; then + : + elif [ -x $libdir/${type}.sh ]; then + . $libdir/${type}.sh || delayed_exit=1 + loaded_types="$loaded_files +$type" + else + error "$libdir/${type}.sh not found" + delayed_exit=1 + fi + + if test -n "$numbered_list"; then + n=$((n + 1)) + prefix="$n. " + fi + ${type}_list $item "$prefix" || delayed_exit=1 +done + +test -n "$delayed_exit" && abend 1 "aborting" + +exit 0 |