How can I have the MySQL backup emailed automatically?
If it is not too large, you can have it emailed to yourself automatically via the cron jobs option in DirectAdmin.
- Open DirectAdmin via My Products (the 'DirectAdmin' button) and log in
- Choose Cron Jobs
- Enter for example 45 for the minute, for example 5 for the hour, and asterisks for the rest so that it runs every day.
- Create 2 cron jobs. Have the 2nd cron job start an hour later, for example
- Cron job 1:
- mysqldump --routines -u <databasegebruikersnaam> -p'<wachtwoord>' <databasenaam> > ${HOME}dbbackup.sql
- Replace <databasegebruikersnaam> with the username of the database. You can find it via DirectAdmin by clicking on the database
- <wachtwoord> The password of the database user in question. If you do not know it, simply create a new user for that database.
- <databasenaam> The full database name, so in the format user_name
- You can also change the name dbbackup.sql to a different name if you want to back up multiple databases.
- mysqldump --routines -u <databasegebruikersnaam> -p'<wachtwoord>' <databasenaam> > ${HOME}dbbackup.sql
- Cron job 2:
- For the command, enter:
- /usr/bin/mutt -s "backup" -a /home/<user>/dbbackup.sql -- <mailadres> < /dev/null
- Replace <sqlnaam> with the name of the database
- Replace <user> with the username you use to log in to DirectAdmin
- Replace <mailadres> with the email address the SQL file should be sent to.
- You can replace the text Backup with your own text (this is the subject of the email)
- For the command, enter:
- Then choose Add.
ATTENTION: Make sure you fill in the minute and day, so NO asterisks. Running it every minute could cause major problems.
Was this article helpful?
