#!/bin/bash # Flags based on # https://borgbackup.readthedocs.io/en/stable/quickstart.html if [ -z "$1" ]; then echo "Must specify backup host" exit 1 fi BORG="/opt/borg/bin/borg" # Setting this, so the repo does not need to be given on the commandline: export BORG_REPO="ssh://{{ borg_username}}@${1}/opt/backups/{{ borg_username }}/backup" # some helpers and error handling: info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; } trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM info "Starting backup" # This avoids UI prompts when first accessing the remote repository export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=1 # Backup the most important directories into an archive named after # the machine this script is currently running on: ${BORG} create \ --verbose \ --filter AME \ --list \ --stats \ --show-rc \ --compression lz4 \ --exclude-caches \ {% for item in borg_backup_excludes + borg_backup_excludes_extra -%} --exclude '{{ item }}' \ {% endfor -%} \ ::'{hostname}-{now}' \ {% for item in borg_backup_dirs + borg_backup_dirs_extra -%} {{ item }} {{ '\\' if not loop.last }} {% endfor -%} backup_exit=$? if [ ${backup_exit} -eq 0 ]; then info "Backup finished successfully" else info "Backup finished with errors" fi exit ${backup_exit}