Drupal
Backup your Drupal 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 "drupal", hostname: "drupal.example.com", private_key: "~/.ssh/electric_sheep_rsa"
job "drupal-files" do
schedule "daily", at: "00:00"
resource "directory", path: "/var/www", host: "drupal"
remotely as: "root" do
tar_gz
end
move to: "localhost", using: "scp", as: "root"
end
job "drupal-db" do
schedule "daily", at: "00:00"
resource "database", name: "drupal", host: "drupal"
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 Drupal database is hosted on a separated server node, declare an additional host entry in the Sheepfile.
host "drupal", hostname: "drupal.example.com", private_key: "~/.ssh/electric_sheep_rsa"
Backup the Drupal files
Declare a job and an initial directory
resource pointing to Drupal's 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 "drupal-files" do
resource "directory", path: "/var/www", host: "drupal"
remotely as: "root" do
tar_gz
end
move to: "localhost", using: "scp", as: "root"
end
Backup the Drupal 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 "drupal-db" do
resource "database", name: "drupal", host: "drupal"
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 Drupal can usually been found in the settings.php
of your Drupal installation.
Schedule your backups
You can choose a different scheduling for each of the jobs in your Sheepfile using the schedule
verb.
job "drupal-files" do
schedule "weekly", on: 'monday', at: "00:00"
...
end
job "drupal-db" do
schedule "daily", at: "00:00"
...
end
Running your Drupal 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 Drupal 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.
Updated less than a minute ago