Compare commits

...

8 Commits

Author SHA1 Message Date
f95211cf50 update documentation 2025-02-19 09:23:29 +01:00
8381cc3a94 update changelog 2025-01-30 09:05:55 +01:00
bd08bac175 add more verbosity 2025-01-30 09:02:00 +01:00
1d69db0356 deal with unknown option 2025-01-30 09:01:34 +01:00
56bf23adaa add verbose mode 2025-01-30 09:01:01 +01:00
8762bab150 set create tar base path
tar ignores -C option while create
2025-01-30 08:27:48 +01:00
a7c0eccde5
use relative paths for tarball for proper extraction 2025-01-29 21:22:22 +01:00
c8ef3d4eb4 normalize file paths for restoring 2025-01-29 17:05:08 +01:00
3 changed files with 55 additions and 21 deletions

View File

@ -4,7 +4,14 @@ 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.0...rel_1.x)
## [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
## [1.0.0](https://git.d3data.de/D3Public/varbackup/releases/tag/1.0.0) - 2025-01-29
### Added

View File

@ -32,16 +32,25 @@ Create a cronjob or execute the following script manually:
### 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 -xvf backup/var/latest.tar
tar -xf backup/var/latest.tar -C /home/project/base/dir/
```
or
```
tar -xzvf backup/var/var.tar.2025-01-01.gz
tar -xzf backup/var/var.tar.2025-01-01.gz -C /home/project/base/dir/
```
## 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
Execute the script initially. After that, modify the `backup/var/rotatemap_var.conf` to your need

View File

@ -5,45 +5,63 @@ Help()
# Display Help
echo "create a rotating backup of the var folder"
echo
echo "Syntax: varbackup [-h|s]"
echo "Syntax: varbackup [-h|s|v]"
echo "options:"
echo "h Print this Help."
echo "s Silent mode."
echo "h Print this Help"
echo "s Silent mode"
echo "v Verbose mode"
echo
}
while getopts ":hs" option; do
while getopts ":hsv" option; do
case $option in
h) # display Help
Help
exit;;
exit
;;
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
done
# main program
BASEDIR=$(dirname "$0")/../../..
BACKUPDIR=$BASEDIR/backup/var/
BASEDIR=$(readlink -f $(dirname "$0")/../../..)
BACKUPDIR=${BASEDIR}/backup/var/
CONFDIR=$BASEDIR/backup/
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[32mstarted\e[0m"
if [ ! -d "$BACKUPDIR" ]; then
[ -z ${isSilent} ] && echo "creating backup directory ${BACKUPDIR}"
mkdir -p "${BACKUPDIR}"
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[36mcreate backup directory ${BACKUPDIR}\e[0m"
mkdir -p ${verboseOption} "${BACKUPDIR}"
fi
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
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
fi
[ -z ${isSilent} ] && echo "pack var directory"
tar --numeric-owner --absolute-names -cf ${BACKUPDIR}new.tar ${BASEDIR}/var;
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[36mpack var directory\e[0m"
cd ${BASEDIR}
tar --numeric-owner ${verboseOption} -cf backup/var/new.tar 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
[[ -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
else
rm ${BACKUPDIR}new.tar
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[36mdiscard unchanged\e[0m"
rm ${verboseOption} ${BACKUPDIR}new.tar
fi
[ -z ${isSilent} ] && echo "finished"
[[ -z ${isSilent} || -v ${verboseOption} ]] && echo -e "\e[32mfinished\e[0m"
exit 0