normalize file paths for restoring

This commit is contained in:
Daniel Seifert 2025-01-29 17:05:08 +01:00
parent f61ed651d9
commit c8ef3d4eb4

View File

@ -23,24 +23,25 @@ while getopts ":hs" option; do
done
# main program
BASEDIR=$(dirname "$0")/../../..
BACKUPDIR=$BASEDIR/backup/var/
BASEDIR=$(readlink -f $(dirname "$0")/../../..)
BACKUPDIR=${BASEDIR}/backup/var/
CONFDIR=$BASEDIR/backup/
if [ ! -d "$BACKUPDIR" ]; then
[ -z ${isSilent} ] && echo "creating backup directory ${BACKUPDIR}"
mkdir -p "${BACKUPDIR}"
fi
if [ ! -f "${BACKUPDIR}../rotatemap_var.conf" ]; then
if [ ! -f "${CONFDIR}rotatemap_var.conf" ]; then
[ -z ${isSilent} ] && echo "creating config file"
printf "${BACKUPDIR}var.tar {\nrotate 100\ncompress\ndateext\ndateformat %s\n}" ".%Y-%m-%dT%H:%M:%S" > ${BACKUPDIR}/../rotatemap_var.conf
printf "${BACKUPDIR}var.tar {\nrotate 100\ncompress\ndateext\ndateformat %s\n}" ".%Y-%m-%dT%H:%M:%S" > ${CONFDIR}rotatemap_var.conf
fi
[ -z ${isSilent} ] && echo "pack var directory"
tar --numeric-owner --absolute-names -cf ${BACKUPDIR}new.tar ${BASEDIR}/var;
if [ ! -f "${BACKUPDIR}latest.tar" ] || [ "$(cmp ${BACKUPDIR}latest.tar ${BACKUPDIR}new.tar)" ]; then
cp ${BACKUPDIR}new.tar ${BACKUPDIR}latest.tar && mv ${BACKUPDIR}new.tar ${BACKUPDIR}var.tar && /usr/sbin/logrotate -fs ${BACKUPDIR}../rotatemap_var.state ${BACKUPDIR}../rotatemap_var.conf
cp ${BACKUPDIR}new.tar ${BACKUPDIR}latest.tar && mv ${BACKUPDIR}new.tar ${BACKUPDIR}var.tar && /usr/sbin/logrotate -fs ${CONFDIR}rotatemap_var.state ${CONFDIR}rotatemap_var.conf
else
rm ${BACKUPDIR}new.tar
fi