aboutsummaryrefslogtreecommitdiff
path: root/lib/beam/s3.sh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/beam/s3.sh')
-rw-r--r--lib/beam/s3.sh114
1 files changed, 58 insertions, 56 deletions
diff --git a/lib/beam/s3.sh b/lib/beam/s3.sh
index d2fcfe6..7b6ad91 100644
--- a/lib/beam/s3.sh
+++ b/lib/beam/s3.sh
@@ -1,6 +1,6 @@
1#! /bin/sh 1#! /bin/sh
2# This file is part of BEAM 2# This file is part of BEAM
3# Copyright (C) 2012 Sergey Poznyakoff 3# Copyright (C) 2012-2014 Sergey Poznyakoff
4# 4#
5# BEAM is free software; you can redistribute it and/or modify 5# BEAM is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by 6# it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@ test -z "$backup_mp" && backup_mp_s3=/mnt/s3
25 25
26s3_getmpoint() 26s3_getmpoint()
27{ 27{
28 case $1 in 28 case $1 in
29# Sample mount output, split into several lines: 29# Sample mount output, split into several lines:
30# a) With --vhost: 30# a) With --vhost:
31# http://BUCKETNAME.s3.amazonaws.com/ on /mnt/s3backer type fuse.s3backer 31# http://BUCKETNAME.s3.amazonaws.com/ on /mnt/s3backer type fuse.s3backer
@@ -33,71 +33,73 @@ s3_getmpoint()
33# b) Without --vhost: 33# b) Without --vhost:
34# http://s3.amazonaws.com/BUCKETNAME/ on /mnt/s3backer type fuse.s3backer 34# http://s3.amazonaws.com/BUCKETNAME/ on /mnt/s3backer type fuse.s3backer
35# (rw,nosuid,nodev,allow_other,default_permissions) 35# (rw,nosuid,nodev,allow_other,default_permissions)
36 backer) 36 backer)
37 mount -tfuse.s3backer | 37 mount -tfuse.s3backer |
38 awk '/https?:\/\/.*'$backup_bucket_name'/ { print $3 }';; 38 awk '/https?:\/\/.*'$backup_bucket_name'/ { print $3 }';;
39 s3) 39 s3)
40 s=$(mount | grep "^${backup_mp_s3backer}/file" | awk '{ print $3 }') 40 s=$(mount | grep "^${backup_mp_s3backer}/file" | awk '{ print $3 }')
41 if [ -z "$s" ]; then 41 if [ -z "$s" ]; then
42 # Some kernels print device name instead of the actual mount file: 42 # Some kernels print device name instead of the actual mount file:
43 s=$(mount | grep "^/dev/loop[0-9] on ${backup_mp_s3}" | awk '{ print $3 }') 43 s=$(mount | grep "^/dev/loop[0-9] on ${backup_mp_s3}" |
44 fi 44 awk '{ print $3 }')
45 echo $s;; 45 fi
46 *) 46 echo $s;;
47 abent 1 "invalid usage of getmpoint" 47 *)
48 esac 48 abent 1 "invalid usage of getmpoint"
49 esac
49} 50}
50 51
51# This variable is populated by s3_mount and is used by s3_unmount to unmount 52# This variable is populated by s3_mount and is used by s3_unmount to unmount
52# s3-backed file system. 53# s3-backed file system.
53umount_list="" 54umount_list=""
54 55
55s3_mount() { 56s3_mount() {
56 # Make sure both mountpoints exist 57 # Make sure both mountpoints exist
57 test -d $backup_mp_s3backer || mkdir $backup_mp_s3backer 58 test -d $backup_mp_s3backer || mkdir $backup_mp_s3backer
58 test -d $backup_mp_s3 || mkdir $backup_mp_s3 59 test -d $backup_mp_s3 || mkdir $backup_mp_s3
59 60
60 set -- $(s3_getmpoint backer) 61 set -- $(s3_getmpoint backer)
61 if test -z "$1"; then 62 if test -z "$1"; then
62 $dry_run s3backer $backup_s3backer_options \ 63 $dry_run s3backer $backup_s3backer_options \
63 $backup_bucket_name $backup_mp_s3backer || 64 $backup_bucket_name $backup_mp_s3backer ||
64 abend 1 "unable to mount $backup_bucket_name" 65 abend 1 "unable to mount $backup_bucket_name"
65 umount_list="$backup_mp_s3backer" 66 umount_list="$backup_mp_s3backer"
66 else 67 else
67 backup_mp_s3backer=$1 68 backup_mp_s3backer=$1
68 fi 69 fi
69 set -- $(s3_getmpoint s3) 70 set -- $(s3_getmpoint s3)
70 if test -z "$1"; then 71 if test -z "$1"; then
71 case $(basename $0) in 72 case $(basename $0) in
72 beam-restore|restore) mountopt=",ro";; 73 beam-restore|restore) mountopt=",ro";;
73 beam-backup|backup) mountopt=",rw";; 74 beam-backup|backup) mountopt=",rw";;
74 beam-s3) ;; 75 beam-s3) ;;
75 *) error "called as $0: assuming default mount options" 76 *) error "called as $0: assuming default mount options"
76 esac 77 esac
77 test -n "$backup_s3_mount_options" && 78 test -n "$backup_s3_mount_options" &&
78 mountopt="$mountopt,$backup_s3_mount_options" 79 mountopt="$mountopt,$backup_s3_mount_options"
79 # NOTE: For ext4 add the journal_async_commit option. 80 # NOTE: For ext4 add the journal_async_commit option.
80 $dry_run mount -oloop$mountopt $backup_mp_s3backer/file $backup_mp_s3 || 81 $dry_run mount -oloop$mountopt \
81 abend 1 "unable to mount $backup_mp_s3backer/file" 82 $backup_mp_s3backer/file $backup_mp_s3 ||
82 umount_list="$backup_mp_s3 $umount_list" 83 abend 1 "unable to mount $backup_mp_s3backer/file"
83 else 84 umount_list="$backup_mp_s3 $umount_list"
84 backup_mp_s3=$1 85 else
85 fi 86 backup_mp_s3=$1
86 epilogue_hook="s3_unmount $epilogue_hook" 87 fi
88 epilogue_hook="s3_unmount $epilogue_hook"
87} 89}
88 90
89s3_unmount() 91s3_unmount()
90{ 92{
91 if test "$1" = "--force"; then 93 if test "$1" = "--force"; then
92 for id in s3 backer 94 for id in s3 backer
93 do 95 do
94 mpoint=$(s3_getmpoint $id) 96 mpoint=$(s3_getmpoint $id)
95 test -n "$mpoint" && $dry_run umount $mpoint 97 test -n "$mpoint" && $dry_run umount $mpoint
96 done 98 done
97 else 99 else
98 for mpoint in $umount_list 100 for mpoint in $umount_list
99 do 101 do
100 test -n "$mpoint" && $dry_run umount $mpoint 102 test -n "$mpoint" && $dry_run umount $mpoint
101 done 103 done
102 fi 104 fi
103} 105}

Return to:

Send suggestions and report system problems to the System administrator.