-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·63 lines (48 loc) · 1.61 KB
/
backup.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
#!/bin/bash
# SPDX-FileCopyrightText: 2022 Wilfred Nicoll <xyzroller@rollyourown.xyz>
# SPDX-License-Identifier: GPL-3.0-or-later
# backup.sh
# This script backs up the persistent storage for a module
# Help and error messages
#########################
helpMessage()
{
echo "backup.sh: Back up the persistent storage for a module"
echo "Usage: ./backup.sh -n hostname -v version"
echo "Flags:"
echo -e "-n hostname \t\t(Mandatory) Name of the host from which to back up module container persistent storage"
echo -e "-s stamp \t\t(Mandatory) A stamp (e.g. date, time, name) to identify the backup"
echo -e "-h \t\t\tPrint this help message"
echo ""
exit 1
}
errorMessage()
{
echo "Invalid option or input variables are missing"
echo "Use \"./backup.sh -h\" for help"
exit 1
}
# Command-line input handling
#############################
restore="false"
while getopts n:s:rh flag
do
case "${flag}" in
n) hostname=${OPTARG};;
s) stamp=${OPTARG};;
h) helpMessage ;;
?) errorMessage ;;
esac
done
if [ -z "$hostname" ] || [ -z "$stamp" ]; then
errorMessage
fi
# Script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Get Module ID from configuration file
MODULE_ID="$(yq eval '.module_id' "$SCRIPT_DIR"/configuration/configuration.yml)"
echo "Starting backup of "$MODULE_ID" on "$hostname""
/bin/bash "$SCRIPT_DIR"/scripts-module/stop-module-containers.sh -n "$hostname"
/bin/bash "$SCRIPT_DIR"/scripts-module/backup-module.sh -n "$hostname" -s "$stamp"
/bin/bash "$SCRIPT_DIR"/scripts-module/start-module-containers.sh -n "$hostname"
echo "Backup completed"