{"id":18298129,"url":"https://github.com/modem7/docker-borgmatic","last_synced_at":"2025-04-09T09:16:12.290Z","repository":{"id":38162358,"uuid":"405103648","full_name":"modem7/docker-borgmatic","owner":"modem7","description":"Container to automate Borgbackups (https://github.com/borgbackup) using Borgmatic (https://github.com/witten/borgmatic)","archived":false,"fork":false,"pushed_at":"2025-04-06T23:03:53.000Z","size":22123,"stargazers_count":37,"open_issues_count":1,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T23:25:58.001Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/modem7.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-10T14:12:33.000Z","updated_at":"2025-04-06T23:03:23.000Z","dependencies_parsed_at":"2023-10-02T11:48:48.841Z","dependency_job_id":"e6412254-05e1-44cc-945b-933221b99253","html_url":"https://github.com/modem7/docker-borgmatic","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modem7%2Fdocker-borgmatic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modem7%2Fdocker-borgmatic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modem7%2Fdocker-borgmatic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modem7%2Fdocker-borgmatic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/modem7","download_url":"https://codeload.github.com/modem7/docker-borgmatic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008626,"owners_count":21032556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T15:05:17.819Z","updated_at":"2025-04-09T09:16:12.260Z","avatar_url":"https://github.com/modem7.png","language":"Dockerfile","funding_links":["https://www.buymeacoffee.com/modem7"],"categories":["Install from Source"],"sub_categories":["Backups"],"readme":"# Borgmatic Container with S6\n[![Docker Pulls](https://img.shields.io/docker/pulls/modem7/borgmatic-docker)](https://hub.docker.com/r/modem7/borgmatic-docker)\n[![Docker Image Size (tag)](https://img.shields.io/docker/image-size/modem7/borgmatic-docker/latest)](https://hub.docker.com/r/modem7/borgmatic-docker)\n[![Build Status](https://drone.modem7.com/api/badges/modem7/docker-borgmatic/status.svg)](https://drone.modem7.com/modem7/docker-borgmatic)\n[![GitHub last commit](https://img.shields.io/github/last-commit/modem7/docker-borgmatic)](https://github.com/modem7/docker-borgmatic)\n[![User Guide](https://img.shields.io/badge/User_Guide-OmegaWiki-informational?style=flat\u0026logo=bookstack)](https://www.modem7.com/books/docker-backup/page/backup-docker-using-borgmatic)\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/modem7)\n\n### Description\nMultiarch fork of [borgmatic-collective/borgmatic](https://github.com/borgmatic-collective/docker-borgmatic) with latest software versions and leveraging S6 so you can run Docker commands. \n\nThere are also tags with Docker-CLI installed. Useful for container stop/start scripts. \n\n### Dockerhub\n\n[modem7/borgmatic-docker](https://hub.docker.com/repository/docker/modem7/borgmatic-docker)\n\n### Github\n\n[modem7/borgmatic-docker](https://github.com/modem7/docker-borgmatic)\n\n### Readme\n\nA little container based on [b3vis's](https://github.com/borgmatic-collective/docker-borgmatic) work to automate my [Borgbackups](https://github.com/borgbackup) using the excellent [Borgmatic](https://github.com/borgmatic-collective/borgmatic).\n\nIt uses cron to run the backups at a time you can configure in `data/borgmatic.d/crontab.txt`.\n\n# Tags\n| Tag | Description |\n| :----: | --- |\n| Latest | Latest version of Borgmatic|\n| 1.8.xx-1.2.x | Specific versions of Borgmatic |\n\n# Environment Variables\n| Variable | Description | Possible Values | Default |\n| :----: | --- | --- | --- |\n| DOCKERCLI | Install DockerCLI and ComposeCLI | true | Empty |\n| EXTRA_PKGS | Install additional packages | rclone coreutils jq other_packages | Empty |\n| CRON | Cron times | cron time, false | 0 1 * * * |\n| CRON_COMMAND | Command cron will run | borgmatic --stats -v 0 2\u003e\u00261 | borgmatic --stats -v 0 2\u003e\u00261 |\n| EXTRA_CRON | Extra cron lines | 0 5 2 * * command1 | Empty |\n\n## Customising the container\nSimply mount a volume located at /custom-cont-init.d and add any scripts you want. These scripts can contain logic for installing packages, copying over custom files to other locations, or installing plugins.\n\nFor example:\n```yaml\nservices:\n  borgmatic:\n    volumes:\n      - /home/foo/my-custom-files:/custom-cont-init.d:ro\n```\n\n### Usage\n\nPlease look at this [guide](https://www.modem7.com/books/docker-backup/page/backup-docker-using-borgmatic) to help you run this container.\n\nTo set your backup timing and configuration, you will need to create\n[crontab.txt](https://github.com/modem7/docker-borgmatic/blob/master/base-fullbuild/data/borgmatic.d/crontab.txt) and your borgmatic\n[config.yaml](https://github.com/modem7/docker-borgmatic/blob/master/base-fullbuild/data/borgmatic.d/config.yaml) and mount these files into the `/etc/borgmatic.d/`\ndirectory. When the container starts it creates the crontab from `crontab.txt` and starts crond. By\ncloning this repo in `/opt/docker/`, you will have a working setup to get started. \n\nIf using remote repositories mount your .ssh to /root/.ssh within the container.\n\n#### Starting and stopping containers from hooks\n\nIn case you are using the container to backup docker volumes used by other containers, you might\nwant to make sure that the data is consistent and doesn't change while the backup is running. The\neasiest way to ensure this is to stop the affected containers before the backup and restart them\nafterwards. You can use the appropriate [borgmatic\nhooks](https://torsion.org/borgmatic/docs/how-to/add-preparation-and-cleanup-steps-to-backups/) and\n[control the docker engine through the API](https://docs.docker.com/engine/api/) using the hosts\ndocker socket.\n\nPlease note that you might want to prefer the `*_everything` hooks to the `*_backup` hooks, as\n`after_backup` will not run if the backup fails for any reason (missing disk space, etc.) and\ntherefore the containers stay stopped.\n\nFirst mount the docker socket from the host by adding `-v /var/run/docker.sock:/var/run/docker.sock`\nto your `run` command or in the volume list of your `docker-compose.yml`.\n\nThen use the following example to create the start/stop hooks in the `config.yml` for the containers\nthat you want to control.\n\n```yaml\nhooks:\n    before_everything:\n        - echo \"Stopping containers...\"\n        - 'echo -ne \"POST /v1.41/containers/\u003ccontainer1-name\u003e/stop HTTP/1.1\\r\\nHost: localhost\\r\\n\\r\\n\" | nc local:/var/run/docker.sock 80 \u003e /dev/null \u0026\u0026 echo \"Stopped Container 1\" || echo \"Failed to stop Container 1\"'\n        - 'echo -ne \"POST /v1.41/containers/\u003ccontainer2-name\u003e/stop HTTP/1.1\\r\\nHost: localhost\\r\\n\\r\\n\" | nc local:/var/run/docker.sock 80 \u003e /dev/null \u0026\u0026 echo \"Stopped Container 2\" || echo \"Failed to stop Container 2\"'\n        - echo \"Containers stopped.\"\n        - echo \"Starting a backup.\"\n\n    after_everything:\n        - echo \"Finished a backup.\"\n        - echo \"Restarting containers...\"\n        - 'echo -ne \"POST /v1.41/containers/\u003ccontainer1-name\u003e/start HTTP/1.1\\r\\nHost: localhost\\r\\n\\r\\n\" | nc local:/var/run/docker.sock 80 \u003e /dev/null \u0026\u0026 echo \"Started Container 1\" || echo \"Failed to start Container 1\"'\n        - 'echo -ne \"POST /v1.41/containers/\u003ccontainer2-name\u003e/start HTTP/1.1\\r\\nHost: localhost\\r\\n\\r\\n\" | nc local:/var/run/docker.sock 80 \u003e /dev/null \u0026\u0026 echo \"Started Container 2\" || echo \"Failed to start Container 2\"'\n        - echo \"Containers restarted.\"\n```\n\n### Example run command\n```console\ndocker run \\\n  --detach --name borgmatic \\\n  -v /home:/mnt/source:ro \\\n  -v /opt/docker/docker-borgmatic/data/repository:/mnt/borg-repository \\\n  -v /opt/docker/docker-borgmatic/data/borgmatic.d:/etc/borgmatic.d/ \\\n  -v /opt/docker/docker-borgmatic/data/.config/borg:/root/.config/borg \\\n  -v /opt/docker/docker-borgmatic/data/.ssh:/root/.ssh \\\n  -v /opt/docker/docker-borgmatic/data/.cache/borg:/root/.cache/borg \\\n  -e TZ=Europe/London \\\n  modem7/borgmatic-docker\n```\nWhile the parameters above are sufficient for regular backups, following additional privileges will\nbe needed to mount an archive as FUSE filesystem:\n```console\n--cap-add SYS_ADMIN \\\n--device /dev/fuse \\\n--security-opt label:disable \\\n--security-opt apparmor:unconfined\n```\nDepending on your security system, `--security-opt` parameters may not be necessary. `label:disable`\nis needed for *SELinux*, while `apparmor:unconfined` is needed for *AppArmor*.\n\nTo init the repo with encryption, run:\n```console\ndocker exec borgmatic \\\nsh -c \"borgmatic --init --encryption repokey-blake2\"\n```\n\n### Layout\n#### /mnt/source\nYour data you wish to backup. For *some* safety you may want to mount read-only. Borgmatic is\nrunning as root so all files can be backed up. \n#### /mnt/borg-repository\nMount your borg backup repository here.\n#### /etc/borgmatic.d\nWhere you need to create crontab.txt and your borgmatic config.yml\n- To generate an example borgmatic configuration, run:\n```console\ndocker exec borgmatic \\\nsh -c \"cd \u0026\u0026 borgmatic config generate -d /etc/borgmatic.d/config.yaml\"\n```\n- crontab.txt example: In this file set the time you wish for your backups to take place default is\n  1am every day. In here you can add any other tasks you want ran\n```\n0 1 * * * PATH=$PATH:/usr/bin /usr/bin/borgmatic --stats -v 0 2\u003e\u00261\n```\n#### /root/.config/borg\nHere the borg config and keys for keyfile encryption modes are stored. Make sure to backup your\nkeyfiles! Also needed when encryption is set to none.\n#### /root/.ssh\nMount either your own .ssh here or create a new one with ssh keys in for your remote repo locations.\n#### /root/.cache/borg\nA non-volatile place to store the borg chunk cache.\n\n### Environment\n- Time zone, e.g. `TZ=\"Europe/Berlin\"'`.\n- SSH parameters, e.g. `BORG_RSH=\"ssh -i /root/.ssh/id_ed25519 -p 50221\"`\n- BORG_RSH=\"ssh -i /root/.ssh/id_ed25519 -p 50221\"\n- Repository passphrase, e.g. `BORG_PASSPHRASE=\"DonNotMissToChangeYourPassphrase\"`\n\n### Docker Compose\n  - Prepare your configuration\n    1. `cp .env.template .env`\n    2. Set your environment and adapt volumes as needed\n  - To start the container for backup: `docker-compose up -d`\n  - For backup restore: \n    1. Stop the backup container: `docker-compose down`\n    2. Run an interactive shell: `docker-compose -f docker-compose.yml -f docker-compose.restore.yml\n       run borgmatic`\n    3. Fuse-mount the backup: `borg mount /mnt/borg-repository \u003cmount_point\u003e`\n    4. Restore your files\n    5. Finally unmount and exit: `borg umount \u003cmount_point\u003e \u0026\u0026 exit`.\n  - In case Borg fails to create/acquire a lock: `borg break-lock /mnt/repository`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodem7%2Fdocker-borgmatic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodem7%2Fdocker-borgmatic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodem7%2Fdocker-borgmatic/lists"}