This repository has been archived by the owner on Aug 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdump_snapshot
executable file
·120 lines (103 loc) · 4.34 KB
/
dump_snapshot
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
export PATH=$PATH:/usr/sbin
SCALEIO_SERVERS="scaleio1.example.com scaleio2.example.com scaleio3.example.com"
SCALEIO_PW="<SCALEIO_PASSWORD>"
TARGET_DEVICE=/dev/scinia
BACKUP_LOCATION=/volumedump
MYIP=$(ip addr show dev eth0 | awk -F'[ /]*' '/inet/ {print $3}')
PASSWORD_FILE=/etc/backup-passwords.txt
RATE=70m
COMPRESS_PROGRAM=gzip
# yum install pigz and change COMPRESS_PROGRAM above for better performance on multi-core hosts
show_help() {
echo -e "\nThis script will attach a given snapshot volume ID temporarily as ${TARGET_DEVICE} and encrypt it into a gzip file within ${BACKUP_LOCATION}/."
echo -e "\nUsage: dump_snapshot [OPTIONS] (-i volume_id) \n"
echo "OPTIONS:"
echo " -h, -? help"
echo " -f display only the output filepath upon success"
echo " -i scaleIO volume_id to dump"
echo -e " -v increase verbosity\n"
exit 1
}
OPTIND=1
VOLUME_ID=
FILEPATH_ONLY=0
VERBOSE=0
while getopts "fh?i:v" opt; do
case "$opt" in
f) FILEPATH_ONLY=1
;;
h|\?)
show_help
exit 0
;;
i) VOLUME_ID=$OPTARG
;;
v) VERBOSE=1
;;
esac
done
shift $((OPTIND-1))
if [ "${VOLUME_ID}" == "" ]
then
show_help
exit 1
fi
if [[ -f ${TARGET_DEVICE} || -b ${TARGET_DEVICE} ]]; then
echo -e "\nERROR: ${TARGET_DEVICE} already exists on this host. Aborting."; exit 1
fi
#Find out which server is our current primary MDM
PRIMARY_SERVER=
for SERVER in ${SCALEIO_SERVERS}; do
OUTPUT=$(ssh ${SERVER} "scli --login --username admin --password ${SCALEIO_PW} 2>&1")
#Error: Failed to connect
#Logged in. User role is SuperUser. System ID is 78221ddb0dcff2f5
WORKED=$(echo "${OUTPUT}" | grep 'Logged in')
if [ $? -eq 0 ]; then
PRIMARY_SERVER=${SERVER}
break
fi
done
if [ "${PRIMARY_SERVER}" != "" ]; then
if [ ${VERBOSE} -eq 1 ]; then echo -e "Found primary ScaleIO MDM ${PRIMARY_SERVER}\n"; fi
OUTPUT=$(ssh ${PRIMARY_SERVER} "scli --query_volume --volume_id ${VOLUME_ID}")
if [ ${VERBOSE} -eq 1 ]; then echo -e "${OUTPUT}\n"; fi
WORKED=$(echo "${OUTPUT}" | grep 'Volume is unmapped')
if [ $? -eq 0 ]; then
OUTPUT=$(ssh ${PRIMARY_SERVER} "scli --map_volume_to_sdc --volume_id ${VOLUME_ID} --sdc_ip ${MYIP}")
#Successfully mapped volume with ID 597033bd0000001f to SDC 224.36.61.124
if [ ${VERBOSE} -eq 1 ]; then echo -e "${OUTPUT}\n"; fi
WORKED=$(echo "${OUTPUT}" | grep 'Successfully mapped')
if [ $? -eq 0 ]; then
sleep 5
if [ ${FILEPATH_ONLY} -eq 0 ]; then
echo "Mapped volume ID ${VOLUME_ID} to ${TARGET_DEVICE}. Dumping to ${BACKUP_LOCATION}/${VOLUME_ID}.gz"
OUTPUT=$(time dd bs=1048576 if=${TARGET_DEVICE} | pv -q --rate-limit ${RATE} | ${COMPRESS_PROGRAM} -1 --stdout - | openssl enc -e -aes-128-ctr -pass file:${PASSWORD_FILE} -out ${BACKUP_LOCATION}/${VOLUME_ID}.gz)
else
OUTPUT=$(dd bs=1048576 if=${TARGET_DEVICE} 2>>/dev/null | pv -q --rate-limit ${RATE} | ${COMPRESS_PROGRAM} -1 --stdout - | ${COMPRESS_PROGRAM} -1 --stdout - | openssl enc -e -aes-128-ctr -pass file:${PASSWORD_FILE} -out ${BACKUP_LOCATION}/${VOLUME_ID}.gz)
fi
if [ $? -eq 0 ]; then
if [ ${FILEPATH_ONLY} -eq 0 ]; then
echo "${OUTPUT}"; ls -lrt ${BACKUP_LOCATION}/${VOLUME_ID}.gz
else
echo "${BACKUP_LOCATION}/${VOLUME_ID}.gz"
fi
fi
OUTPUT=$(ssh ${PRIMARY_SERVER} "scli --unmap_volume_from_sdc --volume_id ${VOLUME_ID} --sdc_ip ${MYIP} --i_am_sure")
#Successfully un-mapped volume with ID 597033bd0000001f from SDC 224.36.61.124
if [ ${VERBOSE} -eq 1 ]; then echo -e "${OUTPUT}\n"; fi
WORKED=$(echo "${OUTPUT}" | grep 'Successfully un-mapped')
if [ $? -ne 0 ]; then
if [ ${VERBOSE} -eq 1 ]; then echo -e "${OUTPUT}\n"; fi
(>&2 echo "WARNING: Volume unmap to this SDC was not successful. You may need to do the following manually on the primary MDM:")
(>&2 echo "scli --unmap_volume_from_sdc --volume_id ${VOLUME_ID} --sdc_ip ${MYIP} --i_am_sure"); exit 2
fi
else
(>&2 echo -e "\n${OUTPUT}\nERROR: Failed to successfull map volume to this SDC."); exit 1
fi
else
(>&2 echo -e "\n${OUTPUT}\nERROR: Unable to find unmapped volume ${VOLUME_ID}."); exit 1
fi
else
(>&2 echo "ERROR: Could not determine the primary ScaleIO MDM server. Aborting."); exit 1
fi