add new env vars and error handling

This commit is contained in:
Audrey Jensen 2025-04-03 08:25:08 -05:00
parent 20b9100624
commit ff55c5e35e
Signed by: audrey
SSH Key Fingerprint: SHA256:k+6b1AGMt7Q6374OfeAXUFNe0eFpsUt6eV4biffF06U

View File

@ -1,14 +1,14 @@
#!/bin/bash #!/bin/bash
echo "Beginning Hot-Backup of database..." echo "Beginning Hot-Backup of database..." >> /var/log/cron.log
# Check if MYSQL_HOST is defined # Check if MYSQL_HOST is defined
if [ -z "$MYSQL_HOST" ]; then if [ -z "$MYSQL_HOST" ]; then
echo "Error: MYSQL_HOST is not defined." echo "Error: MYSQL_HOST is not defined." >> /var/log/cron.log
exit 1 exit 1
fi fi
# Check if MYSQL_ROOT_PASS is defined # Check if MYSQL_ROOT_PASS is defined
if [ -z "$MYSQL_ROOT_PASS" ]; then if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
echo "Error: MYSQL_ROOT_PASS is not defined." echo "Error: MYSQL_ROOT_PASS is not defined." >> /var/log/cron.log
exit 1 exit 1
fi fi
# Check if BACKUP_NAME is defined # Check if BACKUP_NAME is defined
@ -24,4 +24,5 @@ else
FILENAME="$BACKUP_NAME.sql" FILENAME="$BACKUP_NAME.sql"
fi fi
mysqldump -u root --password=$MYSQL_ROOT_PASS --host=$MYSQL_HOST --all-databases > "/backup/$FILENAME.sql" mysqldump -u root --password=$MYSQL_ROOT_PASSWORD --host=$MYSQL_HOST --all-databases > "/backup/$FILENAME"
echo "MySQL backup complete" >> /var/log/cron.log