Updated all scripts

release/full-rewrite
capntack 6 months ago
parent 226dec6163
commit 5069f24868

@ -33,7 +33,7 @@ if [ $NTFY_NOTIFICATIONS = 'yes' ]; then
-H "Filename: backupLog_"${DATETIME}".log" \ -H "Filename: backupLog_"${DATETIME}".log" \
-H prio:high \ -H prio:high \
-H "Title: Backup Failed on ${HOSTNAME}" \ -H "Title: Backup Failed on ${HOSTNAME}" \
ntfyUser:ntfyPassword@ntfyDomain/ntfyTopic "${NTFY_URL}"
} }
fi fi
@ -47,28 +47,28 @@ if [ $RSYNC_BACKUP = 'yes' ]; then
fi fi
# If selected, run a local restic backup # If selected, run a local restic backup
if [ $LOCAL_RESTIC_BACKUP = 'yes' ]; then if [ $LAN_RESTIC_BACKUP = 'yes' ]; then
. "${SCRIPT_DIR}"/rsync.sh . "${SCRIPT_DIR}"/restic.sh
fi fi
# If selected, run a forget, prune, and check on the local restic repo after a local restic backup # If selected, run a forget, prune, and check on the local restic repo after a local restic backup
if [ $LOCAL_RESTIC_BACKUP_CLEAN = 'yes' ]; then if [ $LAN_RESTIC_CLEAN = 'yes' ]; then
. "${SCRIPT_DIR}"/rsync.sh . "${SCRIPT_DIR}"/resticClean.sh
fi fi
# If selected, run a forget, prune, and check on the local restic repo before a remote restic backup # Overwrite LAN restic variables with the AWS restic variables
if [ $REMOTE_RESTIC_BACKUP_CLEAN_LOCAL = 'yes' ]; then if [ $LAN_AND_AWS_RESTIC = 'yes' ]; then
. "${SCRIPT_DIR}"/rsync.sh . "${SCRIPT_DIR}"/variablesAWS.sh
fi fi
# If selected, run a remote restic backup # If selected, run a remote restic backup
if [ $REMOTE_RESTIC_BACKUP = 'yes' ]; then if [ $AWS_RESTIC_BACKUP = 'yes' ]; then
. "${SCRIPT_DIR}"/rsync.sh . "${SCRIPT_DIR}"/restic.sh
fi fi
# If selected, run a forget, prune, and check on the remote restic repo after a remote restic backup # If selected, run a forget, prune, and check on the remote restic repo after a remote restic backup
if [ $REMOTE_RESTIC_BACKUP_CLEAN = 'yes' ]; then if [ $AWS_RESTIC_CLEAN = 'yes' ]; then
. "${SCRIPT_DIR}"/rsync.sh . "${SCRIPT_DIR}"/resticClean.sh
fi fi
############## ##############
@ -89,5 +89,5 @@ if [ $NTFY_NOTIFICATIONS = 'yes' ]; then
-H "Filename: backupLog_"${DATETIME}".log" \ -H "Filename: backupLog_"${DATETIME}".log" \
-H prio:low \ -H prio:low \
-H "Title: Backup Succeeded on ${HOSTNAME}" \ -H "Title: Backup Succeeded on ${HOSTNAME}" \
ntfyUser:ntfyPassword@ntfyDomain/ntfyTopic "${NTFY_URL}"
fi fi

@ -3,18 +3,22 @@
# Run retention policy # Run retention policy
if [ $RESTIC_CALENDAR_RETENTION = 'yes' ]; then if [ $RESTIC_CALENDAR_RETENTION = 'yes' ]; then
restic unlock
restic forget --prune --verbose \ restic forget --prune --verbose \
--tag "${RESTIC_TAG_01}","${RESTIC_TAG_02}" \ --tag "${RESTIC_TAG_01}","${RESTIC_TAG_02}" \
--keep-daily "${RESTIC_RETENTION_DAYS}" \ --keep-daily "${RESTIC_RETENTION_DAYS}" \
--keep-weekly "${RESTIC_RETENTION_WEEKS}" \ --keep-weekly "${RESTIC_RETENTION_WEEKS}" \
--keep-monthly "${RESTIC_RETENTION_MONTHS}" \ --keep-monthly "${RESTIC_RETENTION_MONTHS}" \
--keep-yearly "${RESTIC_RETENTION_YEARS}" --keep-yearly "${RESTIC_RETENTION_YEARS}"
restic unlock
fi fi
if [ $RESTIC_CALENDAR_RETENTION = 'no' ]; then if [ $RESTIC_CALENDAR_RETENTION = 'no' ]; then
restic unlock
restic forget --prune --verbose \ restic forget --prune --verbose \
--tag "${RESTIC_TAG_01}","${RESTIC_TAG_02}" \ --tag "${RESTIC_TAG_01}","${RESTIC_TAG_02}" \
--keep-last "${RESTIC_RETENTION_KEEP_LAST}" --keep-last "${RESTIC_RETENTION_KEEP_LAST}"
restic unlock
fi fi
# Verify the repo's integrity # Verify the repo's integrity

