From 45b6b3d0f2fd4efde5608e2afe00671ac33a41bf Mon Sep 17 00:00:00 2001 From: Ben Rog-Wilhelm Date: Wed, 14 Jun 2023 04:34:24 -0500 Subject: [PATCH 1/6] Add a prototype example docker-compose environment. --- example/README.md | 9 ++++++ example/borgmatic.d/config.yml | 44 ++++++++++++++++++++++++++++ example/borgmatic.d/crontab.txt | 2 ++ example/docker-compose.yml | 51 +++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 example/README.md create mode 100644 example/borgmatic.d/config.yml create mode 100644 example/borgmatic.d/crontab.txt create mode 100644 example/docker-compose.yml diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..c320a7d --- /dev/null +++ b/example/README.md @@ -0,0 +1,9 @@ +Here's a simple example of running this in a docker-compose environment. + +Read through `docker-compose.yml` and change things as appropriate. Then do the same with `borgmatic.d/config.yml` and `borgmatic.d/crontab.txt`. + +Start the container - `docker-compose up -d`. + +At the moment, you need to initialize the repo manually. Connect to the container directly (`docker exec -it borgmatic bash`). If you want a repo without encryption, run `borgmatic init -e none`. + +If you are using encryption, you'll need to do something else; I haven't written this section because I'm not using encryption (sorry! Please file a pull request if you figure it out!) Also, IT IS VITALLY IMPORTANT THAT YOU BACK UP `/config.borg/*` AND YOUR PASSPHRASE TO SOMEPLACE SAFE. YOU WILL NEED THESE TO RESTORE YOUR BACKUP. THIS IS NOT OPTIONAL. \ No newline at end of file diff --git a/example/borgmatic.d/config.yml b/example/borgmatic.d/config.yml new file mode 100644 index 0000000..7a8db26 --- /dev/null +++ b/example/borgmatic.d/config.yml @@ -0,0 +1,44 @@ +# See https://torsion.org/borgmatic/docs/reference/configuration/ for detailed information. + +location: + source_directories: + - /mnt/source + exclude_patterns: + - /mnt/source/home/*/.cache + source_directories_must_exist: true + + repositories: + # If you're backing up to a local directory, use this. + - /mnt/borg-repository + + # If you're backing up to a remote server, use your remote server's provided URL. + #- ssh://mmvz9gp4@mmvz9gp4.repo.borgbase.com/./repo + +storage: + compression: lz4 + archive_name_format: 'backup-{now}' + +retention: + keep_hourly: 0 + keep_daily: 7 + keep_weekly: 4 + keep_monthly: 12 + keep_yearly: 1 + +consistency: + checks: + - repository + - archives + check_last: 3 + prefix: 'backup-' + +hooks: + before_backup: + - echo "Starting a backup job." + after_backup: + - echo "Backup created." + on_error: + - echo "Error while creating a backup." + + # Third-party services to notify you if backups aren't happening; see https://healthchecks.io + # healthchecks: https://hc-ping.com/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx diff --git a/example/borgmatic.d/crontab.txt b/example/borgmatic.d/crontab.txt new file mode 100644 index 0000000..f6f1d8d --- /dev/null +++ b/example/borgmatic.d/crontab.txt @@ -0,0 +1,2 @@ +## This starts a Borg run every day at 2 in the morning. +0 2 * * * PATH=$PATH:/usr/bin /usr/bin/borgmatic --stats -v 0 2>&1 diff --git a/example/docker-compose.yml b/example/docker-compose.yml new file mode 100644 index 0000000..812c387 --- /dev/null +++ b/example/docker-compose.yml @@ -0,0 +1,51 @@ +version: "2.4" +services: + borgmatic: + container_name: borgmatic + + image: modem7/borgmatic-docker + #build: ../base + + volumes: + # ------------- + # Source and destination directories + + # Mount the directories you want to back up under /mnt/source. + # We're mounting them read-only for a little extra safety. + - /home:/mnt/source/home:ro + - /etc:/mnt/source/etc:ro + + # If you're backing up to a local backup destination, mount it here. + # Remove this if you're doing remote backups only. + - /mnt/backup:/mnt/borg-repository + + # ------------- + # Config files that you write + + # Borgmatic and crontab config files will go here. + - ./borgmatic.d:/etc/borgmatic.d/ + + # If you're using a remote repository, you'll need an SSH key. + # Uncomment this if you want to use root's ssh key. + #- ~/.ssh:/root/.ssh + + # If you want a separate SSH key just for borg, uncomment this instead, then `ssh-keygen -f ssh/id_rsa`. + #- ./ssh:/root/.ssh + + # ------------- + # Borgmon working space + + # Borgmon will write config files and keyfiles here (back these up somewhere very safe if you're using encryption! You will need them to restore your backup! If you do not have your keyfile you will not be able to restore your files!) + - ./config.borg:/root/.config/borg + + # Borg wants local cache data to track deduplication. Does not need to be backed up, but makes Borg run faster. + - ./cache.borg:/root/.cache/borg + + environment: + # Change this to your local timezone if you care about when your backups run. + - TZ=America/Chicago + + # If you're using a passphrase on your keyfile, make sure this is wrtten somewhere extremely safe. You will also need this to restore your files! + #- BORG_PASSPHRASE=SetYourPassphraseHereIfYouWantOne + + restart: unless-stopped From 1c6855e20e282a6ca3f02eb74fcb555a9ef06501 Mon Sep 17 00:00:00 2001 From: Ben Rog-Wilhelm Date: Thu, 15 Jun 2023 01:15:12 -0500 Subject: [PATCH 2/6] Fix: Incorrect crontab binary path. --- example/borgmatic.d/crontab.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/borgmatic.d/crontab.txt b/example/borgmatic.d/crontab.txt index f6f1d8d..abf82ef 100644 --- a/example/borgmatic.d/crontab.txt +++ b/example/borgmatic.d/crontab.txt @@ -1,2 +1,2 @@ ## This starts a Borg run every day at 2 in the morning. -0 2 * * * PATH=$PATH:/usr/bin /usr/bin/borgmatic --stats -v 0 2>&1 +0 2 * * * PATH=$PATH:/usr/local/bin /usr/local/bin/borgmatic --stats -v 0 2>&1 From 243dbee405c130ce6817ba8e0958be82a9e3d5eb Mon Sep 17 00:00:00 2001 From: Ben Rog-Wilhelm Date: Sun, 18 Jun 2023 06:23:46 -0500 Subject: [PATCH 3/6] Fix: Container was reading off a third party, not the official repo. --- example/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/docker-compose.yml b/example/docker-compose.yml index 812c387..eb0052b 100644 --- a/example/docker-compose.yml +++ b/example/docker-compose.yml @@ -3,7 +3,7 @@ services: borgmatic: container_name: borgmatic - image: modem7/borgmatic-docker + image: ghcr.io/borgmatic-collective/borgmatic #build: ../base volumes: From 05e5f9372b13a0174f83b5949c56f42398afe361 Mon Sep 17 00:00:00 2001 From: Ben Rog-Wilhelm Date: Sun, 18 Jun 2023 12:16:18 -0500 Subject: [PATCH 4/6] Add a little more documentation and suggestions for common directory mounts. --- example/docker-compose.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/example/docker-compose.yml b/example/docker-compose.yml index eb0052b..b87a8ad 100644 --- a/example/docker-compose.yml +++ b/example/docker-compose.yml @@ -11,9 +11,14 @@ services: # Source and destination directories # Mount the directories you want to back up under /mnt/source. + # Common suggestions are provided here. # We're mounting them read-only for a little extra safety. - - /home:/mnt/source/home:ro - - /etc:/mnt/source/etc:ro + - /home:/mnt/source/home:ro # User home directories. + - /etc:/mnt/source/etc:ro # System configuration. + #- /var:/mnt/source/var:ro # Variable system data; it's common for databases and Docker volumes to end up here. Probably not necessary unless you're hosting services off this computer. + #- /srv:/mnt/source/srv:ro # Another common location for service data, especially websites. + #- /media:/mnt/source/media:ro # Common location for mounted external drives or secondary drives. Likely to include USB sticks and CDs, which may be undesirable. + #- /data:/mnt/source/data:ro # Less standard but sometimes-seen directory for permanent drive mounts and service data. # If you're backing up to a local backup destination, mount it here. # Remove this if you're doing remote backups only. From 87416a96d1b11325344f3d4c9a8b16a23688a630 Mon Sep 17 00:00:00 2001 From: Ben Rog-Wilhelm Date: Sun, 18 Jun 2023 12:16:30 -0500 Subject: [PATCH 5/6] Clean up encryption text a little bit. --- example/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/docker-compose.yml b/example/docker-compose.yml index b87a8ad..7ae6e82 100644 --- a/example/docker-compose.yml +++ b/example/docker-compose.yml @@ -40,7 +40,7 @@ services: # ------------- # Borgmon working space - # Borgmon will write config files and keyfiles here (back these up somewhere very safe if you're using encryption! You will need them to restore your backup! If you do not have your keyfile you will not be able to restore your files!) + # Borgmon will write config files and keyfiles here (if you're using encryption, back these up somewhere very safe! You will need them to restore your backup! If you do not have your keyfile you will not be able to restore encrypted files!) - ./config.borg:/root/.config/borg # Borg wants local cache data to track deduplication. Does not need to be backed up, but makes Borg run faster. From 18d6e66e38752d51c31fe9f4b64fb4955f506b7b Mon Sep 17 00:00:00 2001 From: Ben Rog-Wilhelm Date: Sun, 18 Jun 2023 12:16:50 -0500 Subject: [PATCH 6/6] Minor documentation improvements. --- example/borgmatic.d/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example/borgmatic.d/config.yml b/example/borgmatic.d/config.yml index 7a8db26..38496da 100644 --- a/example/borgmatic.d/config.yml +++ b/example/borgmatic.d/config.yml @@ -4,6 +4,7 @@ location: source_directories: - /mnt/source exclude_patterns: + # Common location for ephemeral cache files that don't need to be backed up. - /mnt/source/home/*/.cache source_directories_must_exist: true @@ -12,6 +13,7 @@ location: - /mnt/borg-repository # If you're backing up to a remote server, use your remote server's provided URL. + # This URL is an example provided by Borgbase and will not work for you, you'll need your own. #- ssh://mmvz9gp4@mmvz9gp4.repo.borgbase.com/./repo storage: