diff --git a/CHANGELOG.md b/CHANGELOG.md index c2d6160..35c88e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +* bkctld-archive: archive a jail * bkctld-rename: rename a jail and all its incs and configuration… ### Changed diff --git a/bkctld b/bkctld index 373dbbd..1c37ceb 100755 --- a/bkctld +++ b/bkctld @@ -101,7 +101,7 @@ case "${subcommand}" in "${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${option}" fi ;; - "start" | "stop" | "reload" | "restart" | "sync" | "update" | "remove" | "firewall" | "upgrade-config") + "start" | "stop" | "reload" | "restart" | "sync" | "update" | "remove" | "firewall" | "upgrade-config" | "archive") jail_name="${2:-}" if [ "${jail_name}" = "all" ]; then for jail in $("${LIBDIR}/bkctld-list"); do diff --git a/bkctld.conf b/bkctld.conf index d6307a7..ea81ceb 100644 --- a/bkctld.conf +++ b/bkctld.conf @@ -14,3 +14,4 @@ #FIREWALL_RULES='' #LOGLEVEL=6 #NODE='' +#ARCHIVESDIR='/backup/archives' diff --git a/lib/bkctld-archive b/lib/bkctld-archive new file mode 100755 index 0000000..abf179d --- /dev/null +++ b/lib/bkctld-archive @@ -0,0 +1,51 @@ +#!/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" diff --git a/lib/includes b/lib/includes index f2aae3c..a2eb76b 100755 --- a/lib/includes +++ b/lib/includes @@ -17,6 +17,7 @@ INCDIR="${INCDIR:-${BACKUP_PARTITION}/incs}" TPLDIR="${TPLDIR:-/usr/share/bkctld}" LOCALTPLDIR="${LOCALTPLDIR:-/usr/local/share/bkctld}" LOCKDIR="${LOCKDIR:-/run/lock/bkctld}" +ARCHIVESDIR="${ARCHIVESDIR:-${BACKUP_PARTITION}/archives}" INDEX_DIR="${INDEX_DIR:-${BACKUP_PARTITION}/index}" IDX_FILE="${IDX_FILE:-${INDEX_DIR}/bkctld-jails.idx}" SSHD_PID="${SSHD_PID:-/run/sshd.pid}" @@ -157,6 +158,12 @@ jail_incs_policy_file() { echo "${jail_config_dir}/incs_policy" } +# Returns the complete path of an archived jail +archive_path() { + jail_name=${1:?} + + echo "${ARCHIVESDIR}/${jail_name}" +} # Returns the path of incs for a jail incs_path() { jail_name=${1:?}