admin-scripts/backup.sh

64 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
################################################################################
# Backup Script
# -------------
#
# This script orchestrates and performs system backups with borg according to
# the environment variables in config/backup and .borgenv files per borg
# repository you wish to backup to. This script assumes two backups for each
# repository, splitting up the base operating system (debian) and the zfs array
# (zfs) which can be custom named in the config file.
#
# EXPECT THESE BACKUP SCRIPTS TO CHANGE IN THE NEAR FUTURE!
#
# Author: Robin Meier - robin@meier.si
################################################################################
# TODO: Check if borg installed
# Load configuration
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
set -o allexport
source ${script_dir}/config/backup > /dev/null 2>&1
set +o allexport
# Import logging functionality
logfile=${script_dir}/log/backup.log
log_identifier="BACKUP"
source ${script_dir}/functions/logging.sh
log "Backup Script Started"
# Run backup preparations
${script_dir}/backup_preparations.sh
# Check preparations exit code
prep_exit=$?
if [[ $prep_exit > 0 ]]; then
log_echo "Preparations failed with exit code $prep_exit"
exit $prep_exit
fi
# Run external disk backup if set
external_exit=0
if [[ -n $EXTERNAL_DISK_BACKUP_ENV_FILE ]]; then
${script_dir}/backup_external_disk.sh &>> $logfile
external_exit=$?
fi
if [[ $external_exit -gt 0 ]]; then
log_echo "External disk backup failed with exit code $external_exit"
fi
# Run remote disk backup if set
remote_exit=0
if [[ -n $EXTERNAL_DISK_BACKUP_ENV_FILE ]]; then
${script_dir}/backup_remote.sh &>> $logfile
remote_exit=$?
fi
if [[ $remote_exit -gt 0 ]]; then
log_echo "External disk backup failed with exit code $remote_exit"
fi
log "Backup Script Finished"