Compare commits

..

No commits in common. "1.0.1" and "1.0.0" have entirely different histories.
1.0.1 ... 1.0.0

3 changed files with 21 additions and 48 deletions

View File

@ -4,14 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased](https://git.d3data.de/D3Public/varbackup/compare/1.0.1...rel_1.x)
## [1.0.1](https://git.d3data.de/D3Public/varbackup/compare/1.0.0...1.0.1) - 2025-01-30
### Added
- verbose mode
### Changed
- normalize paths because of restore errors
- relative paths in tar for proper extraction
## [Unreleased](https://git.d3data.de/D3Public/varbackup/compare/1.0.0...rel_1.x)
## [1.0.0](https://git.d3data.de/D3Public/varbackup/releases/tag/1.0.0) - 2025-01-29
### Added

View File

@ -32,16 +32,14 @@ Create a cronjob or execute the following script manually:
### Restore last backup
Important: This overwrites all files without prompting!
```
tar -xf backup/var/latest.tar -C /home/project/base/dir/
tar -xvf backup/var/latest.tar
```
or
```
tar -xzf backup/var/var.tar.2025-01-01.gz -C /home/project/base/dir/
tar -xzvf backup/var/var.tar.2025-01-01.gz
```
## Customizing

View File

@ -5,63 +5,45 @@ Help()
# Display Help
echo "create a rotating backup of the var folder"
echo
echo "Syntax: varbackup [-h|s|v]"
echo "Syntax: varbackup [-h|s]"
echo "options:"
echo "h Print this Help"
echo "s Silent mode"
echo "v Verbose mode"
echo "h Print this Help."
echo "s Silent mode."
echo
}
while getopts ":hsv" option; do
while getopts ":hs" option; do
case $option in
h) # display Help
Help
exit
;;
exit;;
s) # enable silent mode
isSilent=true
;;
v) # enable verbose mode
verboseOption=" -v"
;;
"?")
echo -e "\e[31mUnknown option -$OPTARG\e[0m"
exit 1
;;
isSilent=true;;
esac
done
# main program
BASEDIR=$(readlink -f $(dirname "$0")/../../..)
BACKUPDIR=${BASEDIR}/backup/var/
CONFDIR=$BASEDIR/backup/
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[32mstarted\e[0m"
BASEDIR=$(dirname "$0")/../../..
BACKUPDIR=$BASEDIR/backup/var/
if [ ! -d "$BACKUPDIR" ]; then
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[36mcreate backup directory ${BACKUPDIR}\e[0m"
mkdir -p ${verboseOption} "${BACKUPDIR}"
[ -z ${isSilent} ] && echo "creating backup directory ${BACKUPDIR}"
mkdir -p "${BACKUPDIR}"
fi
if [ ! -f "${CONFDIR}rotatemap_var.conf" ]; then
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[36mcreate config file\e[0m"
printf "${BACKUPDIR}var.tar {\nrotate 100\ncompress\ndateext\ndateformat %s\n}" ".%Y-%m-%dT%H:%M:%S" > ${CONFDIR}rotatemap_var.conf
if [ ! -f "${BACKUPDIR}../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
fi
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[36mpack var directory\e[0m"
cd ${BASEDIR}
tar --numeric-owner ${verboseOption} -cf backup/var/new.tar var
[ -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
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[36madd to backup\e[0m"
cp ${verboseOption} ${BACKUPDIR}new.tar ${BACKUPDIR}latest.tar && \
mv ${verboseOption} ${BACKUPDIR}new.tar ${BACKUPDIR}var.tar && \
/usr/sbin/logrotate ${verboseOption} -fs ${CONFDIR}rotatemap_var.state ${CONFDIR}rotatemap_var.conf
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
else
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[36mdiscard unchanged\e[0m"
rm ${verboseOption} ${BACKUPDIR}new.tar
rm ${BACKUPDIR}new.tar
fi
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[32mfinished\e[0m"
[ -z ${isSilent} ] && echo "finished"
exit 0