bkctld-archive: archive a jail

This commit is contained in:
Jérémy Lecour 2021-06-29 07:44:38 +02:00 committed by Jérémy Lecour
parent d467690ff5
commit 134faf3e47
5 changed files with 61 additions and 1 deletions

View File

@ -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

2
bkctld
View File

@ -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

View File

@ -14,3 +14,4 @@
#FIREWALL_RULES=''
#LOGLEVEL=6
#NODE=''
#ARCHIVESDIR='/backup/archives'

51
lib/bkctld-archive Executable file
View File

@ -0,0 +1,51 @@
#!/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
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"

View File

@ -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:?}