aboutsummaryrefslogtreecommitdiff
path: root/lib/beam/s3.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/s3.sh
parent8ceb3484f218d25e025deb618ae3d202e2599dab (diff)
downloadbeam-d669127d2efaf9969b081fbaff47ff8938388750.tar.gz
beam-d669127d2efaf9969b081fbaff47ff8938388750.tar.bz2
Rename project to BEAM (Backup Easy And Manageable).
Diffstat (limited to 'lib/beam/s3.sh')
-rw-r--r--lib/beam/s3.sh85
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/beam/s3.sh b/lib/beam/s3.sh
new file mode 100644
index 0000000..5f7235c
--- /dev/null
+++ b/lib/beam/s3.sh
@@ -0,0 +1,85 @@
+# This file is part of BEAM -*- shell-script -*-
+# 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/>.
+
+# 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 $backup_s3backer_options \
+ $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
+ beam-restore|restore) mountopt=",ro";;
+ beam-backup|backup) mountopt=",rw,data=writeback";;
+ beam-s3) ;;
+ *) 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.