{"_id":"54fda39021538c21006c49b5","__v":0,"user":"54bf8cd9dcfc4d0d00a1a19e","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","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"},"metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-02-25T10:28:13.094Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Installation\"\n}\n[/block]\nInstall [Docker](https://www.docker.com/) and pull the ElectricSheep.IO image from the Docker Hub:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"docker pull servebox/electric_sheep\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Running the container\"\n}\n[/block]\nThe [Dockerfile](https://github.com/servebox/electric_sheep/blob/master/build/Dockerfile) sets the container's `WORKDIR` to `/electric_sheep` and the `ENTRYPOINT` to `electric_sheep`. You'll have to mount a volume on `/electric_sheep` using the `-v` flag to make your configuration files available inside the container (_Sheepfile_, SSH and GPG keys - if applicable).\n\nConfigure the paths to your SSH and encryption keys according to the container filesystem (not to the host filesystem):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"decrypt with: \\\"/electric_sheep/electric_sheep.private.gpg.asc\\\"\\n\\nhost \\\"db\\\",\\n\\thostname: \\\"db.example.com\\\",\\n\\tprivate_key: \\\"/electric_sheep/electric_sheep_rsa\\\"\\n\\njob \\\"myapp-db\\\" do\\n  \\n  schedule \\\"daily\\\"\\n  \\n  resource \\\"database\\\", host: \\\"db\\\", name: \\\"myapp\\\"\\n  \\n  remotely as: \\\"operator\\\" do\\n    mysql_dump  user: \\\"mysql-user\\\", password: encrypted(\\\"XXXX\\\")\\n    tar_gz delete_source: true\\n  end\\n  \\n  move to: \\\"localhost\\\", using: \\\"scp\\\", as: \\\"operator\\\"\\n  move to: \\\"backups/bucket\\\", region: \\\"eu-west-1\\\", using: \\\"s3\\\" #...\\n  \\n  notify via: \\\"email\\\" #...\\n\\nend\",\n      \"language\": \"ruby\",\n      \"name\": \"Sheepfile\"\n    }\n  ]\n}\n[/block]\nOnce you're ready, start the container (you may also execute jobs inline using the `work` command instead of `start`):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"docker run -d \\\\\\n-v /path/to/config:/electric_sheep \\\\\\n--name backup-jobs \\\\\\nservebox/electric_sheep start\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Persistence\",\n  \"body\": \"Containers don't persist data across restarts. All is fine if you store your backups remotely, for example in an S3 bucket. But if you plan on storing a copy of your backups on the host running the container, you'll have to mount a second volume to store the artifacts. You may simply map a directory of the host to a volume of the container or create a data-only container.\"\n}\n[/block]\n### Store backups in a Host Directory\n\nIndicate the directory ES.IO should use as its [working directory](doc:working-directories) inside the container:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"working_directory \\\"/backups\\\"\\n\\n#...\",\n      \"language\": \"ruby\",\n      \"name\": \"Sheepfile\"\n    }\n  ]\n}\n[/block]\nThen mount the corresponding volume when starting the container:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"docker run -d \\\\\\n-v /var/backups:/backups \\\\\\n-v /path/to/config:/electric_sheep \\\\\\n--name backup-jobs \\\\\\nservebox/electric_sheep start\",\n      \"language\": \"shell\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\nIt's pretty straightforward but, to avoid container portability issues - such as uid/gid mismatches, a better approach is to create a data volume container.\n\n### Store backups in a Data Volume Container\n\nAlthough containers do not persist anything, volumes created by containers do. You don't have to map the volume on a host directory. First, create the data container:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"docker run \\\\\\n-v /backups \\\\\\n--name backups \\\\\\nubuntu echo \\\"Creating data volume\\\"\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIndicate ES.IO it should use this volume as its [working directory](doc:working-directories):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"working_directory \\\"/backups\\\"\\n\\n#...\",\n      \"language\": \"ruby\"\n    }\n  ]\n}\n[/block]\nNow start the ES.IO container and bind the volume from the previously created container:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"docker run -d \\\\\\n--name electric_sheep \\\\\\n--volumes-from backups \\\\\\n-v /path/to/config:/electric_sheep \\\\\\nservebox/electric_sheep start\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIf you need to manipulate the data to inspect or restore your backups, mount the volume inside another container:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"docker run \\\\\\n--volumes-from backups \\\\\\nubuntu du -h /backups\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nSee the [Docker documentation](http://docs.docker.com/userguide/dockervolumes/#creating-and-mounting-a-data-volume-container) for more information on data volume containers.","excerpt":"Run your backup jobs in a Docker container","slug":"docker","type":"basic","title":"Docker"}

