About Me

My photo
India
Hey there, lovely people! I'm Hemant Menaria, and I'm passionate about programming. Having completed my MCA in 2011, I've delved into the world of coding with fervor. I believe in sharing knowledge, making complex concepts easy to grasp for everyone. JAVA, PHP, and ANDROID hold a special place in my heart, and I spend most of my time immersed in them. Currently, I'm deeply engaged in API/Webservice frameworks and crafting Hybrid mobile applications to enhance flexibility in the digital realm. If you ever find yourself stuck with a programming challenge, feel free to reach out to me at +91-8955499900 or drop me a line at hemantmenaria008@gmail.com. I'm always eager to help fellow enthusiasts navigate the intricacies of coding!

Wednesday, July 19, 2017

Cpanel Cron job for mysql datbase backup


Cron Job: Cron Job is a time base task which will execute on a fixed time or interval (repeat after a time).

How to create a cron job in cpanel to take database backup. 

Now Follow the Steps:

Step 1- First of all Create a file on your computer system and paste below code into file 

[client]
user = yourCpanelUserName
password = "yourCpanelPassword"
host = localhost

save above file with .my.cnf and upload it to your server directory (like /home/Your_Domain_Directory/)

 Step 2- Create a folder for backup with name of  db_backup on server at same place ( /home/Your_Domain_Directory/)

Step 3- 
1 -Go to Cpanel main page
2- Click on Cron Job
3- Enter email for notification regarding cron job.
4- Select Job Setting  means frequency of your task /job execution.
5- Paste below line in command text box:

mysqldump --all-databases  > /home/Your_Domain_Directory/db_backup/All_DB_Backup_$(date +'\%d-\%m-\%Y').sql

The above code will generate backup for your all databases in /home/Your_Domain_Directory/db_backup directory with the name of "All_DB_Backup_TodayDate".  so if you set daily backup policy then it will create a backup file with current date without overriding the same file.

if you want to take backup of a particular database then at the place of --all-database you can write the name of the particular database.

Step 4 - Finally click on Add Crone Job button to save it.

Step 5 - Go to the folder /home/Your_Domain_Directory/db_backup  to check your datbase backup.


No comments:

Post a Comment