Compare commits

..

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

3 changed files with 21 additions and 55 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/), 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). 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) ## [Unreleased](https://git.d3data.de/D3Public/varbackup/compare/1.0.0...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
## [1.0.0](https://git.d3data.de/D3Public/varbackup/releases/tag/1.0.0) - 2025-01-29 ## [1.0.0](https://git.d3data.de/D3Public/varbackup/releases/tag/1.0.0) - 2025-01-29
### Added ### Added

View File

@ -32,25 +32,16 @@ Create a cronjob or execute the following script manually:
### Restore last backup ### Restore last backup
Important: This overwrites all files without prompting!
If a restore is necessary, please restore all files. Do not perform a partial restore.
``` ```
tar -xf backup/var/latest.tar -C /home/project/base/dir/ tar -xvf backup/var/latest.tar
``` ```
or 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
``` ```
## Daily use
It is highly recommended to set up a cronjob that performs this backup periodically (e.g. daily).
You can also use this command for all critical actions (such as Composer calls) by adding it to the alias.
## Customizing ## Customizing
Execute the script initially. After that, modify the `backup/var/rotatemap_var.conf` to your need Execute the script initially. After that, modify the `backup/var/rotatemap_var.conf` to your need

View File

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