{"_id":"54fda39021538c21006c49b3","version":{"_id":"54fda38e21538c21006c49a6","__v":3,"forked_from":"54eb4535615ffc19003059f0","project":"545e249c7ca5470800b3a1b2","createdAt":"2015-03-09T13:43:42.927Z","releaseDate":"2015-03-09T13:43:42.927Z","categories":["54fda38f21538c21006c49a7","54fda38f21538c21006c49a8","54fda38f21538c21006c49a9","54fda38f21538c21006c49aa","54fda38f21538c21006c49ab","54fda3d347f93619001d2ae2","54fea8975c4ab10d00ef4279"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.5.0","version":"0.5.0"},"category":{"_id":"54fda38f21538c21006c49a9","version":"54fda38e21538c21006c49a6","project":"545e249c7ca5470800b3a1b2","__v":1,"pages":["54fda39021538c21006c49b3","54fda39021538c21006c49b4","54fda39021538c21006c49b5"],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-11-26T13:55:44.138Z","from_sync":false,"order":5,"slug":"cookbooks","title":"Cookbooks"},"githubsync":"","project":"545e249c7ca5470800b3a1b2","__v":0,"user":"545e246f7ca5470800b3a1b1","updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-11-26T13:57:42.052Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"never","params":[],"url":""},"isReference":false,"order":1,"body":"Remember to create an SSH keypair and to deploy the public key on the remote host(s). See [here](doc:getting-started) for instructions on installation and public key deployment.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"For the impatient\"\n}\n[/block]\nAdd 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.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"host \\\"drupal\\\", hostname: \\\"drupal.example.com\\\", private_key: \\\"~/.ssh/electric_sheep_rsa\\\"\\n\\njob \\\"drupal-files\\\" do\\n  schedule \\\"daily\\\", at: \\\"00:00\\\"\\n  resource \\\"directory\\\", path: \\\"/var/www\\\", host: \\\"drupal\\\"\\n  remotely as: \\\"root\\\" do\\n    tar_gz\\n  end\\n  move to: \\\"localhost\\\", using: \\\"scp\\\", as: \\\"root\\\"\\nend\\n\\njob \\\"drupal-db\\\" do\\n  schedule \\\"daily\\\", at: \\\"00:00\\\"\\n  resource \\\"database\\\", name: \\\"drupal\\\", host: \\\"drupal\\\"\\n  remotely as: \\\"root\\\" do\\n    mysql_dump user: \\\"db-username\\\", password: \\\"db-password\\\"\\n    tar_gz delete_source: true\\n  end\\n  move to: \\\"localhost\\\", using: \\\"scp\\\", as: \\\"root\\\"\\nend\",\n      \"language\": \"ruby\",\n      \"name\": \"Sheepfile\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Step by step configuration\"\n}\n[/block]\n### Declare the remote host(s)\n\nAdd 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.\n\nIf the Drupal database is hosted on a separated server node, declare an additional host entry in the Sheepfile.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"host \\\"drupal\\\", hostname: \\\"drupal.example.com\\\", private_key: \\\"~/.ssh/electric_sheep_rsa\\\"\",\n      \"language\": \"ruby\",\n      \"name\": \"Sheepfile\"\n    }\n  ]\n}\n[/block]\n### Backup the Drupal files\n\nDeclare 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.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"job \\\"drupal-files\\\" do\\n  resource \\\"directory\\\", path: \\\"/var/www\\\", host: \\\"drupal\\\"\\n  remotely as: \\\"root\\\" do\\n    tar_gz\\n  end\\n  move to: \\\"localhost\\\", using: \\\"scp\\\", as: \\\"root\\\"\\nend\",\n      \"language\": \"ruby\",\n      \"name\": \"Sheepfile\"\n    }\n  ]\n}\n[/block]\n### Backup the Drupal database\n\nDeclare 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.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"job \\\"drupal-db\\\" do\\n  resource \\\"database\\\", name: \\\"drupal\\\", host: \\\"drupal\\\"\\n  remotely as: \\\"root\\\" do\\n    mysql_dump user: \\\"db-username\\\", password: \\\"db-password\\\"\\n    tar_gz delete_source: true\\n  end\\n  move to: \\\"localhost\\\", using: \\\"scp\\\", as: \\\"root\\\"\\nend\",\n      \"language\": \"ruby\",\n      \"name\": \"Sheepfile\"\n    }\n  ]\n}\n[/block]\nThe MySQL credentials used by Drupal can usually been found in the `settings.php` of your Drupal installation.\n\n### Schedule your backups\n\nYou can choose a different scheduling for each of the jobs in your _Sheepfile_ using the `schedule` verb.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"job \\\"drupal-files\\\" do\\n  schedule \\\"weekly\\\", on: 'monday', at: \\\"00:00\\\"\\n  ...\\nend\\n\\njob \\\"drupal-db\\\" do\\n  schedule \\\"daily\\\", at: \\\"00:00\\\"\\n  ...\\nend\",\n      \"language\": \"ruby\",\n      \"name\": \"Sheepfile\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Running your Drupal Backup\"\n}\n[/block]\n### Test drive / single run\n\nOpen a terminal, change to the directory containing your _Sheepfile_ and run:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"electric_sheep\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nThe `schedule` will be ignored and your Drupal backup will execute sequentially. See the [Command Line Reference](doc:command-line) for options.\n\n### Start as a daemon\n\nOpen a terminal, change to the directory containing your Sheepfile and run:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"electric_sheep start\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nElectric Sheep IO will place itself in the background and launch workers to process your jobs on schedule.\n\nUse `stop` or `restart` if you want to halt execution or reload the configuration. See the [Command Line Reference](doc:command-line) for options.","excerpt":"Backup your Drupal database, code and files","slug":"drupal","type":"basic","title":"Drupal"}

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](doc:getting-started) for instructions on installation and public key deployment. [block:api-header] { "type": "basic", "title": "For the impatient" } [/block] 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. [block:code] { "codes": [ { "code": "host \"drupal\", hostname: \"drupal.example.com\", private_key: \"~/.ssh/electric_sheep_rsa\"\n\njob \"drupal-files\" do\n schedule \"daily\", at: \"00:00\"\n resource \"directory\", path: \"/var/www\", host: \"drupal\"\n remotely as: \"root\" do\n tar_gz\n end\n move to: \"localhost\", using: \"scp\", as: \"root\"\nend\n\njob \"drupal-db\" do\n schedule \"daily\", at: \"00:00\"\n resource \"database\", name: \"drupal\", host: \"drupal\"\n remotely as: \"root\" do\n mysql_dump user: \"db-username\", password: \"db-password\"\n tar_gz delete_source: true\n end\n move to: \"localhost\", using: \"scp\", as: \"root\"\nend", "language": "ruby", "name": "Sheepfile" } ] } [/block] [block:api-header] { "type": "basic", "title": "Step by step configuration" } [/block] ### 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. [block:code] { "codes": [ { "code": "host \"drupal\", hostname: \"drupal.example.com\", private_key: \"~/.ssh/electric_sheep_rsa\"", "language": "ruby", "name": "Sheepfile" } ] } [/block] ### 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. [block:code] { "codes": [ { "code": "job \"drupal-files\" do\n resource \"directory\", path: \"/var/www\", host: \"drupal\"\n remotely as: \"root\" do\n tar_gz\n end\n move to: \"localhost\", using: \"scp\", as: \"root\"\nend", "language": "ruby", "name": "Sheepfile" } ] } [/block] ### 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. [block:code] { "codes": [ { "code": "job \"drupal-db\" do\n resource \"database\", name: \"drupal\", host: \"drupal\"\n remotely as: \"root\" do\n mysql_dump user: \"db-username\", password: \"db-password\"\n tar_gz delete_source: true\n end\n move to: \"localhost\", using: \"scp\", as: \"root\"\nend", "language": "ruby", "name": "Sheepfile" } ] } [/block] 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. [block:code] { "codes": [ { "code": "job \"drupal-files\" do\n schedule \"weekly\", on: 'monday', at: \"00:00\"\n ...\nend\n\njob \"drupal-db\" do\n schedule \"daily\", at: \"00:00\"\n ...\nend", "language": "ruby", "name": "Sheepfile" } ] } [/block] [block:api-header] { "type": "basic", "title": "Running your Drupal Backup" } [/block] ### Test drive / single run Open a terminal, change to the directory containing your _Sheepfile_ and run: [block:code] { "codes": [ { "code": "electric_sheep", "language": "shell" } ] } [/block] The `schedule` will be ignored and your Drupal backup will execute sequentially. See the [Command Line Reference](doc:command-line) for options. ### Start as a daemon Open a terminal, change to the directory containing your Sheepfile and run: [block:code] { "codes": [ { "code": "electric_sheep start", "language": "shell" } ] } [/block] 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](doc:command-line) for options.