-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
37 lines (32 loc) · 826 Bytes
/
run.sh
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
#!/bin/bash
AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID:?"AWS_ACCESS_KEY_ID required"}
AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY:?"AWS_SECRET_ACCESS_KEY required"}
AWS_BACKUP_BUCKET=${AWS_BACKUP_BUCKET:?"AWS_BACKUP_BUCKET required"}
DIRECTORY_TARGET=${DIRECTORY_TARGET:?"DIRECTORY_TARGET required"}
SLEEP_TIME=${SLEEP_TIME:-300} # 300 seconds / 5 minutes
backup() {
while true
do
echo "[$(date)] Backing up"
aws s3 sync $DIRECTORY_TARGET s3://$AWS_BACKUP_BUCKET
echo "[$(date)] Going to sleep..."
sleep $SLEEP_TIME
done
}
restore() {
echo "[$(date)] Restoring"
aws s3 sync s3://$AWS_BACKUP_BUCKET $DIRECTORY_TARGET
}
command=$1
case "$command" in
backup)
backup
;;
restore)
restore
;;
*)
echo "Do not recognise command. Use backup|restore"
RETVAL=1
esac
exit $RETVAL