-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup_s3
executable file
·64 lines (57 loc) · 1.61 KB
/
backup_s3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
USAGE="Usage: backup_s3 -u <user list> -s <s3 bucket> -e <EC2 server name>\n
\n
Creates a backup of group_work volume and user volumes in S3. Make sure you have your credentials in ~/.aws.
If you haven't set up your credentials yet, run 'aws configure' first.\n
\n
-u user list. Tab delimited list of users with three columns: port, user name, password\n
-s S3 bucket.\n
-e EC2 server name. This is used as directory name on S3.\n
"
while getopts ":u:s:e:" opt
do
case $opt in
u)
USERLIST=$OPTARG
;;
s)
S3BUCKET=$OPTARG
;;
e)
SERVERNAME=$OPTARG
;;
esac
done
# return usage if no options are passed
if [ $OPTIND -eq 1 ]
then
echo -e "No options were passed. \n" >&2
echo -e $USAGE >&2
exit 1
fi
# required options
if [ "$USERLIST" == "" ]; then echo "option -u is missing, but required">&2 && exit 1; fi
if [ "$SERVERNAME" == "" ]; then echo "option -e is missing, but required">&2 && exit 1; fi
if [ "$S3BUCKET" == "" ]; then echo "option -s is missing, but required">&2 && exit 1; fi
# S3BUCKET=single-cell-transcriptomics
# SERVERNAME=general
# USERLIST=small_userlist.txt
docker run \
--rm \
-v ~/.aws:/root/.aws \
--mount source=group,target=/group_work,readonly \
amazon/aws-cli \
s3 sync --delete --quiet \
/group_work \
s3://$S3BUCKET/$SERVERNAME/group_work
cat $USERLIST | tr -d '\015\040' | while read port user password
do
docker run \
--rm \
-v ~/.aws:/root/.aws \
--mount source=$user,target=/root/$user,readonly \
amazon/aws-cli \
s3 sync --delete --quiet \
/root/$user/ \
s3://$S3BUCKET/$SERVERNAME/users/$user
done