backup-mariadb.sh 1.0 KB

123456789101112131415161718
  1. #!/bin/bash
  2. #Backup a MariaDB database with a specific name and folder location then check that the output file is large enough.
  3. #Here we pass in params like the database name and MySQL backup folder from the Makefile.
  4. db=$2
  5. mkdir -p $1
  6. chmod -R 777 $1
  7. filename=$(date "+%Y%m%d-%H%M-%Z")-$db.zip
  8. email="openrsc.emailer@gmail.com";
  9. discordwebhook=$(cat Deployment_Scripts/.discordstaffmonitorwebhook); #We are in the root core directory, not Deployment_Scripts, so we must specify Deployment_Scripts.
  10. docker exec mariadb mysqldump -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} $db --single-transaction --quick --lock-tables=false | zip > $1/$filename
  11. size=$(stat --printf="%s" $1/$filename);
  12. if [[ $size -lt 100000 && $db != "laravel" ]]; then
  13. warning="Warning: OpenRSC $db DB backup file $filename is too small. Size is: $size";
  14. mail -s "OpenRSC $db DB backup size warning" $email <<< "$warning";
  15. curl -H "Content-Type: application/json" \
  16. -X POST \
  17. -d "{\"content\": \"$warning\"}" $discordwebhook
  18. fi