evobackup/lib/bkctld-inc

84 lines
2.4 KiB
Plaintext
Raw Normal View History

2019-01-04 13:51:05 +01:00
#!/bin/sh
#
# Make incremental inc of all jails
# Usage: inc
#
2019-01-04 13:51:05 +01:00
2020-04-01 11:23:35 +02:00
# shellcheck source=./config
2019-01-04 13:51:05 +01:00
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
create_inc_btrfs() {
jail_name=$1
inc_name=$2
jail_path=$(jail_path "${jail_name}")
inc_path=$(inc_path "${jail_name}" "${inc_name}")
start=$(current_time)
if dry_run; then
echo "[dry-run] btrfs subvolume snapshot of ${jail_path} to ${inc_path}"
else
mkdir --parents "$(dirname "${inc_path}")"
# create a btrfs readonly snapshot from the jail
/bin/btrfs subvolume snapshot -r "${jail_path}" "${inc_path}" | debug
fi
end=$(current_time)
notice "${jail_name} : ${inc_name} inc created [${start}/${end}]"
}
create_inc_ext() {
jail_name=$1
inc_name=$2
jail_path=$(jail_path "${jail_name}")
inc_path=$(inc_path "${jail_name}" "${inc_name}")
lock="${LOCKDIR}/inc-${jail_name}.lock"
if [ -f "${lock}" ]; then
warning "${jail_name} : skipping ${inc_name}, it is already being created."
else
(
start=$(current_time)
mkdir --parents "${LOCKDIR}" && touch "${lock}"
# shellcheck disable=SC2064
trap "rm -f ${lock}" 0
if dry_run; then
echo "[dry-run] copy of ${jail_path} to ${inc_path}"
else
mkdir --parents "$(dirname "${inc_path}")"
# create a copy of the jail with hard links
cp --archive --link --one-file-system "${jail_path}/" "${inc_path}"
fi
end=$(current_time)
notice "${jail_name} : ${inc_name} inc created [${start}/${end}]"
)
fi
}
inc_name=$(date +"%Y-%m-%d-%H")
for jail_name in $(jails_list); do
jail_path=$(jail_path "${jail_name}")
inc_path=$(inc_path "${jail_name}" "${inc_name}")
incs_policy_file=$(jail_incs_policy_file ${jail_name})
# If not incs policy is found, we don't create incs
if [ -n "${incs_policy_file}" ]; then
# If not incs directory is found, we don't create incs
if [ ! -d "${inc_path}" ]; then
if is_btrfs "${jail_path}"; then
create_inc_btrfs "${jail_name}" "${inc_name}"
else
create_inc_ext "${jail_name}" "${inc_name}"
fi
else
warning "${jail_name} : skipping ${inc_name}, it already exists."
2019-01-04 13:51:05 +01:00
fi
else
warning "${jail_name} : skipping ${inc_name}, incs policy not found."
2019-01-04 13:51:05 +01:00
fi
done