evobackup/lib/bkctld-rm
Victor LABORIE 842e57ba53 Big refactoring
* Jails are created on start and run in tmpfs
* All config files are on /etc/bkctld
* Cleaning of sshd_config and /etc/group
2020-01-08 14:46:18 +01:00

47 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
#
# Remove old incremtal inc of all jails
# Usage: rm
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
empty="/tmp/bkctld-${$}-$(date +%N))"
mkdir "${empty}"
pidfile="/var/run/bkctld-rm.pid"
if [ -f "${pidfile}" ]; then
pid=$(cat "${pidfile}")
ps -u "${pid}" >/dev/null
if [ "${?}" -eq 0 ]; then
kill -9 "${pid}"
warning "${0} rm always run (PID ${pid}), killed by ${$} !"
fi
rm "${pidfile}"
fi
echo "${$}" > "${pidfile}"
for jail in $("${LIBDIR}/bkctld-list"); do
keepfile="$(mktemp)"
while read j; do
date=$( echo "${j}" | cut -d. -f1 )
before=$( echo "${j}" | cut -d. -f2 )
date -d "$(date "${date}") ${before}" "+%Y-%m-%d"
done < "${CONFDIR}/${jail}" > "${keepfile}"
incs=$(find "${MOUNT_POINT}/${jail}" -mindepth 1 -maxdepth 1 -type d ! -name last -exec basename {} \;)
for j in ${incs}; do
start=$(date +"%H:%M:%S")
inc_inode=$(stat --format=%i "${MOUNT_POINT}/${jail}/${j}")
if [ "${inc_inode}" -eq 256 ]; then
/bin/btrfs subvolume delete "${MOUNT_POINT}/${jail}/${j}" | debug
else
cd "${MOUNT_POINT}/${jail}"
rsync -a --delete "${empty}/" "${j}/"
rmdir "${j}"
fi
end=$(date +"%H:%M:%S")
notice "${jail} : deleted ${j} inc [${start}/${end}]"
done
rm "${keepfile}"
done
rmdir "${empty}"
rm "${pidfile}"