2021-06-29 07:44:38 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Description: Archive jail and all dated copies (incs)
|
|
|
|
# Usage: archive <jailname>|all
|
|
|
|
# Return codes:
|
|
|
|
# * 101 : jail archival aborted
|
|
|
|
#
|
|
|
|
|
|
|
|
# shellcheck source=./includes
|
|
|
|
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
|
|
|
|
|
|
|
|
jail_name="${1:?}"
|
|
|
|
if [ -z "${jail_name}" ]; then
|
|
|
|
show_help && exit 1
|
|
|
|
fi
|
|
|
|
jail_path=$(jail_path "${jail_name}")
|
|
|
|
|
|
|
|
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
|
|
|
|
|
|
|
|
archive_jail_path=$(archive_path "${jail_name}")
|
|
|
|
|
|
|
|
test -d "${archive_jail_path}" && error "${jail_name}: archive already exists" 2
|
|
|
|
|
|
|
|
if [ "${FORCE}" != "1" ]; then
|
|
|
|
answer=""
|
|
|
|
while :; do
|
2021-06-30 14:59:54 +02:00
|
|
|
printf "> Are you sure you want to archive jail \`%s'? [Y,n,?] " "${jail_name}"
|
2021-06-29 07:44:38 +02:00
|
|
|
read -r answer
|
|
|
|
case $answer in
|
2021-06-30 14:59:54 +02:00
|
|
|
[Yy]|"" )
|
2021-06-29 07:44:38 +02:00
|
|
|
break
|
|
|
|
;;
|
2021-06-30 14:59:54 +02:00
|
|
|
[Nn] )
|
2021-06-29 07:44:38 +02:00
|
|
|
tty -s && echo "Abort." >&2
|
|
|
|
exit 101
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
printf "y - yes, execute actions and exit\n"
|
|
|
|
printf "n - no, don't execute actions and exit\n"
|
|
|
|
printf "? - print this help\n"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
"${LIBDIR}/bkctld-is-on" "${jail_name}" && "${LIBDIR}/bkctld-stop" "${jail_name}"
|
|
|
|
|
|
|
|
mkdir -p "$(dirname "${archive_jail_path}")"
|
|
|
|
mv "${jail_path}" "${archive_jail_path}"
|
|
|
|
|
|
|
|
notice "Archive jail \`${jail_name}' : OK"
|