MySQL dumps from a cron task
Create a cron task that generates a dump file from a MySQL database.
Bash file
This bash function creates a dump file from a database with a timesamp.
#!/bin/bash create_dump () { TIME=$(date '+%Y-%m-%d_%H-%M-%S') /usr/bin/mysqldump --single-transaction -u $1 -p$2 -h localhost --all-databases > /dumps/$3-$TIME.sql }
Call the function with the database user, database password and the output filename (without timestamp) on parameters.
create_dump db_user db_password file_name
Crontab
Add a cron task that execute the script. This exemple will create a dump file every sunday at 19h.
0 0 19 * 0 /crons/dumps.sh >> /logs/dumps.log 2>&1