forked from mohamnag/docker-s3-dir-backup
-
Notifications
You must be signed in to change notification settings - Fork 2
/
restore.sh
34 lines (24 loc) · 993 Bytes
/
restore.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
#!/bin/bash
if [ -z "$RESTORE_FILE_PATH" ]; then
echo "finding last backup..."
# find last object in bucket
LAST_OBJ=`/usr/local/bin/aws s3 ls s3://${BACKUP_S3_BUCKET}/ --recursive --region ${AWS_DEFAULT_REGION} | grep ".gz" | sort | tail -n 1 | awk '{print $4}'`
else
echo "restoring requested backup..."
LAST_OBJ=$RESTORE_FILE_PATH
fi
# make full path for last backup object, is necessary because bucket name may have path inside
LAST_OBJ=`echo ${BACKUP_S3_BUCKET} | sed -e 's/\/.*//g'`/${LAST_OBJ}
echo "backup file to resotre: s3://${LAST_OBJ}"
echo "downloading backup from S3..."
/usr/local/bin/aws s3 cp s3://${LAST_OBJ} ${BACKUP_TGT_DIR} --region ${AWS_DEFAULT_REGION}
echo "backup download finished"
BCK_FILE=${BACKUP_TGT_DIR}`echo ${LAST_OBJ} | sed -e 's/\(.*\/\)*//g'`
tar -xzvf ${BCK_FILE} -C ${BACKUP_SRC_DIR}
rm ${BCK_FILE}
if [ -z "$RESTORE_RESUME_BACKUP" ]; then
echo "restore finished, exiting"
else
echo "continuing with backup corn job..."
/opt/cron.sh
fi