Setting a MySQL Database Dump Cron Job in cPanel

  • Thread starter EmeraldHike
  • Start date
EmeraldHike

EmeraldHike

New Member
Joined
May 10, 2021
Messages
11
Reaction score
0
Points
1
  • #1
I know I've seen the instructions for doing this around the internet over the past few years, but I completely forget how to do it or where the instructions were. My goal is to save backups (database dumps) of my website's MySQL database to my hosting account's home directory. I obviously don't want this file publicly accessible. Also, since the database can get over 50MB, I'd like to zip it, or compress it before it saves to the home directory. I would like to run a cron job once per day and have the new file overwrite the old one. Every so often, I'll FTP in to the home directory and download the database for safe keeping (backup). Can anyone please give me the directions for setting up a compressed MySQL database dump cron job in cPanel?
 
15Katey

15Katey

New Member
Joined
May 10, 2021
Messages
11
Reaction score
0
Points
1
  • #2
For creating a cron job in general, you may view this post:

https://gaulard.com/forum/threads/25/

For creating a specific cron command that'll dump your database, compress it, and store it in a specific file, I can help with that. Be warned though, I've tried this command on various servers and it's only worked on some of them. Oddly enough, some cron commands only work with some servers. I am currently running a Linux server with cPanel, so if you've got the same, this might work for you. If not, contact your host and someone should be able to help. Cron commands are oftentimes easy for systems admins to put together.

To create your cron job, log into cPanel and access your Cron Job page. Then, set up the times and days of the week you'd like the job to run. Finally, the create the command, you can use something like this:

mysqldump --user=database_user --password='database_password' database_name | gzip > /home/yourhostingaccount/database_name.sql.gz

Obviously, you'd want to change out the "database_user," "password," database_name," and "yourhostingaccount" variable to your own. I just placed them in there to make things easier.

As you can see the command used gzip to compress the database and then saves it out in the user account of the home directory as an .sql.gz file. I think that's what you wanted.

For more instructions and ideas for creating a database dump cron command, check out these resources:

https://stackoverflow.com/questions/6578533/daily-database-backup-using-cron-job
https://www.a2hosting.com/kb/developer-corner/mysql/mysql-database-backups-using-cron-jobs
https://www.comentum.com/mysqldump-cron.html
https://blog.cpanel.com/how-to-back-up-and-restore-mysql-databases-in-cpanel/

That last link actually covers how to do backups and restores in cPanel. It does give cron command instructions though.
 
Last edited:
Setting a MySQL Database Dump Cron Job in cPanel was posted on 05-23-2021 by EmeraldHike in the Servers & Hosting forum.

Forum statistics

Threads
88
Messages
156
Members
17
Latest member
mandy cromarty
Looking for an all-around awesome forum? Check out IndyFor!
Top