2019-01-04 13:51:05 +01:00
|
|
|
#!/bin/sh
|
2019-01-07 14:47:05 +01:00
|
|
|
#
|
|
|
|
# Make incremental inc of all jails
|
|
|
|
# Usage: inc
|
|
|
|
#
|
2019-01-04 13:51:05 +01:00
|
|
|
|
2020-04-02 13:44:13 +02:00
|
|
|
# shellcheck source=./includes
|
2020-04-02 00:31:57 +02:00
|
|
|
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
|
2019-01-04 13:51:05 +01:00
|
|
|
|
2020-04-01 18:39:56 +02:00
|
|
|
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)
|
2020-04-02 14:50:55 +02:00
|
|
|
notice "${jail_name}: inc '${inc_name}' has been created [${start}/${end}]"
|
2020-04-01 18:39:56 +02:00
|
|
|
}
|
|
|
|
create_inc_ext() {
|
|
|
|
jail_name=$1
|
|
|
|
inc_name=$2
|
|
|
|
|
|
|
|
jail_path=$(jail_path "${jail_name}")
|
|
|
|
inc_path=$(inc_path "${jail_name}" "${inc_name}")
|
|
|
|
|
2020-04-02 18:29:40 +02:00
|
|
|
# The lock file prevents from starting a new copy when one is already being done
|
|
|
|
lock_file="${LOCKDIR}/inc-${jail_name}-${inc_name}.lock"
|
|
|
|
if [ -f "${lock_file}" ]; then
|
2020-04-02 14:50:55 +02:00
|
|
|
warning "${jail_name}: skipping '${inc_name}', it is already being created."
|
2020-04-01 18:39:56 +02:00
|
|
|
else
|
|
|
|
(
|
|
|
|
start=$(current_time)
|
2020-04-02 18:29:40 +02:00
|
|
|
mkdir --parents "${LOCKDIR}" && touch "${lock_file}"
|
2020-04-01 18:39:56 +02:00
|
|
|
# shellcheck disable=SC2064
|
2020-04-02 18:29:40 +02:00
|
|
|
trap "rm -f ${lock_file}" 0
|
2020-04-01 18:39:56 +02:00
|
|
|
|
|
|
|
if dry_run; then
|
|
|
|
echo "[dry-run] copy of ${jail_path} to ${inc_path}"
|
2020-03-05 14:42:29 +01:00
|
|
|
else
|
2020-04-01 18:39:56 +02:00
|
|
|
mkdir --parents "$(dirname "${inc_path}")"
|
|
|
|
# create a copy of the jail with hard links
|
|
|
|
cp --archive --link --one-file-system "${jail_path}/" "${inc_path}"
|
2020-03-05 14:42:29 +01:00
|
|
|
fi
|
2020-04-01 18:39:56 +02:00
|
|
|
|
|
|
|
end=$(current_time)
|
2020-04-02 14:50:55 +02:00
|
|
|
notice "${jail_name}: in '${inc_name}' has been created [${start}/${end}]"
|
2020-04-01 18:39:56 +02:00
|
|
|
)
|
|
|
|
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}")
|
2020-04-02 18:26:53 +02:00
|
|
|
incs_policy_file=$(current_jail_incs_policy_file ${jail_name})
|
2020-04-01 18:39:56 +02:00
|
|
|
|
|
|
|
# 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
|
2020-04-02 01:07:12 +02:00
|
|
|
warning "${jail_name}: skipping ${inc_name}, it already exists."
|
2019-01-04 13:51:05 +01:00
|
|
|
fi
|
|
|
|
else
|
2020-04-02 01:07:12 +02:00
|
|
|
warning "${jail_name}: skipping ${inc_name}, incs policy not found."
|
2019-01-04 13:51:05 +01:00
|
|
|
fi
|
|
|
|
done
|