Automate MySQL Database Backup via Cronjob: Difference between revisions
Docs admin (talk | contribs) No edit summary |
Docs admin (talk | contribs) No edit summary |
||
Line 22: | Line 22: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br><br> | <br><br> | ||
For <syntaxhighlight lang="bash"> | |||
<syntaxhighlight lang="bash"> | |||
date=`date -I`; /usr/bin/mysqldump -umyusername -pmypassword mydatabase > /home/example/mydatabase_$date.sql | date=`date -I`; /usr/bin/mysqldump -umyusername -pmypassword mydatabase > /home/example/mydatabase_$date.sql | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 11:18, 6 June 2018
Automating a MySQL Database backup in cPanel is a two step process.
Create the Backup cron in cPanel
1) Log into your cPanel
2) Go to Advanced -> Cron Jobs
3) Enter the email you wish to email the results of the cron job to.
4) Scroll down a bit, and either select a common setting (Once a day, once a week, etc) from the drop down. or enter a custom entry for days, weeks, months, etc.
5) For the command to run, enter the following command. Replace CPANELUSERNAME with your cpanel username. Replace DBUSERNAME with your database username. Replace PASSWORD with the database password, and CPANELUSERNAME with your cPanel username.
<syntaxhighlight lang="bash">
date=`date -I`; /usr/bin/mysqldump -uDBUSERNAME -pPASSWORD dbname > /home/CPANELUSERNAME/dbname$date.sql
</syntaxhighlight>
For <syntaxhighlight lang="bash">
date=`date -I`; /usr/bin/mysqldump -umyusername -pmypassword mydatabase > /home/example/mydatabase_$date.sql
</syntaxhighlight>
This will create a sql file in your /home/cpanelusername directory with a name similar to mydatabase_20180101.sql.