Manual backups are error-prone and easily forgotten. Automating backups with shell scripts and schedulers (cron on Linux, Task Scheduler on Windows) ensures backups happen reliably every day.
A Robust Backup Script
A good backup script should: use a date-stamped filename, compress the output, keep only the last N backups to manage disk space, and log success or failure. Optionally, it uploads the backup to off-site storage (S3, Google Cloud Storage, etc.).
Scheduling with Cron
Add the script to crontab to run nightly. Use a MySQL option file (~/.my.cnf) to store credentials safely rather than embedding them in the script.
MySQL Option File (.my.cnf)
Store the database password in ~/.my.cnf with [client] section so you never have a password visible in scripts or process lists.