* target: tests/.environment.sh * don't pass BIN_DIR around * manage db backup/restore separately * don't export CONFIG_DIR, DATA_DIR (derive path locations from CONFIG_YAML); redirect stdout, stderr to &3 by default in setup_file, teardown_file
53 lines
1.1 KiB
Bash
Executable file
53 lines
1.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -eu
|
|
script_name=$0
|
|
|
|
die() {
|
|
echo >&2 "$@"
|
|
exit 1
|
|
}
|
|
|
|
about() {
|
|
die "usage: $script_name [backup | restore] <backup_file>"
|
|
}
|
|
|
|
#shellcheck disable=SC1007
|
|
THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
cd "${THIS_DIR}"
|
|
#shellcheck disable=SC1090
|
|
. ./.environment.sh
|
|
|
|
# you have not removed set -u above, have you?
|
|
|
|
[ -z "${CONFIG_YAML-}" ] && die "\$CONFIG_YAML must be defined."
|
|
|
|
# ---------------------------
|
|
|
|
[ $# -lt 1 ] && about
|
|
|
|
./assert-crowdsec-not-running
|
|
|
|
DATA_DIR=$(yq <"${CONFIG_YAML}" '.config_paths.data_dir')
|
|
DB_FILE="${DATA_DIR}/crowdsec.db"
|
|
|
|
case "$1" in
|
|
backup)
|
|
[ $# -lt 2 ] && about
|
|
backup_file="$2"
|
|
# dirty fast cp. nothing should be accessing it right now, anyway.
|
|
[ -f "${DB_FILE}" ] || die "missing file ${DB_FILE}"
|
|
cp "${DB_FILE}" "$backup_file"
|
|
;;
|
|
restore)
|
|
[ $# -lt 2 ] && about
|
|
backup_file="$2"
|
|
[ -f "$backup_file" ] || die "missing file $backup_file"
|
|
cp "$backup_file" "${DB_FILE}"
|
|
;;
|
|
*)
|
|
about
|
|
;;
|
|
esac;
|
|
|