fix most of the shellcheck quoted var issues

This commit is contained in:
Alex Kelly 2024-12-18 11:47:35 -05:00
parent a78d22643f
commit e19dba183c

View file

@ -17,12 +17,12 @@ while [ $# -gt 0 ]; do
esac
done
if [ -z $CONFIG_FILE_PATH ] ; then
SCRIPTPATH=$(cd ${0%/*} && pwd -P)
if [ -z "$CONFIG_FILE_PATH" ] ; then
SCRIPTPATH=$(cd "${0%/*}" && pwd -P)
CONFIG_FILE_PATH="${SCRIPTPATH}/pg_backup.config"
fi
if [ ! -r ${CONFIG_FILE_PATH} ] ; then
if [ ! -r "${CONFIG_FILE_PATH}" ] ; then
echo "Could not load config file from ${CONFIG_FILE_PATH}" 1>&2
exit 1
fi
@ -44,11 +44,11 @@ fi
### INITIALISE DEFAULTS ###
###########################
if [ ! $HOSTNAME ]; then
if [ ! "$HOSTNAME" ]; then
HOSTNAME="localhost"
fi;
if [ ! $USERNAME ]; then
if [ ! "$USERNAME" ]; then
USERNAME="postgres"
fi;
@ -64,7 +64,7 @@ function perform_backups()
echo "Making backup directory in $FINAL_BACKUP_DIR"
if ! mkdir -p $FINAL_BACKUP_DIR; then
if ! mkdir -p "$FINAL_BACKUP_DIR"; then
echo "Cannot create backup directory in $FINAL_BACKUP_DIR. Go and fix it!" 1>&2
exit 1;
fi;
@ -76,7 +76,7 @@ function perform_backups()
echo -e "\n\nPerforming globals backup"
echo -e "--------------------------------------------\n"
if [ $ENABLE_GLOBALS_BACKUPS = "yes" ]
if [ "$ENABLE_GLOBALS_BACKUPS" = "yes" ]
then
echo "Globals backup"
@ -173,10 +173,10 @@ function perform_backups()
DAY_OF_MONTH=`date +%d`
if [ $DAY_OF_MONTH -eq 1 ];
if [ "$DAY_OF_MONTH" -eq 1 ];
then
# Delete all expired monthly directories
find $BACKUP_DIR -maxdepth 1 -name "*-monthly" -exec rm -rf '{}' ';'
find "$BACKUP_DIR" -maxdepth 1 -name "*-monthly" -exec rm -rf '{}' ';'
perform_backups "-monthly"
@ -188,10 +188,10 @@ fi
DAY_OF_WEEK=`date +%u` #1-7 (Monday-Sunday)
EXPIRED_DAYS=`expr $((($WEEKS_TO_KEEP * 7) + 1))`
if [ $DAY_OF_WEEK = $DAY_OF_WEEK_TO_KEEP ];
if [ "$DAY_OF_WEEK" = "$DAY_OF_WEEK_TO_KEEP" ];
then
# Delete all expired weekly directories
find $BACKUP_DIR -maxdepth 1 -mtime +$EXPIRED_DAYS -name "*-weekly" -exec rm -rf '{}' ';'
find "$BACKUP_DIR" -maxdepth 1 -mtime +"$EXPIRED_DAYS" -name "*-weekly" -exec rm -rf '{}' ';'
perform_backups "-weekly"
@ -201,8 +201,7 @@ fi
# DAILY BACKUPS
# Delete daily backups 7 days old or more
find $BACKUP_DIR -maxdepth 1 -mtime +$DAYS_TO_KEEP -name "*-daily" -exec rm -rf '{}' ';'
find "$BACKUP_DIR" -maxdepth 1 -mtime +"$DAYS_TO_KEEP" -name "*-daily" -exec rm -rf '{}' ';'
perform_backups "-daily"
ln -nsf
ln -nsf $FINAL_BACKUP_DIR $BACKUP_DIR/latest
ln -nsf "$FINAL_BACKUP_DIR" "$BACKUP_DIR/latest"