Taking a snapshot/backup of WordPress from the command line on a Plesk server

I quite regularly need to take quick backups of a WordPress installation while working on a Plesk server.

Here’s a script I created that will dump the DB as well as backup the WordPress directory where the site files are in. The concept is easy, execution was a little more complicated since Plesk can now store a secondary domain’s root within the filesystem path of it’s master subscriptions domain.

How it works

The script will query the psa database for the domain id of a supplied domain. Next it will get the www root of the domain using the domain id. It will then look for wp-config.php in that directory in case your WordPress install resides in it’s own directory. It will then grab the DB name from wp-config.php and use that to dump the right DB.

Assumptions made

  • /root/wpsnapshots will be used to store your snapshots.
  • There is only 1 WordPress install in your wwwroot directory.

How to use it

./wpsnapshot.sh domainname.com

That’s all there is to it. The script will figure out where WordPress is installed and which DB it’s using.

To Do

Making it handle multiple WordPress directories.

Feedback would be appreciated.

Enjoy!

Download script

Leave a Comment

Your email address will not be published.

Scroll to Top