aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-05-28 18:37:26 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-05-28 18:46:14 +0300
commit8ceb3484f218d25e025deb618ae3d202e2599dab (patch)
tree21b551664e24a420d1c967ace2144ee12f3adecd /lib
parent74940a305bb009a690e56d6d6562b3fd24269ae0 (diff)
downloadbeam-8ceb3484f218d25e025deb618ae3d202e2599dab.tar.gz
beam-8ceb3484f218d25e025deb618ae3d202e2599dab.tar.bz2
Incorporate s3 support. Change hook handling.
(Additionally: mysql.sh has been tested.) * .gitignore: Add s3mount.sh * Makefile.am: Build and install s3mount (conditionally). * backup-cleanup: Rename to backup-cleaner. * backup.conf (backup_retain_interval) (backup_bucket_name,backup_mp_s3backer) (backup_mp_s3): New variables. * backup.in: Change hook handling: each hook is a list of commands which are executed in succession. New option --version (-V). Run backup-cleaner if backup_retain_interval is set. * restore.in: Change hook handling. New option --version (-V). * configure.ac: Change version to 1.1. New option --with-s3. * doc/backup.conf.5in: Document new variables and changes in the hook handling. * examples/.gitignore: Remove. * examples/Makefile.am: Remove s3mount. * examples/s3mount.in: Remove. * lib/backup/Makefile.am (libbackup_SCRIPTS, EXTRA_DIST): Add s3.sh * lib/backup/common.in: Source backup/s3 if backup_bucket_name is set. (runhook,print_version): New function. * lib/backup/s3.sh: New file. * s3mount.in: New file.
Diffstat (limited to 'lib')
-rw-r--r--lib/backup/Makefile.am2
-rw-r--r--lib/backup/common.in26
-rw-r--r--lib/backup/s3.sh69
3 files changed, 97 insertions, 0 deletions
diff --git a/lib/backup/Makefile.am b/lib/backup/Makefile.am
index 38a8085..d1f687d 100644
--- a/lib/backup/Makefile.am
+++ b/lib/backup/Makefile.am
@@ -1,11 +1,13 @@
libbackupdir=$(libdir)/backup
libbackup_SCRIPTS=\
common.sh\
+ s3.sh\
fs.sh\
mysql.sh\
postgres.sh
EXTRA_DIST=\
common.in\
+ s3.sh\
fs.sh\
mysql.sh\
postgres.sh
diff --git a/lib/backup/common.in b/lib/backup/common.in
index ab80204..11cb2d0 100644
--- a/lib/backup/common.in
+++ b/lib/backup/common.in
@@ -83,4 +83,30 @@ $type"
test -n "$delayed_exit" && abend 1 "aborting"
tar_suffix=${backup_suffix:-.tar}
+
+ if [ -n "$backup_bucket_name" ]; then
+ . @LIBDIR@/backup/s3.sh
+ prologue_hook="$prologue_hook s3_mount"
+ fi
+}
+
+runhook() {
+ local hook_list
+
+ eval hook_list=\$$1
+ for hook in $hook_list
+ do
+ $hook
+ done
}
+
+print_version() {
+ cat <<EOF
+$0 (@PACKAGE_NAME@) @PACKAGE_VERSION@
+Copyright (C) 2012 Sergey Poznyakoff
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+EOF
+ exit 0
+} \ No newline at end of file
diff --git a/lib/backup/s3.sh b/lib/backup/s3.sh
new file mode 100644
index 0000000..e463e76
--- /dev/null
+++ b/lib/backup/s3.sh
@@ -0,0 +1,69 @@
+# The configuration variable "backup_bucket_name" must contain the name
+# of the s3 bucket to use.
+
+# Raw bucket is mounted to /mnt/s3backer
+test -z "$backup_mp_s3backer" && backup_mp_s3backer=/mnt/s3backer
+# The actual file system is mounted to /mnt/s3
+test -z "$backup_mp" && backup_mp_s3=/mnt/s3
+
+# This variable is populated by s3_mount and is used by s3_unmount to unmount
+# s3-backed file system.
+umount_list=""
+
+s3_mount() {
+ # Make sure both mountpoints exist
+ test -d $backup_mp_s3backer || mkdir $backup_mp_s3backer
+ test -d $backup_mp_s3 || mkdir $backup_mp_s3backer
+
+# Sample mount output, split into several lines:
+# http://finox-backup-fs.s3.amazonaws.com/ on /mnt/s3backer type fuse.s3backer
+# (rw,nosuid,nodev,allow_other,default_permissions)
+ set -- $(mount -tfuse.s3backer |
+ awk '/https?:\/\/'$backup_bucket_name'/ { print $3 }')
+ if test -z "$1"; then
+ $dry_run s3backer --accessFile=/root/.s3backer_passwd --vhost \
+ $backup_bucket_name $backup_mp_s3backer ||
+ abend 1 "unable to mount $backup_bucket_name"
+ umount_list="$backup_mp_s3backer"
+ else
+ backup_mp_s3backer=$1
+ fi
+ set -- $(mount | grep "^${backup_mp_s3backer}/file" | awk '{ print $3 }')
+ if test -z "$1"; then
+ case $(basename $0) in
+ restore) mountopt=",ro";;
+ backup) mountopt=",rw,data=writeback";;
+ s3mount) ;;
+ *) error "called as $0: assuming default mount options"
+ esac
+ # NOTE: For ext4 add the journal_async_commit option.
+ $dry_run mount -oloop$mountopt $backup_mp_s3backer/file $backup_mp_s3 ||
+ abend 1 "unable to mount $backup_mp_s3backer/file"
+ umount_list="$backup_mp_s3 $umount_list"
+ else
+ backup_mp_s3=$1
+ fi
+ epilogue_hook="s3_unmount $epilogue_hook"
+}
+
+s3_getmpoint()
+{
+ case $1 in
+ backer)
+ mount -tfuse.s3backer |
+ awk '/https?:\/\/'$backup_bucket_name'/ { print $3 }';;
+ s3)
+ mount | grep "^${backup_mp_s3backer}/file" | awk '{ print $3 }';;
+ *)
+ abent 1 "invalid usage of getmpoint"
+ esac
+}
+
+s3_unmount()
+{
+ for id in s3 backer
+ do
+ mpoint=$(s3_getmpoint $id)
+ test -n "$mpoint" && umount $mpoint
+ done
+}

Return to:

Send suggestions and report system problems to the System administrator.