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

Export Mailman lists without SSH access

Mailman is a great mailing list manager. It’s a shame it doesn’t provide a way for you to export Member lists within the Mailman interface itself. Sure if you had SSH access you could do this quite easily. But most web hosts won’t provide you with SSH access.

So what do we do?

With the help of the Linux or Mac command line, this task becomes less tedious.

  1. Log into the Mailman interface of your source host.
  2. Go to the Member list and start with A.
  3. Starting from the bottom of the list (simply because it’s easier to select from the end) highlight all email addresses upwards. You’ll also highlight the rightmost column but don’t worry about that, it won’t show in the paste.
  4. On the command line, create a new file.
  5. Paste the contents of the clipboard into the file. There’ll be lots of blank lines mixed in with Tabs. Once again don’t worry.
  6. Rinse and repeat for the rest of the letters.
  7. Save the contents of the file and exit the editor.
  8. Run grep against the file with: grep -v ‘ ‘ <filename> | grep -v ‘^$’ | grep -v -P ‘\t’ | sort > thelist

You now have a file named “thelist” with the list of Members stripped of blank lines and tabs, ready to be imported the target Mailman instance!

Plesk PHP FastCGI and Safe Mode

Updated 06/09/2011

Trying to run a PHP site in FastCGI mode and wondering why Safe Mode won’t turn off even though its unticked in the panel? Yeah, it had me tearing my hair out too.

Turns out that when running a site in PHP FastCGI mode, the Safe Mode setting in Plesk will NOT affect wether Safe Mode is on or off. In this mode, the Safe Mode setting is derived from the global php.ini.

Here’s what it says in the Plesk 10 doco:

Note: When PHP is operating in CGI or FastCGI modes, PHP settings are taken from the global php.ini file, and PHP safe mode cannot be switched off by means of security policy settings. If your customers want to use applications that require PHP safe mode to be switched off, and you decide to switch it off, then you need to modify the php.ini file located in /etc/directory on Linux platforms, and the following directory on Windows platforms:
%plesk_dir%\Additional\PHP and %plesk_dir%\Additional\PleskPHP5

Who’d have thought to look in the Plesk manuals :)

Update: Plesk 10.3 features custom php.ini settings per subscription.