forked from istepanov/docker-backup-to-s3
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbackup.sh
executable file
·37 lines (28 loc) · 944 Bytes
/
backup.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
set -e
dateISO() {
date -j -f "%s" $started -u +"%Y-%m-%dT%H:%M:%SZ"
}
started=$(date +%s)
startedAt=$(date -u -d @$started +"%Y-%m-%dT%H:%M:%SZ")
if [ "$PREFIX" ]; then
name="$PREFIX-$startedAt.tgz"
else
name="$startedAt.tgz"
fi
s3name=$name.aes
#echo "Starting backup from:$DATA_PATH to $S3_PATH/$s3name"
tar czf /tmp/$name -C $DATA_PATH .
openssl enc -aes-256-cbc -salt -k "${AES_PASSPHRASE}" -in /tmp/$name -out /tmp/$s3name
output=$(/usr/local/bin/s3cmd put -m application/octet-stream $PARAMS /tmp/$s3name "$S3_PATH" 2>&1 | tr '\n' ';' )
code=$?
if [ $code ]; then
result=ok
else
result="error:$code"
fi
rm -f /tmp/$name
rm -f /tmp/$s3name
finished=$(date +%s)
duration=$(( finished - started ))
printf "{\"backup\": { \"startedAt\":\"%s\", \"duration\":\"PT%is\", \"name\":\"%s/%s\", \"result\":\"%s\", \"output\":\"%s\"}}\n" "$startedAt" "$duration" "$S3_PATH" "$s3name" "$result" "$output"