Wordpress

Backup your Wordpress database, code and files

Remember to create an SSH keypair and to deploy the public key on the remote host(s). See here for instructions on installation and public key deployment.

For the impatient

Add this configuration to your Sheepfile and replace the hostname, SSH user, directory path, database name and credentials with the appropriate values. If you prefer a step-by-step explanation, skip to the next section.

host "wordpress", hostname: "wordpress.example.com", private_key: "~/.ssh/electric_sheep_rsa"

job "wordpress-files" do
  schedule "daily", at: "00:00"
  resource "directory", path: "/var/www", host: "wordpress"
  remotely as: "root" do
    tar_gz
  end
  move to: "localhost", using: "scp", as: "root"
end

job "wordpress-db" do
  schedule "daily", at: "00:00"
  resource "database", name: "wordpress", host: "wordpress"
  remotely as: "root" do
    mysql_dump user: "db-username", password: "db-password"
    tar_gz delete_source: true
  end
  move to: "localhost", using: "scp", as: "root"
end

Step by step configuration

Declare the remote host(s)

Add an host entry to your Sheepfile and point it to your server's hostname or IP address, then indicate the SSH private key that will be used to access the remote node.

If the Wordpress database is hosted on a separated server node, declare an additional host entry in the Sheepfile.

host "wordpress", hostname: "wordpress.example.com", private_key: "~/.ssh/electric_sheep_rsa"

Backup the Wordpress files

Declare a job and an initial directory resource pointing to Wordpress' root directory (here, /var/www). Starting from here, there are a lot of possible backup strategies. In the following example, we remotely build a .tar.gz archive of the directory and move it to the localhost.

job "wordpress-files" do
  resource "directory", path: "/var/www", host: "wordpress"
  remotely as: "root" do
    tar_gz
  end
  move to: "localhost", using: "scp", as: "root"
end

Backup the Wordpress database

Declare another job with an initial database resource specifying your database name. We then ask ES.io to create an SQL dump of the database, place it in a .tar.gz archive, then move it to the localhost.

job "wordpress-db" do
  resource "database", name: "wordpress", host: "wordpress"
  remotely as: "root" do
    mysql_dump user: "db-username", password: "db-password"
    tar_gz delete_source: true
  end
  move to: "localhost", using: "scp", as: "root"
end

The MySQL credentials used by Wordpress can usually been found in the wp-config.php of your Wordpress installation.

Schedule your backups

You can choose a different scheduling for each of the jobs in your Sheepfile using the schedule verb.

job "wordpress-files" do
  schedule "weekly", on: 'monday', at: "00:00"
  ...
end

job "wordpress-db" do
  schedule "daily", at: "00:00"
  ...
end

Running your Wordpress Backup

Test drive / single run

Open a terminal, change to the directory containing your Sheepfile and run:

electric_sheep

The schedule will be ignored and your Wordpress backup will execute sequentially. See the Command Line Reference for options.

Start as a daemon

Open a terminal, change to the directory containing your Sheepfile and run:

electric_sheep start

Electric Sheep IO will place itself in the background and launch workers to process your jobs on schedule.

Use stop or restart if you want to halt execution or reload the configuration. See the Command Line Reference for options.