forked from nullart/debian-ubuntu-mariadb-backup
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextract-mariadb.sh
executable file
·82 lines (61 loc) · 2.57 KB
/
extract-mariadb.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
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
log_file="extract-progress.log"
source "$(dirname "$0")/config.sh"
source "$(dirname "$0")/lib.sh"
number_of_args="${#}"
sanity_check () {
check_backup_user
# Check whether the qpress binary is installed
if ! command -v qpress >/dev/null 2>&1; then
error "Could not find the \"qpress\" command. Please install it and try again."
fi
# Check whether any arguments were passed
if [ "${number_of_args}" -lt 1 ]; then
error "Script requires at least one \".xbstream\" file as an argument."
fi
# Check whether the encryption key file is available
#if [ ! -r "${encryption_key_file}" ]; then
# error "Cannot read encryption key at ${encryption_key_file}"
#fi
}
do_extraction () {
for file in "${@}"; do
base_filename="$(basename "${file%.xbstream}")"
restore_dir="./restore/${base_filename}"
echo "Extracting file ${file}"
# Extract the directory structure from the backup file
mbstream_output="$(mktemp)"
run mkdir --verbose -p "${restore_dir}" >&$log ||\
error "mkdir ${restore_dir} failed"
run mbstream -v -x -C "${restore_dir}" < "${file}" > >(tee "$mbstream_output" >&$log) 2>&1 ||\
error "mbstream failed"
#"--decrypt=AES256"
#"--encrypt-key-file=${encryption_key_file}"
# workaround: mbstream doesn't always exit non-zero on errors
if grep -iE 'error|fail' "$mbstream_output"; then
error "mbstream failed"
fi
# work around a bug: mbstream creates an extra copy of xtrabackup_info
# in the original backup dir
# https://jira.mariadb.org/browse/MDEV-18438
extra_info_file="$(grep /xtrabackup_info "$mbstream_output" | grep -v decompressing | sed -r 's/\[[^]]+\] ....-..-.. ..:..:.. //')"
if [ -n "$extra_info_file" ]; then
run rm -f "$extra_info_file" || error "failed to remove extra xtrabackup_info file"
fi
rm -f "$mbstream_output"
mariabackup_args=(
"--parallel=${processors}"
"--decompress"
)
run mariabackup "${mariabackup_args[@]}" --target-dir="${restore_dir}" >&$log ||\
error "mariabackup failed"
run find "${restore_dir}" -name "*.qp" -exec rm {} \; ||\
error "find *.qp in ${restore_dir} failed"
echo "Finished work on ${file}"
done
}
# truncate log file
>"${log_file}"
sanity_check && do_extraction "$@" 2>&$log
printf "Extraction complete! Backup directories have been extracted to the \"restore\" directory.\n"
exit 0