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

This commit is contained in:
Tristan Ancelet 2023-11-26 12:58:06 -06:00
parent 97b5db543d
commit 7e1c698858

View File

@ -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
### <actual-directory>:<name-of-backup-dir>
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