Docker

Run your backup jobs in a Docker container

[block:api-header] { "type": "basic", "title": "Installation" } [/block] Install [Docker](https://www.docker.com/) and pull the ElectricSheep.IO image from the Docker Hub: [block:code] { "codes": [ { "code": "docker pull servebox/electric_sheep", "language": "shell" } ] } [/block] [block:api-header] { "type": "basic", "title": "Running the container" } [/block] The [Dockerfile](https://github.com/servebox/electric_sheep/blob/master/build/Dockerfile) sets the container's `WORKDIR` to `/electric_sheep` and the `ENTRYPOINT` to `electric_sheep`. You'll have to mount a volume on `/electric_sheep` using the `-v` flag to make your configuration files available inside the container (_Sheepfile_, SSH and GPG keys - if applicable). Configure the paths to your SSH and encryption keys according to the container filesystem (not to the host filesystem): [block:code] { "codes": [ { "code": "decrypt with: \"/electric_sheep/electric_sheep.private.gpg.asc\"\n\nhost \"db\",\n\thostname: \"db.example.com\",\n\tprivate_key: \"/electric_sheep/electric_sheep_rsa\"\n\njob \"myapp-db\" do\n \n schedule \"daily\"\n \n resource \"database\", host: \"db\", name: \"myapp\"\n \n remotely as: \"operator\" do\n mysql_dump user: \"mysql-user\", password: encrypted(\"XXXX\")\n tar_gz delete_source: true\n end\n \n move to: \"localhost\", using: \"scp\", as: \"operator\"\n move to: \"backups/bucket\", region: \"eu-west-1\", using: \"s3\" #...\n \n notify via: \"email\" #...\n\nend", "language": "ruby", "name": "Sheepfile" } ] } [/block] Once you're ready, start the container (you may also execute jobs inline using the `work` command instead of `start`): [block:code] { "codes": [ { "code": "docker run -d \\\n-v /path/to/config:/electric_sheep \\\n--name backup-jobs \\\nservebox/electric_sheep start", "language": "shell" } ] } [/block] [block:callout] { "type": "danger", "title": "Persistence", "body": "Containers don't persist data across restarts. All is fine if you store your backups remotely, for example in an S3 bucket. But if you plan on storing a copy of your backups on the host running the container, you'll have to mount a second volume to store the artifacts. You may simply map a directory of the host to a volume of the container or create a data-only container." } [/block] ### Store backups in a Host Directory Indicate the directory ES.IO should use as its [working directory](doc:working-directories) inside the container: [block:code] { "codes": [ { "code": "working_directory \"/backups\"\n\n#...", "language": "ruby", "name": "Sheepfile" } ] } [/block] Then mount the corresponding volume when starting the container: [block:code] { "codes": [ { "code": "docker run -d \\\n-v /var/backups:/backups \\\n-v /path/to/config:/electric_sheep \\\n--name backup-jobs \\\nservebox/electric_sheep start", "language": "shell", "name": null } ] } [/block] It's pretty straightforward but, to avoid container portability issues - such as uid/gid mismatches, a better approach is to create a data volume container. ### Store backups in a Data Volume Container Although containers do not persist anything, volumes created by containers do. You don't have to map the volume on a host directory. First, create the data container: [block:code] { "codes": [ { "code": "docker run \\\n-v /backups \\\n--name backups \\\nubuntu echo \"Creating data volume\"", "language": "shell" } ] } [/block] Indicate ES.IO it should use this volume as its [working directory](doc:working-directories): [block:code] { "codes": [ { "code": "working_directory \"/backups\"\n\n#...", "language": "ruby" } ] } [/block] Now start the ES.IO container and bind the volume from the previously created container: [block:code] { "codes": [ { "code": "docker run -d \\\n--name electric_sheep \\\n--volumes-from backups \\\n-v /path/to/config:/electric_sheep \\\nservebox/electric_sheep start", "language": "shell" } ] } [/block] If you need to manipulate the data to inspect or restore your backups, mount the volume inside another container: [block:code] { "codes": [ { "code": "docker run \\\n--volumes-from backups \\\nubuntu du -h /backups", "language": "shell" } ] } [/block] See the [Docker documentation](http://docs.docker.com/userguide/dockervolumes/#creating-and-mounting-a-data-volume-container) for more information on data volume containers.