Replace SQL db with another every hour

Operating System & Version
CentOS 7.9
cPanel & WHM Version
98.0.8

milo695

Registered
Aug 30, 2021
4
0
1
Croatia
cPanel Access Level
Root Administrator
Hi all,
How can I replace SQL database with another one via Cron every hour?

Context: I'm trying to create a Wordpress demo site and setup cron job to replace modified database with the original repeatedly.
If anyone has the command example and where to place original SQL db I'd really appreciate the help.
Thank you
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,496
1,009
313
cPanel Access Level
Root Administrator
Hey there! I believe this should be doable as long as the user has shell access enabled. This would let the user have access to mysql on the command line, allowing them to import the database from a cron.

I tested this on my end by doing the following:

-placed the original database.sql in the /home/username directory
-ensured the cPanel user has shell access

After that, I created the database and ensured there was a user that could access it. I was then able to run this command from a Bash script to update the database:

Code:
 mysql -u username_testuser -p PASSWORD-GOES-HERE username_testdb < original_db.sql
That Bash script would then just get called hourly by the cron job.

I would expect that to work just as well on your end, but let me know if you run into issues.
 
  • Like
Reactions: milo695

milo695

Registered
Aug 30, 2021
4
0
1
Croatia
cPanel Access Level
Root Administrator
Hey there! I believe this should be doable as long as the user has shell access enabled. This would let the user have access to mysql on the command line, allowing them to import the database from a cron.

I tested this on my end by doing the following:

-placed the original database.sql in the /home/username directory
-ensured the cPanel user has shell access

After that, I created the database and ensured there was a user that could access it. I was then able to run this command from a Bash script to update the database:

Code:
 mysql -u username_testuser -p PASSWORD-GOES-HERE username_testdb < original_db.sql
That Bash script would then just get called hourly by the cron job.

I would expect that to work just as well on your end, but let me know if you run into issues.
Thank you for this, but I only have Reseller account without the Shell access in this scenario, is there a way to pull this off somehow or should I contact Hosting company to implement this for me?