-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestore.sh
executable file
·72 lines (58 loc) · 1.79 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
68
69
70
71
72
#!/bin/bash
BACKUP_DIR=/var/backup/octane/
STANDBY_IP=67.217.83.5
STANDBY_DIR=/var/backup/octane/
MASTER_HOSTNAME=fuel1
STANDBY_HOSTNAME=fuel2
PASSWORD=
DATE=`date +%F`
STATE_FILE=fuel-backup.8.0.tar.gz
REPO_FILE=fuel-repo-backup.8.0.tar.gz
LOG_FILE=/var/log/master_standby.log
exec 1<&-
exec 2<&-
exec 1<>$LOG_FILE
exec 2>&1
#TODO check octane installed
set +e
type octane >/dev/null 2>&1
if [ $? -eq 1 ]; then
echo 'There is no fuel-octane. Run "yum install fuel-octane" first.'
exit 1
fi
set -e
#check latest backup exist
LAST_DIR=`ls -t $STANDBY_DIR -1|head -n 1`
if ! [ -d $STANDBY_DIR/$LAST_DIR ]; then
echo "Unexpected files in $STANDBY_DIR. Aborting."
exit 1
fi
if ! [ -s $STANDBY_DIR/$LAST_DIR/$STATE_FILE ]; then
echo "File $STANDBY_DIR/$LAST_DIR/$STATE_FILE do not exist. Aborting."
exit 1
fi
if ! [ -s $STANDBY_DIR/$LAST_DIR/$REPO_FILE ]; then
echo "File $STANDBY_DIR/$LAST_DIR/$REPO_FILE do not exist. Aborting."
exit 1
fi
#change astute.yaml in tarball
if [ -s astute/astute.yaml ]; then
rm astute/astute.yaml
fi
if ! [ -d astute ]; then
mkdir astute 2>/dev/null
fi
tar -Oxzf $STANDBY_DIR/$LAST_DIR/$STATE_FILE astute/astute.yaml | python -c "import sys;import yaml; data = yaml.load(sys.stdin);data['HOSTNAME']=\"${STANDBY_HOSTNAME}\"; yaml.dump(data, sys.stdout);" >astute/astute.yaml
if [ -s astute/astute.yaml ]; then
tar_file=$STANDBY_DIR/$LAST_DIR/${STATE_FILE%.*}
gunzip $STANDBY_DIR/$LAST_DIR/$STATE_FILE
tar -uf $tar_file astute/astute.yaml
gzip $tar_file
else
echo "Astute.yaml modify was unsuccessful. Aborting."
exit 1
fi
#restore backup
octane fuel-restore --from $STANDBY_DIR/$LAST_DIR/$STATE_FILE --admin-password $PASSWORD
octane fuel-repo-restore --from $STANDBY_DIR/$LAST_DIR/$REPO_FILE
#delete backup files (optionaly)