Automatic MySQL / PostgreSQL Backups with a Shell Script and Cron Job
We’ll cover backing things up on a custom schedule and restoring from a backup.
Hit the subscribe button to receive more videos like this!
—
Code:
https://gist.github.com/nickjj/00b07e522caee02e37951ec6de2a9c95
Timestamps:
0:00 — What we’ll be covering in this video
0:44 — Sendy is the app we’re backing up, which uses MySQL / MariaDB
1:44 — Using mysqldump to save a compressed version of the database backup
4:00 — Parsing out DB credentials from a file using grep, cut and sed
8:20 — Demonstrating how the backup script works when calling it manually
9:32 — Scheduling the backup to happen once a day with a cron job
12:13 — Creating a separate backup rotation cron job to delete old backups
14:20 — Going over how mtime works and how to set a custom time for testing
16:23 — Creating another script to restore your database
22:02 — Modifying things for PostgreSQL
22:51 — When disaster strikes it’s nice to have scripts to help restore things quickly
23:30 — Potentially modifying things to write to block storage or an S3 bucket
Reference links:
https://sendy.co/?ref=6L8Qf (affiliate link)
https://www.digitalocean.com/?refcode=0a14c0d916b3 (affiliate link and you get $100 in credits)
https://crontab.guru
—
Follow along?
Personal Website: https://nickjanetakis.com
Twitter: https://twitter.com/nickjanetakis
Comments are closed.