-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore.sh
executable file
·68 lines (47 loc) · 1.85 KB
/
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
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
65
66
67
#!/bin/sh
set -e
if [ "$TAR_PATH" = "" ]; then
_file="$TAR_TO_RESTORE"
else
echo "Getting latest filename"
aws configure set aws_access_key_id $S3_KEY
aws configure set aws_secret_access_key $S3_SECRET
filename=`aws --endpoint-url $S3_PROTOCOL://$S3_HOST/ s3 ls s3://$S3_BUCKET/$TAR_PATH/ | sort | tail -n 1 | awk '{print $4}'`
echo $filename
_file="$TAR_PATH/$filename"
fi
bucket="$S3_BUCKET"
host="$S3_HOST"
link="$S3_PROTOCOL""://""$S3_HOST"
echo "$link"
s3_key="$S3_KEY"
s3_secret="$S3_SECRET"
resource="/${bucket}/${_file}"
content_type="application/octet-stream"
date=`date -R`
_signature="GET\n\n${content_type}\n${date}\n${resource}"
signature=`echo -en ${_signature} | openssl sha1 -hmac ${s3_secret} -binary | base64`
echo $signature
echo "Download file $link${resource}"
curl -v -H "Host: $host" \
-H "Date: ${date}" \
-H "Content-Type: ${content_type}" \
-H "Authorization: AWS ${s3_key}:${signature}" \
$link${resource} -o out.tar.gz
echo "SUBSTITUTING FILES!!!"
if [ "$TRANSFORM_FROM" = "" ]; then
tar -xvf out.tar.gz -C /
else
tar -xvf out.tar.gz -C /
rsync -avh $TRANSFORM_FROM $TRANSFORM_TO --delete
rm -rf $TRANSFORM_FROM
fi
rm out.tar.gz
if [ -n "$NEW_WORDPRESS_WPCONFIG_PATH" ]; then
echo "REPLACING WORDPRESS CONFIG"
sed -i "s;\(define([[:space:]]*'DB_HOST',[[:space:]]*\)\(.*\)\()\;\);\1'$NEW_WORDPRESS_HOST'\3;g" $NEW_WORDPRESS_WPCONFIG_PATH
sed -i "s;\(define([[:space:]]*'DB_NAME',[[:space:]]*\)\(.*\)\()\;\);\1'$NEW_WORDPRESS_DBNAME'\3;g" $NEW_WORDPRESS_WPCONFIG_PATH
sed -i "s;\(define([[:space:]]*'DB_USER',[[:space:]]*\)\(.*\)\()\;\);\1'$NEW_WORDPRESS_DBUSER'\3;g" $NEW_WORDPRESS_WPCONFIG_PATH
sed -i "s;\(define([[:space:]]*'DB_PASSWORD',[[:space:]]*\)\(.*\)\()\;\);\1'$NEW_WORDPRESS_DBPASS'\3;g" $NEW_WORDPRESS_WPCONFIG_PATH
echo "DONE REPLACING WORDPRESS CONFIG"
fi