Files
disaster_recovery/make_backup.sh

44 lines
997 B
Bash
Executable File

#!/usr/bin/env bash
## Source backup.env file for settings and secrets.
## it is possible to pass a filename as .env file.
## Passing a file makes it possible to have several .env files for different backups and one "work script".
if [[ -z "$1" ]]; then
source backup.env
else
source $1
fi
## Setup that everything is written to log
exec > >(tee -i ${LOGFILE})
exec 2>&1
## Checks that a few important thins is set.
## In case a invalid path/file is passed.
if [[ -z $REPOSITORY ]]; then
echo "No \$REPOSITORY set, cannot make backup. \nDid you pass a valid .env file?"
exit 4
fi
if [[ -z $BACKUP_NAME ]]; then
echo "No \$BACKUP_NAME set, cannot make backup. \nDid you pass valid .env file?"
exit 5
fi
echo "######## Backup started at $(date) ########"
borg create -v --stats \
--exclude-from $BACKUP_EXCLUDE \
$REPOSITORY::$BACKUP_NAME \
$BACKUP_PATH
echo "######### Backup Finished $(date) #########"