This shell script creates daily backups of all MySQL databases on macOS. Currently the script uses [email protected], installed by homebrew.
- Daily backups are kept for a week.
- Weekly backups are kept for a month.
- Monthly backups are kept for a year.
-
Make
mysqldump_cron.sh
executable:~: sudo chmod +x mysqldump_cron.sh
-
Create a symlink for
mysqldump_cron.sh
that is placed in/usr/local/bin
and that is namedmysqlbackup
~: ln -s /Users/USERNAME/PATH/TO/SCRIPT/mysqldump_cron.sh /usr/local/bin/mysqlbackup
-
Edit your Mac's crontab and have it execute
mysqlbackup
hourly. A backup will only be created once a day.env EDITOR=nano crontab -e
add the line
0 * * * * /usr/local/bin/mysqlbackup >> /Users/PATH/TO/LOGFILE/.shell-scripts/mysqlbackup.log 2>&1