From 7e1c698858eb336f3ff26b7fbf48332bb9b6eebf Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Sun, 26 Nov 2023 12:58:06 -0600 Subject: [PATCH] Decided to just give full path to btrfs util for each call due to the alias not working and the crontab not giving it enough of a PATH to know where it is --- do-daily-btrfs-snapshot.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/do-daily-btrfs-snapshot.sh b/do-daily-btrfs-snapshot.sh index 585bba4..be853a7 100755 --- a/do-daily-btrfs-snapshot.sh +++ b/do-daily-btrfs-snapshot.sh @@ -38,9 +38,6 @@ LOG_FILE=$LOG_DIR/$DATE.log ## The amount of backups that are allowed of each configured subvols LIMIT=5 -## Because cron fucks our env, and loading /etc/bashrc doesn't always fix it -alias btrfs='/usr/sbin/btrfs' - ## The subvols that we want to backup ### : declare -a SUBVOLS=( @@ -55,16 +52,22 @@ DATE_REGEX='[0-9]{4}-[0-9]{2}-[0-9]{2}' # BEGIN: Pre-Work Checks -## This will check to make sure that the log directory has been created, if not it will create it -[[ ! -d $LOG_DIR ]] && mkdir -p $LOG_DIR -## Setting up the script to direct all output to the log file for this snapshot session exec > $LOG_FILE +## This will check to make sure that the log directory has been created, if not it will create it +[[ ! -d $LOG_DIR ]] && { + mkdir -p $LOG_DIR + echo "$LOG_DIR did not exist. Creating" +} + +## Setting up the script to direct all output to the log file for this snapshot session + # END: Pre-Work Checks # BEGIN: Work +echo "Beginning backup at `date`" for SUBVOL_INFO in ${SUBVOLS[@]}; do ## Stripping the delemited info out of the subvol entry @@ -90,7 +93,7 @@ for SUBVOL_INFO in ${SUBVOLS[@]}; do if [[ ${#backups[@]} -ge $LIMIT ]]; then SNAPSHOT_PATH="$SUBVOL_BACKUP_DIR/${backups[0]}" echo "${#backups[@]} was found to be equal to or greater than $LIMIT. Deleting $SNAPSHOT_PATH." - btrfs subvol del "$SUBVOL_BACKUP_DIR/${backups[0]}" + /usr/sbin/btrfs subvol del "$SUBVOL_BACKUP_DIR/${backups[0]}" else break fi @@ -101,7 +104,8 @@ for SUBVOL_INFO in ${SUBVOLS[@]}; do SNAPSHOT=$SUBVOL_BACKUP_DIR/$DATE ## If the snapshot doesn't already exist, then create a new read-only snapshot - [[ ! -d $SNAPSHOT ]] && btrfs subvol snapshot -r $DIR $SNAPSHOT + [[ ! -d $SNAPSHOT ]] && /usr/sbin/btrfs subvol snapshot -r $DIR $SNAPSHOT done +echo "Finishing backup at `date`" # END: Work