@ -4,4 +4,6 @@ restic backup --verbose \
--tag "${RESTIC_TAG_01}" --tag "${RESTIC_TAG_02}" \ --tag "${RESTIC_TAG_01}" --tag "${RESTIC_TAG_02}" \
--exclude-caches \ --exclude-caches \
--exclude-file="${RESTIC_EXCLUDES}" \ --exclude-file="${RESTIC_EXCLUDES}" \
--exclude "${SCRIPT_DIR}"/variables.sh \
--exclude "${SCRIPT_DIR}"/variablesAWS.sh \
"${RESTIC_SOURCE}" "${RESTIC_SOURCE}"

@ -0,0 +1,34 @@
#!/bin/bash
########################
# AWS RESTIC REPO VARS #
########################
## Only set these if LAN_AND_AWS_RESTIC is set to 'yes' in variables.sh
## Also ensure the restic vars in that file or for the LAN restic
## Only uncomment and set this var if you want it different from variables.sh
# readonly RESTIC_CALENDAR_RETENTION='yes'
## Set these for all restic configurations
export RESTIC_REPOSITORY='/path/to/repo'
export AWS_ACCESS_KEY_ID='KEY-ID'
export AWS_SECRET_ACCESS_KEY='SECRET-KEY'
export RESTIC_PASSWORD='PASSWORD'
readonly RESTIC_SOURCE='/path/to/dir/to/backup'
## RESTIC_CALENDAR_RETENTION must be set to 'yes' for these
readonly RESTIC_RETENTION_DAYS='0'
readonly RESTIC_RETENTION_WEEKS='4'
readonly RESTIC_RETENTION_MONTHS='0'
readonly RESTIC_RETENTION_YEARS='0'
## RESTIC_CALENDAR_RETENTION must be set to 'no' for this
# readonly RESTIC_RETENTION_KEEP_LAST='2'
## Recommendation is to leave the first tag be, and configure the second
readonly RESTIC_TAG_01="${HOSTNAME}"
readonly RESTIC_TAG_02='TAG-02'
## Leave this var be
readonly RESTIC_EXCLUDES="${SCRIPT_DIR}/resticExcludes"

