This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
export
executable file
·71 lines (55 loc) · 2.09 KB
/
export
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
#!/bin/bash
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
set -e
env > "/tmp/EXPORT_DERPYNESS_$(date +%s)"
. common.sh
# Executing a full raw backup of the device using dd making a file-disk-image.
if [ ! -b $blockdev ]; then
echo "ERROR: ${blockdev} is not a Block Device."
cleanup
exit 1
fi
# Load the configurations for this os definition
if [ -f environment.sh ]; then
. environment.sh
else
exit 1
fi
# File to use as template to create the rebuild helper script
REBUILD_TEMPLATE=rebuild.sh.template
# local variables used to create the helper script for the restore
EXPORT_PATH=${EXPORT_DIR}/${INSTANCE_NAME}.new
#Perform the export
dd if=${blockdev} bs=512 | pigz -p 4
EXIT_STATUS="$?"
# Create temporary directory
TMP_DIR="/tmp/ganeti-export/${INSTANCE_NAME}"
[ -d ${TMP_DIR} ] || mkdir -p ${TMP_DIR}
# Create into the backup directory the shell script helper to help the user to
# rebuild the instance
cat ${REBUILD_TEMPLATE} | sed -e "s/%INSTANCE_NAME%/${INSTANCE_NAME}/g" \
-e "s/%INSTANCE_PRIMARY_NODE%/${INSTANCE_PRIMARY_NODE}/g" \
-e "s/%INSTANCE_SECONDARY_NODES%/${INSTANCE_SECONDARY_NODES}/g" \
> ${TMP_DIR}/rebuild.sh
# Copy the files into the backup directory
# NOTE: One of the following commands always fails
scp ${TMP_DIR}/* ${INSTANCE_PRIMARY_NODE}:${EXPORT_PATH}/ || true
scp ${TMP_DIR}/* ${INSTANCE_SECONDARY_NODES}:${EXPORT_PATH}/ || true
rm -fr ${TMP_DIR}
# execute cleanups
cleanup
trap - EXIT
exit ${EXIT_STATUS}