WordPress SQL Database Backup and Optimization Without Plugins

In my pursuit for optimization without utilizing resource-hungry plugins, I’ve compiled the following PHP snippets to run as cron jobs on my Bluehost account.

Daily backup – requires the database name and its associated username/password. You’ll need a “backup” folder under public_html (or modify the save path accordingly in the code). Executing the script will create a GZipped backup archive of the specified database. I run this daily and save the file as the day of the week. Replace DB_USERNAME, DB_PASSWORD, and DB_NAME in the following script.

 ~/public_html/backup/$day.sql.gz";
system($command);?>

Note that there is no space between the “-p” flag and DB_PASSWORD.

Database optimization – optimizes all the databases linked to a username/password combination. Replace DB_USERNAME and DB_PASSWORD in the following script.

I saved the scripts above as two different PHP files which I run through a Cron Job task (under CPanel).

/ramdisk/bin/php5 -q /path/to/your/script.php

Leave questions below!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Try EchoTools - my free, iOS ultrasonography reference application!

Latest Articles