@ -4,39 +4,63 @@
# FUNCTION SWITCHES # # FUNCTION SWITCHES #
##################### #####################
# For any function that you want to run, change from "no" to "yes" ## For any function that you want to run, change from "no" to "yes"
## For debugging the script
readonly DEBUG='no' readonly DEBUG='no'
## For use with NTFY.
## If set 'yes' will need to set NTFY_URL further below
readonly NTFY_NOTIFICATIONS='no' readonly NTFY_NOTIFICATIONS='no'
## For running the rsync script.
## Will ened to set the rsync vars further below
readonly RSYNC_BACKUP='no' readonly RSYNC_BACKUP='no'
readonly LOCAL_RESTIC_BACKUP='no'
readonly LOCAL_RESTIC_BACKUP_CLEAN='no' ## For running the restic script.
readonly REMOTE_RESTIC_BACKUP_CLEAN_LOCAL='no' readonly LAN_RESTIC_BACKUP='no'
readonly REMOTE_RESTIC_BACKUP='no' readonly LAN_RESTIC_CLEAN='no'
readonly REMOTE_RESTIC_BACKUP_CLEAN='no' readonly AWS_RESTIC_BACKUP='no'
# Set the below 'no' if using keep last instead readonly AWS_RESTIC_CLEAN='no'
## Set to 'yes' if running a LAN_RESTIC_CLEAN prior to an AWS_RESTIC_BACKUP of the LAN repo
## If set to 'yes' set the restic vars further below for the LAN repo
## And set the AWS restic repo vars in the variables-aws.sh file
## restic retention vars set in this file will be for LAN, variables-aws.sh will have the AWS retention
## Also leave the RESTIC_TAGs and RESTIC_EXCLUDES vars commented out in this file
readonly LAN_AND_AWS_RESTIC='no'
## Set to 'no' if using RESTIC_RETENTION_KEEP_LAST further below
readonly RESTIC_CALENDAR_RETENTION='yes' readonly RESTIC_CALENDAR_RETENTION='yes'
############################ ############################
# LOGGING & ERROR HANDLING # # LOGGING & ERROR HANDLING #
############################ ############################
# Ensure you set the SCRIPT_DIR variable correctly as the error handling will not catch it ## Leave these vars be
# Change the LOG_RETENTION if you wish for more or less. readonly LOG_DIR="${SCRIPT_DIR}/logs"
readonly LOG_DIR="${SCRIPT_DIR}/backupLogs"
readonly DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')" readonly DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')"
readonly BACKUP_LOG="${LOG_DIR}/backupLog_"${DATETIME}".log" readonly BACKUP_LOG="${LOG_DIR}/"${DATETIME}"_backup.log"
readonly LOG_RETENTION="14"
## Adjust to your preferred retention
readonly LOG_RETENTION='30'
## If using, must set NTFY_NOTIFICATIONS further above to 'yes'
# readonly NTFY_URL='user:password@ntfy.tld/topic'
################ ################
# RSYNC SCRIPT # # RSYNC SCRIPT #
################ ################
## Configure variables from here... ## Only uncomment and set these if RSYNC_BACKUP further above is set to 'yes'
# readonly RSYNC_SOURCE="/path/to/dir/to/backup"
# readonly RSYNC_DEST="/path/to/dir/to/backup/to" ## Set these vars
# readonly RSYNC_SOURCE='/path/to/dir/to/backup'
# readonly RSYNC_DEST='/path/to/dir/to/backup/to'
# readonly RSYNC_RETENTION_DAYS='7'
## Leave these vars be
# readonly RSYNC_MANIFEST="${SCRIPT_DIR}/rsyncManifest" # readonly RSYNC_MANIFEST="${SCRIPT_DIR}/rsyncManifest"
# readonly RSYNC_RETENTION_DAYS="7"
## ...to here
# readonly RSYNC_DEST_PATH="${RSYNC_DEST}/${DATETIME}" # readonly RSYNC_DEST_PATH="${RSYNC_DEST}/${DATETIME}"
# readonly RSYNC_LATEST_LINK="${RSYNC_DEST}/latest" # readonly RSYNC_LATEST_LINK="${RSYNC_DEST}/latest"
@ -44,19 +68,29 @@ readonly LOG_RETENTION="14"
# RESTIC SCRIPT # # RESTIC SCRIPT #
################# #################
## Only use the following two AWS vars if backing up to a compatible repo ## Only uncomment and set these if the relevant RESTIC vars further above are set to 'yes'
# export AWS_ACCESS_KEY_ID="KEY-IID"
# export AWS_SECRET_ACCESS_KEY="SECRET-KEY" ## Only set these if backing up to a compatible repo
## Set all the remaining variables except for the last # export AWS_ACCESS_KEY_ID='KEY-ID'
# export RESTIC_PASSWORD="REPOSITORY-PASSWORD" # export AWS_SECRET_ACCESS_KEY='SECRET-KEY'
# export RESTIC_REPOSITORY="PATH-TO-REPOSITORY"
# readonly RESTIC_SOURCE="/path/to/dir/to/backup" ## Set these for all restic configurations
# readonly RESTIC_RETENTION_DAYS="7" # export RESTIC_REPOSITORY='/path/to/repo'
# readonly RESTIC_RETENTION_WEEKS="4" # export RESTIC_PASSWORD='PASSWORD'
# readonly RESTIC_RETENTION_MONTHS="6" # readonly RESTIC_SOURCE='/path/to/dir/to/backup'
# readonly RESTIC_RETENTION_YEARS="1"
## If you prefer a keep last retention policy, comment out the above 4 and uncomment the below and configure ## RESTIC_CALENDAR_RETENTION must be set to 'yes' for these
# readonly RESTIC_RETENTION_KEEP_LAST="2" # readonly RESTIC_RETENTION_DAYS='3'
# readonly RESTIC_RETENTION_WEEKS='1'
# readonly RESTIC_RETENTION_MONTHS='1'
# readonly RESTIC_RETENTION_YEARS='1'
## RESTIC_CALENDAR_RETENTION must be set to 'no' for this
# readonly RESTIC_RETENTION_KEEP_LAST='2'
## Recommendation is to leave the first tag be, and configure the second
# readonly RESTIC_TAG_01="${HOSTNAME}" # readonly RESTIC_TAG_01="${HOSTNAME}"
# readonly RESTIC_TAG_02="TAG-02" # readonly RESTIC_TAG_02='TAG-02'
## Leave this var be
# readonly RESTIC_EXCLUDES="${SCRIPT_DIR}/resticExcludes" # readonly RESTIC_EXCLUDES="${SCRIPT_DIR}/resticExcludes"
Loading…
Cancel
Save