#!/bin/sh # # Description: Archive jail and all dated copies (incs) # Usage: archive |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 printf "> Are you sure you want to archive jail \`%s'? [Y,n,?] " "${jail_name}" read -r answer case $answer in [Yy]|"" ) break ;; [Nn] ) 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"