Repository navigation
Expand file tree
/
Copy pathbc.sh
More file actions
executable file
·65 lines (56 loc) · 1.62 KB
/
Copy pathbc.sh
File metadata and controls
executable file
·65 lines (56 loc) · 1.62 KB
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
#!/bin/sh
# ------------------------------------------------------------
# bc.sh – Live‑disk backup for libvirt VMs
# ------------------------------------------------------------
# ------------------------------------------------------------
# Script/base dir
# ------------------------------------------------------------
get_base_dir() {
if [ -f "${0}" ]
then
# $0 points to a file on disk
printf '%s\n' "$(cd -- "$(dirname -- "${0}")" && pwd -P)"
else
# The script was sourced in a shell where $0 is not the script path
# Fallback to the current working directory
printf '%s\n' "$(pwd -P)"
fi
}
# ------------------------------------------------------------
# Main function to prevent occasional environment pollution
# ------------------------------------------------------------
closure() {
#set -x # debug
# Define BASE_DIR
BASE_DIR="$(get_base_dir)"
# Load library
LIB_SH="${BASE_DIR}/lib.sh"
if [ ! -e "${LIB_SH}" ]
then
printf "${LIB_SH} does not exist, exiting\n"
exit 1
fi
# shellcheck source=lib.sh
if ! . "${LIB_SH}"
then
printf "Could not load ${LIB_SH}, exiting\n"
exit 1
fi
unset LIB_SH
# Do the job
environment
create_backup_dirs_and_log
check_running
create_running
# Cleanup on interrupt
trap cleanup_on_exit INT TERM HUP QUIT
# Release the lock on normal exit
trap rm_running EXIT
create_current_backup_dir
clean_obsolete_backups
export_vm_and_disk_configuration
check_available_disk_space
backup_vms
validate_backups
}
closure