Skip to content

Instantly share code, notes, and snippets.

@kfelter
Created August 29, 2023 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kfelter/2289fd48533ffc4c7d97bfaba77d3b7d to your computer and use it in GitHub Desktop.
Save kfelter/2289fd48533ffc4c7d97bfaba77d3b7d to your computer and use it in GitHub Desktop.
#!/bin/bash
FNAME="$(date +"%Y_%m_%d_%H_%M_%S").dump"
/opt/homebrew/bin/mysqldump --port=3306 --host=127.0.0.1 \
-u $your_username -p$your_password $your_database_name > $FNAME
gzip $FNAME
# Then, you can add a cron job to run this script every day at 3am:
# 0 3 * * * /path/to/backup-db.sh
# restore db
# gzcat BACKUP_FILE_GZIP | mysql --port=3306 --host=127.0.0.1 -u $your_username -p $your_database_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment