Difference between revisions of "Automate MySQL Database Backup via Cronjob"

From Acenet Knowledgebase
Jump to: navigation, search
Line 2: Line 2:
  
 
==Create the cron entry in cPanel==
 
==Create the cron entry in cPanel==
{{note|You will need to know your Database Username and Database Password in order to configure the backup.}}
+
<br>
 
+
{{note|You will need to know your Database username and database password in order to configure the backup.}}
 +
<br>
 
1) Log into your cPanel
 
1) Log into your cPanel
 
+
<br>
 
2) Go to Advanced -> Cron Jobs
 
2) Go to Advanced -> Cron Jobs
 
+
<br>
 
3) Enter the email you wish to email the results of the cron job to.
 
3) Enter the email you wish to email the results of the cron job to.
 
+
<br>
 
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.
 
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.
 
+
<br>
 
5) For the command to run, enter the following:
 
5) For the command to run, enter the following:
 
+
<br>
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
date=`date -I`; /usr/bin/mysqldump -uDBUSERNAME -pPASSWORD dbname > /home/CPANELUSERNAME/FILE_NAME_HOME_DIRECTORY$date.sql
 
date=`date -I`; /usr/bin/mysqldump -uDBUSERNAME -pPASSWORD dbname > /home/CPANELUSERNAME/FILE_NAME_HOME_DIRECTORY$date.sql
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
<br><br>
 +
Replace CPANELUSERNAME with your cpanel username.  Replace DBUSERNAME with your database username.  Replace PASSWORD with the database password, and CPANELUSERNAME with your cPanel username.
 +
<br><br>
 +
As an example, cPanel user is example, Database username is myusername, database name is mydatabase, password is mypassword:
 +
<syntaxhighlight lang="bash">
 +
date=`date -I`; /usr/bin/mysqldump -umyusername -pmypassword mydatabase > /home/example/FILE_NAME_HOME_DIRECTORY$date.sql
 +
</syntaxhighlight>
 +
 +
 +
  
 
==Configure the Log rotation==
 
==Configure the Log rotation==

Revision as of 16:06, 6 June 2018

Automating a MySQL Database backup in cPanel is a two step process.

Create the cron entry in cPanel


You will need to know your Database username and database password in order to configure the backup.


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:

date=`date -I`; /usr/bin/mysqldump -uDBUSERNAME -pPASSWORD dbname > /home/CPANELUSERNAME/FILE_NAME_HOME_DIRECTORY$date.sql



Replace CPANELUSERNAME with your cpanel username. Replace DBUSERNAME with your database username. Replace PASSWORD with the database password, and CPANELUSERNAME with your cPanel username.

As an example, cPanel user is example, Database username is myusername, database name is mydatabase, password is mypassword:

date=`date -I`; /usr/bin/mysqldump -umyusername -pmypassword mydatabase > /home/example/FILE_NAME_HOME_DIRECTORY$date.sql



Configure the Log rotation