Compare commits

...

123 Commits

Author SHA1 Message Date
Frederik Ring
89655e09ad Config reference should always use default values (#549)
* Config reference should always use default values

* Cut down proliferation of conventions in config reference
2025-02-28 17:31:07 +01:00
Frederik Ring
016e470f5f Directories aren't excluded from pruning logic (#548) 2025-02-28 17:21:35 +01:00
Frederik Ring
0f30b959f8 Info on filenames is missing on errors when deleting files 2025-02-28 14:48:11 +01:00
Frederik Ring
eb4099debd Paths are joined with client side separators when targeting remotes (#547)
Currently, filepath.Join is used to join path fragments that are supposed
to be created on remote storage backends. This could theoretically cause
problems when the separators used by the client and the remotes do not match.
It's unlikely this causes problems right now, but it's definitely better to
rectify it before it causes further confusion.

This was raised in #541
2025-02-27 13:55:14 +01:00
Frederik Ring
d8ac5ae7e6 Ensure all examples in docs mount a readonly socket 2025-02-27 11:47:57 +01:00
Frederik Ring
bad2d98ac8 Always use read only socket mount in tests (#546) 2025-02-26 12:00:39 +01:00
dependabot[bot]
2884d89f47 Bump github.com/klauspost/compress from 1.17.11 to 1.18.0 (#545) 2025-02-25 06:21:53 +00:00
dependabot[bot]
fcdaa09538 Bump github.com/minio/minio-go/v7 from 7.0.86 to 7.0.87 (#544) 2025-02-25 06:21:37 +00:00
dependabot[bot]
c48ac28626 Bump github.com/docker/cli (#543) 2025-02-25 06:21:23 +00:00
dependabot[bot]
22a4346c06 Bump golang.org/x/oauth2 from 0.26.0 to 0.27.0 (#542) 2025-02-25 06:21:08 +00:00
dependabot[bot]
41d518a341 Bump golang from 1.23-alpine to 1.24-alpine (#537)
* Bump golang from 1.23-alpine to 1.24-alpine

Bumps golang from 1.23-alpine to 1.24-alpine.

---
updated-dependencies:
- dependency-name: golang
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* Also update CI and go.mod

* Old version of golangci-lint does not match Go version

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Frederik Ring <frederik.ring@gmail.com>
2025-02-22 16:33:20 +01:00
dependabot[bot]
8f0a1c9809 Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity (#536) 2025-02-17 21:57:57 +00:00
dependabot[bot]
75f94b0211 Bump github.com/minio/minio-go/v7 from 7.0.85 to 7.0.86 (#535) 2025-02-17 21:57:01 +00:00
dependabot[bot]
56f325a8bd Bump golang.org/x/sync from 0.10.0 to 0.11.0 (#533) 2025-02-11 06:23:44 +00:00
dependabot[bot]
7e6ed752f7 Bump github.com/minio/minio-go/v7 from 7.0.84 to 7.0.85 (#534) 2025-02-11 06:05:06 +00:00
dependabot[bot]
00cf059f4f Bump golang.org/x/oauth2 from 0.25.0 to 0.26.0 (#532) 2025-02-11 06:04:51 +00:00
Frederik Ring
cbbaa6ba7a Support passing standard ssh keys to age encryption (#530)
* Support passing standard ssh keys to age encryption

* Cover SSH keys in age test case
2025-02-07 13:43:41 +01:00
Frederik Ring
2652e05169 Docker build now warns about casing mismatch 2025-02-06 17:49:50 +01:00
Frederik Ring
23756074f9 Publishing actions have been deprecated 2025-02-04 16:37:25 +01:00
Frederik Ring
40b12b9d07 Configuration reference on age encryption is lacking 2025-02-04 16:34:10 +01:00
dependabot[bot]
e628f09122 Bump github.com/docker/cli (#526) 2025-01-28 06:21:38 +00:00
dependabot[bot]
7340e00dab Bump github.com/Azure/azure-sdk-for-go/sdk/storage/azblob (#527) 2025-01-28 06:02:39 +00:00
Frederik Ring
958585336a Funding info for GitHub is redundant 2025-01-23 13:53:26 +01:00
dependabot[bot]
68b7e4d678 Bump github.com/minio/minio-go/v7 from 7.0.83 to 7.0.84 (#524) 2025-01-21 06:01:34 +00:00
dependabot[bot]
857e4fc605 Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity (#523) 2025-01-21 06:01:11 +00:00
dependabot[bot]
8d26194809 Bump github.com/docker/cli (#522) 2025-01-14 12:09:03 +00:00
Frederik Ring
3063288d1e Main README should refer to configuration reference instead 2025-01-09 18:17:53 +01:00
dependabot[bot]
02fdfb363c Bump alpine from 3.20 to 3.21 (#502) 2025-01-07 15:00:54 +00:00
dependabot[bot]
2ee23a9384 Bump golang.org/x/oauth2 from 0.24.0 to 0.25.0 (#517) 2025-01-07 06:06:22 +00:00
dependabot[bot]
16be0c0217 Bump github.com/otiai10/copy from 1.14.0 to 1.14.1 (#518) 2025-01-07 05:47:03 +00:00
Frederik Ring
4799795f0a MariaDB image stopped providing mysqldump shim, use plain name 2025-01-06 20:07:35 +01:00
Frederik Ring
49b8d2f8d8 Error cases when parsing commands into argv are not handled sufficiently (#506) 2025-01-06 19:55:15 +01:00
Frederik Ring
e4beef200a Update minio client to v7.0.83 (#516) 2025-01-06 19:54:54 +01:00
dependabot[bot]
e75ab8bdd8 Bump github.com/studio-b12/gowebdav from 0.9.0 to 0.10.0 (#512) 2024-12-24 06:31:56 +00:00
dependabot[bot]
a4145352f9 Bump github.com/docker/cli (#511) 2024-12-24 06:27:44 +00:00
dependabot[bot]
615256cda9 Bump filippo.io/age from 1.2.0 to 1.2.1 (#510) 2024-12-18 18:43:47 +00:00
dependabot[bot]
40c4f11d70 Bump github.com/minio/minio-go/v7 from 7.0.81 to 7.0.82 (#508) 2024-12-16 21:21:07 +00:00
dependabot[bot]
2685571c58 Bump golang.org/x/sync from 0.9.0 to 0.10.0 (#500) 2024-12-09 21:35:36 +00:00
dependabot[bot]
04ad0777e0 Bump github.com/docker/cli (#501) 2024-12-09 21:35:31 +00:00
dependabot[bot]
50e41eac02 Bump github.com/minio/minio-go/v7 from 7.0.80 to 7.0.81 (#499) 2024-12-03 06:20:34 +00:00
dependabot[bot]
94e59a102e Bump github.com/Azure/azure-sdk-for-go/sdk/storage/azblob from 1.4.1 to 1.5.0 (#495)
* Bump github.com/Azure/azure-sdk-for-go/sdk/storage/azblob

Bumps [github.com/Azure/azure-sdk-for-go/sdk/storage/azblob](https://github.com/Azure/azure-sdk-for-go) from 1.4.1 to 1.5.0.
- [Release notes](https://github.com/Azure/azure-sdk-for-go/releases)
- [Changelog](https://github.com/Azure/azure-sdk-for-go/blob/main/documentation/release.md)
- [Commits](https://github.com/Azure/azure-sdk-for-go/compare/sdk/storage/azblob/v1.4.1...sdk/azcore/v1.5.0)

---
updated-dependencies:
- dependency-name: github.com/Azure/azure-sdk-for-go/sdk/storage/azblob
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update azurite image to match updated client capabilities

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Frederik Ring <frederik.ring@gmail.com>
2024-11-19 13:27:36 +01:00
dependabot[bot]
964a5e0342 Bump golang.org/x/oauth2 from 0.23.0 to 0.24.0 (#494) 2024-11-12 06:20:46 +00:00
dependabot[bot]
2363c3c9cb Bump golang.org/x/sync from 0.8.0 to 0.9.0 (#493) 2024-11-12 06:02:14 +00:00
dependabot[bot]
6bc66db833 Bump github.com/minio/minio-go/v7 from 7.0.79 to 7.0.80 (#491) 2024-11-04 21:39:31 +00:00
dependabot[bot]
de40eae4de Bump github.com/minio/minio-go/v7 from 7.0.78 to 7.0.79 (#488) 2024-10-28 21:53:31 +00:00
dependabot[bot]
731421e359 Bump github.com/pkg/sftp from 1.13.6 to 1.13.7 (#489) 2024-10-28 21:33:27 +00:00
dependabot[bot]
d46918b13a Bump rexml from 3.3.6 to 3.3.9 in /docs (#487) 2024-10-28 20:41:16 +00:00
dependabot[bot]
2fb63059b3 Bump mvdan.cc/sh/v3 from 3.9.0 to 3.10.0 (#485) 2024-10-22 04:23:31 +00:00
dependabot[bot]
e0fcbd27e5 Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity (#483) 2024-10-15 04:45:35 +00:00
dependabot[bot]
f4884bf190 Bump github.com/minio/minio-go/v7 from 7.0.77 to 7.0.78 (#482) 2024-10-15 04:26:31 +00:00
dependabot[bot]
52787a1e42 Bump github.com/minio/minio-go/v7 from 7.0.76 to 7.0.77 (#479) 2024-10-01 04:43:46 +00:00
dependabot[bot]
6e08ae7c39 Bump github.com/Azure/azure-sdk-for-go/sdk/storage/azblob (#477) 2024-09-24 05:40:41 +00:00
dependabot[bot]
0183db831b Bump github.com/klauspost/compress from 1.17.9 to 1.17.10 (#476) 2024-09-24 05:22:26 +00:00
dependabot[bot]
f481fda848 Bump github.com/docker/cli (#475) 2024-09-24 05:22:06 +00:00
shalafi99
f4cf4173e6 Documentation update for DROPBOX_REMOTE_PATH environment variable (#473)
* Update set-up-dropbox.md

Updated text for explanation of DROPBOX_REMOTE_PATH environment variable usage accordingly to how the Dropbox App was scoped during creation.

* Update set-up-dropbox.md

Minor style edit

* Update index.md

Replaced /Apps/my-test-app/some_subdir with /somedir in example value for DROPBOX_REMOTE_PATH environment variable under "Backing up to Dropbox" section, to align with updates done to related "how-to" text
2024-09-18 20:43:54 +02:00
dependabot[bot]
681983608f Bump github.com/docker/cli (#470) 2024-09-10 05:35:58 +00:00
dependabot[bot]
45335ffb67 Bump golang.org/x/oauth2 from 0.22.0 to 0.23.0 (#469) 2024-09-10 05:35:34 +00:00
dependabot[bot]
01a595607d Bump github.com/docker/cli (#467) 2024-09-03 05:00:46 +00:00
dependabot[bot]
119391e8df Bump github.com/minio/minio-go/v7 from 7.0.75 to 7.0.76 (#464) 2024-08-27 05:27:41 +00:00
dependabot[bot]
dd5f7f5b66 Bump rexml from 3.3.3 to 3.3.6 in /docs (#463) 2024-08-23 05:23:04 +00:00
dependabot[bot]
c54a5bef5f Update to use Go 1.23 (#462)
* Bump golang from 1.22-alpine to 1.23-alpine

Bumps golang from 1.22-alpine to 1.23-alpine.

---
updated-dependencies:
- dependency-name: golang
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* Use Go 1.23 throughout

* Update golangci-lint

* Fix complaint raised by linter

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Frederik Ring <frederik.ring@gmail.com>
2024-08-20 11:17:49 +02:00
dependabot[bot]
8fac9608ff Bump github.com/docker/cli (#461) 2024-08-20 04:53:30 +00:00
dependabot[bot]
3ee40b6422 Bump mvdan.cc/sh/v3 from 3.8.0 to 3.9.0 (#460) 2024-08-20 04:53:06 +00:00
Frederik Ring
8b5c9a494f Exclude legacy docs page from navigation 2024-08-19 22:50:26 +02:00
nick comer
44ad3bbda2 feat: allow backups to be encrypted with age (#432)
GPG is known to have usability issues and is generally cumbersome to
use. age [0] is a modern alternative to GPG that is designed by a
cryptographer that has worked and continues to work on Golang's crypto
packages for years.

Allowing age to be used to encrypt backups dramatically simplifies the
backup process.

[0]: https://age-encryption.org/
2024-08-19 22:49:49 +02:00
dependabot[bot]
74e065cbb9 Bump github.com/minio/minio-go/v7 from 7.0.74 to 7.0.75 (#458) 2024-08-13 04:05:47 +00:00
Lennart
8a64da4b0b Feature: PGP Asymmetric Encryption (#456)
* feat: asym encryption

* tests

* docs

* refactor

* logs & errs

* comment

* Update docs/reference/index.md

use correct env var in example

Co-authored-by: Frederik Ring <frederik.ring@gmail.com>

* Update cmd/backup/encrypt_archive.go

use errwarp for initial error msg

Co-authored-by: Frederik Ring <frederik.ring@gmail.com>

* rm orphaned code in encryption functions

* inline readArmoredKeys

* naming -GPG_PUBLIC_KEYS- to GPG_PUBLIC_KEY_RING

* add eror handling for closing func

* use dynamically generated keys for testing

* rm explicit gpg-agent start

* rm unnecessary private_key export

* pass PASSPHRASE correctly to the decryption command

* capture defer errors

* log & err msg

---------

Co-authored-by: Frederik Ring <frederik.ring@gmail.com>
2024-08-11 10:11:23 +02:00
J. Zebedee
f97ce11734 Add "none" compression type (#457)
* Add "none" compression type

* Add "none" compression to docs

* Use passThroughWriteCloser for "none" compression

* Add test for none compression

---------

Co-authored-by: Frederik Ring <frederik.ring@gmail.com>
2024-08-11 10:11:09 +02:00
Frederik Ring
336e12f874 Add support for Azure storage access tiers (#452) 2024-08-09 15:37:27 +02:00
dependabot[bot]
016c6c8307 Bump golang.org/x/sync from 0.7.0 to 0.8.0 (#454) 2024-08-06 03:33:32 +00:00
dependabot[bot]
e22f317fbb Bump golang.org/x/oauth2 from 0.21.0 to 0.22.0 (#453) 2024-08-06 03:15:49 +00:00
dependabot[bot]
e04bd2f066 Bump rexml from 3.2.8 to 3.3.3 in /docs (#451) 2024-08-02 06:35:44 +00:00
Frederik Ring
c4eeaad813 Bump shoutrrr to version 0.8 (#450) 2024-07-31 21:58:24 +02:00
Frederik Ring
5840f1c5dc Update docker/docker package (#449) 2024-07-31 21:54:25 +02:00
dependabot[bot]
d71b7304c2 Bump github.com/docker/cli (#448) 2024-07-30 05:14:03 +00:00
Frederik Ring
fbc7f85d9f version key in compose file is deprecated (#445) 2024-07-23 20:47:45 +02:00
dependabot[bot]
2af5bdf4d9 Bump github.com/Azure/azure-sdk-for-go/sdk/storage/azblob from 1.2.1 to 1.4.0 (#442) 2024-07-23 18:33:13 +00:00
dependabot[bot]
631ca3e07d Bump github.com/gofrs/flock from 0.12.0 to 0.12.1 (#444) 2024-07-22 21:57:20 +00:00
dependabot[bot]
3d35d7c00e Bump github.com/minio/minio-go/v7 from 7.0.73 to 7.0.74 (#443) 2024-07-22 21:39:21 +00:00
dependabot[bot]
954bde73fb Bump github.com/docker/cli (#441) 2024-07-22 21:39:11 +00:00
dependabot[bot]
ab46e96706 Bump github.com/gofrs/flock from 0.11.0 to 0.12.0 (#439) 2024-07-09 04:21:31 +00:00
dependabot[bot]
ab4ce94534 Bump github.com/minio/minio-go/v7 from 7.0.72 to 7.0.73 (#440) 2024-07-09 04:04:26 +00:00
dependabot[bot]
e4170addb6 Bump github.com/docker/cli from 26.1.4+incompatible to 27.0.3+incompatible (#437)
* Bump github.com/docker/cli

Bumps [github.com/docker/cli](https://github.com/docker/cli) from 26.1.4+incompatible to 27.0.3+incompatible.
- [Commits](https://github.com/docker/cli/compare/v26.1.4...v27.0.3)

---
updated-dependencies:
- dependency-name: github.com/docker/cli
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update all Docker versions to 27

* Swap deprecated methods

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Frederik Ring <frederik.ring@gmail.com>
2024-07-02 21:15:49 +02:00
dependabot[bot]
b8410bbdc5 Bump github.com/gofrs/flock from 0.8.1 to 0.11.0 (#438) 2024-07-02 05:21:06 +00:00
dependabot[bot]
24e1341589 Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity (#435) 2024-06-25 03:41:41 +00:00
dependabot[bot]
3d0286472b Bump github.com/minio/minio-go/v7 from 7.0.71 to 7.0.72 (#434) 2024-06-25 03:41:21 +00:00
dependabot[bot]
bb11ae035b Bump github.com/klauspost/compress from 1.17.8 to 1.17.9 (#431) 2024-06-18 05:09:55 +00:00
dependabot[bot]
9209037ed9 Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity (#430) 2024-06-11 20:45:47 +00:00
dependabot[bot]
2e73dea4f7 Bump github.com/docker/cli (#428) 2024-06-11 05:57:25 +00:00
dependabot[bot]
7dc3ae17e7 Bump github.com/minio/minio-go/v7 from 7.0.70 to 7.0.71 (#427) 2024-06-11 05:57:06 +00:00
dependabot[bot]
9d5ea718a0 Bump golang.org/x/oauth2 from 0.20.0 to 0.21.0 (#426) 2024-06-11 05:56:37 +00:00
dependabot[bot]
272495ae7d Bump alpine from 3.19 to 3.20 (#424) 2024-05-28 04:45:31 +00:00
Frederik Ring
8beb28d4f8 Documentation should mention label visibility restrictions 2024-05-26 10:28:46 +02:00
dependabot[bot]
0ec2e68076 --- (#421) 2024-05-21 04:51:09 +00:00
dependabot[bot]
b85afa6008 Bump rexml from 3.2.6 to 3.2.8 in /docs (#420) 2024-05-17 11:04:07 +00:00
guangwu
4cb47a4818 fix: close backup file (#419) 2024-05-16 09:35:28 +02:00
dependabot[bot]
9b5ba8958d Bump github.com/docker/cli (#418) 2024-05-14 04:37:36 +00:00
dependabot[bot]
0327701e2d Bump golang.org/x/oauth2 from 0.19.0 to 0.20.0 (#416) 2024-05-07 04:13:27 +00:00
dependabot[bot]
58f26ba004 Bump github.com/docker/cli (#415) 2024-05-07 04:12:59 +00:00
dependabot[bot]
f62ef6e05a Bump github.com/minio/minio-go/v7 from 7.0.69 to 7.0.70 (#414) 2024-04-30 11:08:13 +00:00
Frederik Ring
40924434e4 Use up to date version of golangci-lint (#413) 2024-04-26 17:48:00 +02:00
Frederik Ring
e613f6046f Fix issues raised by linter 2024-04-26 17:10:06 +02:00
dependabot[bot]
292d47eb19 Bump github.com/docker/cli from 24.0.9+incompatible to 26.1.0+incompatible (#411)
* Bump github.com/docker/cli

Bumps [github.com/docker/cli](https://github.com/docker/cli) from 24.0.9+incompatible to 26.1.0+incompatible.
- [Commits](https://github.com/docker/cli/compare/v24.0.9...v26.1.0)

---
updated-dependencies:
- dependency-name: github.com/docker/cli
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Upgrade docker/docker to matching version

* Tidy go.mod

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Frederik Ring <frederik.ring@gmail.com>
2024-04-25 17:33:07 +02:00
dependabot[bot]
7637975e3f Bump golang.org/x/net from 0.22.0 to 0.23.0 (#410) 2024-04-19 13:37:08 +00:00
dependabot[bot]
c47a14c53a Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity (#408) 2024-04-16 11:21:42 +00:00
dependabot[bot]
9f795761d6 Bump github.com/klauspost/compress from 1.17.7 to 1.17.8 (#409) 2024-04-16 11:21:21 +00:00
Frederik Ring
f2ef48803c Print stack trace when encountering unexpected panic (#406) 2024-04-15 15:12:10 +02:00
Frederik Ring
8b69566291 Result of query for services is used before handling possible error (#405)
* Result of query for services is used before handling possible error

* Return early when a non-replicated service is matched
2024-04-15 15:08:37 +02:00
Frederik Ring
bf79c913e0 Update test suite image to use Docker 26 (#404) 2024-04-15 13:09:43 +02:00
dependabot[bot]
2f7193aa9b Bump golang.org/x/oauth2 from 0.18.0 to 0.19.0 (#402) 2024-04-09 07:04:13 +00:00
dependabot[bot]
550c4f520f Bump golang.org/x/sync from 0.6.0 to 0.7.0 (#401) 2024-04-09 04:46:24 +00:00
Frederik Ring
1af472077c Update author reference in license statements (#393) 2024-03-15 11:42:22 +01:00
dependabot[bot]
a077f12c11 Bump google.golang.org/protobuf from 1.31.0 to 1.33.0 (#392) 2024-03-14 06:06:22 +00:00
dependabot[bot]
cb5a38a1b7 Bump github.com/minio/minio-go/v7 from 7.0.68 to 7.0.69 (#390) 2024-03-11 22:13:04 +00:00
dependabot[bot]
b8995dbc51 Bump golang.org/x/oauth2 from 0.17.0 to 0.18.0 (#389) 2024-03-11 22:11:37 +00:00
Frederik Ring
baf34ec1f7 Allow authentication using connection string when targeting Azure Blob Storage (#383)
* Allow authentication using connection string when targeting Azure Blob Storage

* Bail on ambiguous configuration
2024-03-08 20:23:30 +01:00
dependabot[bot]
e8562b1785 Bump github.com/minio/minio-go/v7 from 7.0.67 to 7.0.68 (#382) 2024-03-05 05:01:42 +00:00
dependabot[bot]
5d7451410b Bump github.com/ProtonMail/go-crypto from 1.1.0-alpha.0 to 1.1.0-alpha.1 (#381) 2024-03-05 05:00:55 +00:00
Frederik Ring
440bcf76ce Document EXEC_LABEL behavior in conjunction with conf.d 2024-03-04 20:31:11 +01:00
Frederik Ring
2d3e79cf5e Also forward exec output when failing to demultiplex (#379) 2024-03-01 09:18:39 +01:00
Frederik Ring
5abfe5bb39 Swarm mode check fails on non-standard Info responses (#376)
* Swarm mode check fails on non-standard Info responses

* Add unit test

* Remove balena tests, add note to docs
2024-02-27 21:12:36 +00:00
dependabot[bot]
6c8b0ccce5 Bump github.com/klauspost/compress from 1.17.6 to 1.17.7 (#377) 2024-02-27 05:57:17 +00:00
Hendrik Niefeld
f4c61125af Update README.md 2024-02-24 20:21:00 +01:00
85 changed files with 1299 additions and 1162 deletions

3
.github/FUNDING.yml vendored
View File

@@ -1,3 +0,0 @@
github: offen
patreon: offen

View File

@@ -39,7 +39,7 @@ jobs:
env: env:
JEKYLL_ENV: production JEKYLL_ENV: production
- name: Upload artifact - name: Upload artifact
uses: actions/upload-pages-artifact@v1 uses: actions/upload-pages-artifact@v3
with: with:
path: 'docs/_site/' path: 'docs/_site/'
@@ -52,4 +52,4 @@ jobs:
steps: steps:
- name: Deploy to GitHub Pages - name: Deploy to GitHub Pages
id: deployment id: deployment
uses: actions/deploy-pages@v1 uses: actions/deploy-pages@v4

View File

@@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-go@v5 - uses: actions/setup-go@v5
with: with:
go-version: '1.22' go-version: '1.24'
cache: false cache: false
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@v3 uses: golangci/golangci-lint-action@v3
@@ -26,7 +26,7 @@ jobs:
# Require: The version of golangci-lint to use. # Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54 version: v1.64
# Optional: working directory, useful for monorepos # Optional: working directory, useful for monorepos
# working-directory: somedir # working-directory: somedir

View File

@@ -14,7 +14,7 @@ jobs:
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v4 uses: actions/setup-go@v4
with: with:
go-version: '1.22.x' go-version: '1.24.x'
- name: Install dependencies - name: Install dependencies
run: go mod download run: go mod download
- name: Test with the Go CLI - name: Test with the Go CLI

View File

@@ -5,4 +5,5 @@ linters:
- staticcheck - staticcheck
- govet - govet
output: output:
format: github-actions formats:
- format: colored-line-number

View File

@@ -1,7 +1,7 @@
# Copyright 2021 - Offen Authors <hioffen@posteo.de> # Copyright 2022 - offen.software <hioffen@posteo.de>
# SPDX-License-Identifier: MPL-2.0 # SPDX-License-Identifier: MPL-2.0
FROM golang:1.22-alpine as builder FROM golang:1.24-alpine AS builder
WORKDIR /app WORKDIR /app
COPY . . COPY . .
@@ -9,7 +9,7 @@ RUN go mod download
WORKDIR /app/cmd/backup WORKDIR /app/cmd/backup
RUN go build -o backup . RUN go build -o backup .
FROM alpine:3.19 FROM alpine:3.21
WORKDIR /root WORKDIR /root

View File

@@ -1,5 +1,5 @@
<a href="https://www.offen.dev/"> <a href="https://www.offen.software/">
<img src="https://offen.github.io/press-kit/offen-material/gfx-GitHub-Offen-logo.svg" alt="Offen logo" title="Offen" width="150px"/> <img src="https://offen.github.io/press-kit/avatars/avatar-OS-header.svg" alt="offen.software logo" title="offen.software" width="60px"/>
</a> </a>
# docker-volume-backup # docker-volume-backup
@@ -76,4 +76,9 @@ docker run --rm \
offen/docker-volume-backup:v2 offen/docker-volume-backup:v2
``` ```
Alternatively, pass a `--env-file` in order to use a full config as described below. Alternatively, pass a `--env-file` in order to use a full config as described [in the docs](https://offen.github.io/docker-volume-backup/reference/).
---
Copyright &copy; 2024 <a target="_blank" href="https://www.offen.software">offen.software</a> and contributors.
Distributed under the <a href="https://github.com/offen/docker-volume-backup/tree/main/LICENSE">MPL-2.0 License</a>.

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
// Portions of this file are taken from package `targz`, Copyright (c) 2014 Fredrik Wallgren // Portions of this file are taken from package `targz`, Copyright (c) 2014 Fredrik Wallgren
@@ -22,8 +22,7 @@ import (
) )
func createArchive(files []string, inputFilePath, outputFilePath string, compression string, compressionConcurrency int) error { func createArchive(files []string, inputFilePath, outputFilePath string, compression string, compressionConcurrency int) error {
inputFilePath = stripTrailingSlashes(inputFilePath) _, outputFilePath, err := makeAbsolute(stripTrailingSlashes(inputFilePath), outputFilePath)
inputFilePath, outputFilePath, err := makeAbsolute(inputFilePath, outputFilePath)
if err != nil { if err != nil {
return errwrap.Wrap(err, "error transposing given file paths") return errwrap.Wrap(err, "error transposing given file paths")
} }
@@ -31,7 +30,7 @@ func createArchive(files []string, inputFilePath, outputFilePath string, compres
return errwrap.Wrap(err, "error creating output file path") return errwrap.Wrap(err, "error creating output file path")
} }
if err := compress(files, outputFilePath, filepath.Dir(inputFilePath), compression, compressionConcurrency); err != nil { if err := compress(files, outputFilePath, compression, compressionConcurrency); err != nil {
return errwrap.Wrap(err, "error creating archive") return errwrap.Wrap(err, "error creating archive")
} }
@@ -55,7 +54,7 @@ func makeAbsolute(inputFilePath, outputFilePath string) (string, string, error)
return inputFilePath, outputFilePath, err return inputFilePath, outputFilePath, err
} }
func compress(paths []string, outFilePath, subPath string, algo string, concurrency int) error { func compress(paths []string, outFilePath, algo string, concurrency int) error {
file, err := os.Create(outFilePath) file, err := os.Create(outFilePath)
if err != nil { if err != nil {
return errwrap.Wrap(err, "error creating out file") return errwrap.Wrap(err, "error creating out file")
@@ -94,6 +93,8 @@ func compress(paths []string, outFilePath, subPath string, algo string, concurre
func getCompressionWriter(file *os.File, algo string, concurrency int) (io.WriteCloser, error) { func getCompressionWriter(file *os.File, algo string, concurrency int) (io.WriteCloser, error) {
switch algo { switch algo {
case "none":
return &passThroughWriteCloser{file}, nil
case "gz": case "gz":
w, err := pgzip.NewWriterLevel(file, 5) w, err := pgzip.NewWriterLevel(file, 5)
if err != nil { if err != nil {
@@ -166,3 +167,15 @@ func writeTarball(path string, tarWriter *tar.Writer, prefix string) error {
return nil return nil
} }
type passThroughWriteCloser struct {
target io.WriteCloser
}
func (p *passThroughWriteCloser) Write(b []byte) (int, error) {
return p.target.Write(b)
}
func (p *passThroughWriteCloser) Close() error {
return nil
}

View File

@@ -1,4 +1,4 @@
// Copyright 2024 - Offen Authors <hioffen@posteo.de> // Copyright 2024 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main
@@ -131,12 +131,8 @@ func (c *command) schedule(strategy configStrategy) error {
c.logger.Warn( c.logger.Warn(
fmt.Sprintf("Scheduled cron expression %s will never run, is this intentional?", config.BackupCronExpression), fmt.Sprintf("Scheduled cron expression %s will never run, is this intentional?", config.BackupCronExpression),
) )
if err != nil {
return errwrap.Wrap(err, "error scheduling")
}
c.schedules = append(c.schedules, id)
} }
c.schedules = append(c.schedules, id)
} }
return nil return nil

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main
@@ -47,6 +47,9 @@ type Config struct {
BackupExcludeRegexp RegexpDecoder `split_words:"true"` BackupExcludeRegexp RegexpDecoder `split_words:"true"`
BackupSkipBackendsFromPrune []string `split_words:"true"` BackupSkipBackendsFromPrune []string `split_words:"true"`
GpgPassphrase string `split_words:"true"` GpgPassphrase string `split_words:"true"`
GpgPublicKeyRing string `split_words:"true"`
AgePassphrase string `split_words:"true"`
AgePublicKeys []string `split_words:"true"`
NotificationURLs []string `envconfig:"NOTIFICATION_URLS"` NotificationURLs []string `envconfig:"NOTIFICATION_URLS"`
NotificationLevel string `split_words:"true" default:"error"` NotificationLevel string `split_words:"true" default:"error"`
EmailNotificationRecipient string `split_words:"true"` EmailNotificationRecipient string `split_words:"true"`
@@ -72,9 +75,11 @@ type Config struct {
LockTimeout time.Duration `split_words:"true" default:"60m"` LockTimeout time.Duration `split_words:"true" default:"60m"`
AzureStorageAccountName string `split_words:"true"` AzureStorageAccountName string `split_words:"true"`
AzureStoragePrimaryAccountKey string `split_words:"true"` AzureStoragePrimaryAccountKey string `split_words:"true"`
AzureStorageConnectionString string `split_words:"true"`
AzureStorageContainerName string `split_words:"true"` AzureStorageContainerName string `split_words:"true"`
AzureStoragePath string `split_words:"true"` AzureStoragePath string `split_words:"true"`
AzureStorageEndpoint string `split_words:"true" default:"https://{{ .AccountName }}.blob.core.windows.net/"` AzureStorageEndpoint string `split_words:"true" default:"https://{{ .AccountName }}.blob.core.windows.net/"`
AzureStorageAccessTier string `split_words:"true"`
DropboxEndpoint string `split_words:"true" default:"https://api.dropbox.com/"` DropboxEndpoint string `split_words:"true" default:"https://api.dropbox.com/"`
DropboxOAuth2Endpoint string `envconfig:"DROPBOX_OAUTH2_ENDPOINT" default:"https://api.dropbox.com/"` DropboxOAuth2Endpoint string `envconfig:"DROPBOX_OAUTH2_ENDPOINT" default:"https://api.dropbox.com/"`
DropboxRefreshToken string `split_words:"true"` DropboxRefreshToken string `split_words:"true"`
@@ -90,7 +95,7 @@ type CompressionType string
func (c *CompressionType) Decode(v string) error { func (c *CompressionType) Decode(v string) error {
switch v { switch v {
case "gz", "zst": case "none", "gz", "zst":
*c = CompressionType(v) *c = CompressionType(v)
return nil return nil
default: default:

View File

@@ -1,4 +1,4 @@
// Copyright 2024 - Offen Authors <hioffen@posteo.de> // Copyright 2024 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main

View File

@@ -1,4 +1,4 @@
// Copyright 2024 - Offen Authors <hioffen@posteo.de> // Copyright 2024 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main

View File

@@ -1,4 +1,4 @@
// Copyright 2024 - Offen Authors <hioffen@posteo.de> // Copyright 2024 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main

View File

@@ -1,64 +1,226 @@
// Copyright 2024 - Offen Authors <hioffen@posteo.de> // Copyright 2024 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main
import ( import (
"bytes"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
"path" "path"
"strings"
"filippo.io/age"
"filippo.io/age/agessh"
"github.com/ProtonMail/go-crypto/openpgp/armor"
openpgp "github.com/ProtonMail/go-crypto/openpgp/v2" openpgp "github.com/ProtonMail/go-crypto/openpgp/v2"
"github.com/offen/docker-volume-backup/internal/errwrap" "github.com/offen/docker-volume-backup/internal/errwrap"
) )
// encryptArchive encrypts the backup file using PGP and the configured passphrase. func countTrue(b ...bool) int {
// In case no passphrase is given it returns early, leaving the backup file c := int(0)
for _, v := range b {
if v {
c++
}
}
return c
}
// encryptArchive encrypts the backup file using PGP and the configured passphrase or publickey(s).
// In case no passphrase or publickey is given it returns early, leaving the backup file
// untouched. // untouched.
func (s *script) encryptArchive() error { func (s *script) encryptArchive() error {
if s.c.GpgPassphrase == "" { useGPGSymmetric := s.c.GpgPassphrase != ""
useGPGAsymmetric := s.c.GpgPublicKeyRing != ""
useAgeSymmetric := s.c.AgePassphrase != ""
useAgeAsymmetric := len(s.c.AgePublicKeys) > 0
switch nconfigured := countTrue(
useGPGSymmetric,
useGPGAsymmetric,
useAgeSymmetric,
useAgeAsymmetric,
); nconfigured {
case 0:
return nil return nil
case 1:
// ok!
default:
return fmt.Errorf(
"error in selecting archive encryption method: expected 0 or 1 to be configured, %d methods are configured",
nconfigured,
)
} }
gpgFile := fmt.Sprintf("%s.gpg", s.file) if useGPGSymmetric {
return s.encryptWithGPGSymmetric()
} else if useGPGAsymmetric {
return s.encryptWithGPGAsymmetric()
} else if useAgeSymmetric || useAgeAsymmetric {
ar, err := s.getConfiguredAgeRecipients()
if err != nil {
return errwrap.Wrap(err, "failed to get configured age recipients")
}
return s.encryptWithAge(ar)
}
return nil
}
func (s *script) getConfiguredAgeRecipients() ([]age.Recipient, error) {
if s.c.AgePassphrase == "" && len(s.c.AgePublicKeys) == 0 {
return nil, fmt.Errorf("no age recipients configured")
}
recipients := []age.Recipient{}
if len(s.c.AgePublicKeys) > 0 {
for _, pk := range s.c.AgePublicKeys {
pkr, err := parseAgeRecipient(pk)
if err != nil {
return nil, errwrap.Wrap(err, "failed to parse age public key")
}
recipients = append(recipients, pkr)
}
}
if s.c.AgePassphrase != "" {
if len(recipients) != 0 {
return nil, fmt.Errorf("age encryption must only be enabled via passphrase or public key, not both")
}
r, err := age.NewScryptRecipient(s.c.AgePassphrase)
if err != nil {
return nil, errwrap.Wrap(err, "failed to create scrypt identity from age passphrase")
}
recipients = append(recipients, r)
}
return recipients, nil
}
func parseAgeRecipient(arg string) (age.Recipient, error) {
// This logic is adapted from what the age CLI is doing
// stripping some special cases
switch {
case strings.HasPrefix(arg, "age1"):
return age.ParseX25519Recipient(arg)
case strings.HasPrefix(arg, "ssh-"):
return agessh.ParseRecipient(arg)
}
return nil, fmt.Errorf("unknown recipient type: %q", arg)
}
func (s *script) encryptWithAge(rec []age.Recipient) error {
return s.doEncrypt("age", func(ciphertextWriter io.Writer) (io.WriteCloser, error) {
return age.Encrypt(ciphertextWriter, rec...)
})
}
func (s *script) encryptWithGPGSymmetric() error {
return s.doEncrypt("gpg", func(ciphertextWriter io.Writer) (io.WriteCloser, error) {
_, name := path.Split(s.file)
return openpgp.SymmetricallyEncrypt(ciphertextWriter, []byte(s.c.GpgPassphrase), &openpgp.FileHints{
FileName: name,
}, nil)
})
}
type closeAllWriter struct {
io.Writer
closers []io.Closer
}
func (c *closeAllWriter) Close() (err error) {
for _, cl := range c.closers {
err = errors.Join(err, cl.Close())
}
return
}
var _ io.WriteCloser = (*closeAllWriter)(nil)
func (s *script) encryptWithGPGAsymmetric() error {
return s.doEncrypt("gpg", func(ciphertextWriter io.Writer) (_ io.WriteCloser, outerr error) {
entityList, err := openpgp.ReadArmoredKeyRing(bytes.NewReader([]byte(s.c.GpgPublicKeyRing)))
if err != nil {
return nil, errwrap.Wrap(err, "error parsing armored keyring")
}
armoredWriter, err := armor.Encode(ciphertextWriter, "PGP MESSAGE", nil)
if err != nil {
return nil, errwrap.Wrap(err, "error preparing encryption")
}
defer func() {
if outerr != nil {
_ = armoredWriter.Close()
}
}()
_, name := path.Split(s.file)
encWriter, err := openpgp.Encrypt(armoredWriter, entityList, nil, nil, &openpgp.FileHints{
FileName: name,
}, nil)
if err != nil {
return nil, err
}
return &closeAllWriter{
Writer: encWriter,
closers: []io.Closer{encWriter, armoredWriter},
}, nil
})
}
func (s *script) doEncrypt(
extension string,
encryptor func(ciphertextWriter io.Writer) (io.WriteCloser, error),
) (outerr error) {
encFile := fmt.Sprintf("%s.%s", s.file, extension)
s.registerHook(hookLevelPlumbing, func(error) error { s.registerHook(hookLevelPlumbing, func(error) error {
if err := remove(gpgFile); err != nil { if err := remove(encFile); err != nil {
return errwrap.Wrap(err, "error removing gpg file") return errwrap.Wrap(err, "error removing encrypted file")
} }
s.logger.Info( s.logger.Info(
fmt.Sprintf("Removed GPG file `%s`.", gpgFile), fmt.Sprintf("Removed encrypted file `%s`.", encFile),
) )
return nil return nil
}) })
outFile, err := os.Create(gpgFile) outFile, err := os.Create(encFile)
if err != nil { if err != nil {
return errwrap.Wrap(err, "error opening out file") return errwrap.Wrap(err, "error opening out file")
} }
defer outFile.Close() defer func() {
if err := outFile.Close(); err != nil {
outerr = errors.Join(outerr, errwrap.Wrap(err, "error closing out file"))
}
}()
_, name := path.Split(s.file) dst, err := encryptor(outFile)
dst, err := openpgp.SymmetricallyEncrypt(outFile, []byte(s.c.GpgPassphrase), &openpgp.FileHints{
FileName: name,
}, nil)
if err != nil { if err != nil {
return errwrap.Wrap(err, "error encrypting backup file") return errwrap.Wrap(err, "error encrypting backup file")
} }
defer dst.Close() defer func() {
if err := dst.Close(); err != nil {
outerr = errors.Join(outerr, errwrap.Wrap(err, "error closing encrypted backup file"))
}
}()
src, err := os.Open(s.file) src, err := os.Open(s.file)
if err != nil { if err != nil {
return errwrap.Wrap(err, fmt.Sprintf("error opening backup file `%s`", s.file)) return errwrap.Wrap(err, fmt.Sprintf("error opening backup file %q", s.file))
} }
defer func() {
if err := src.Close(); err != nil {
outerr = errors.Join(outerr, errwrap.Wrap(err, "error closing backup file"))
}
}()
if _, err := io.Copy(dst, src); err != nil { if _, err := io.Copy(dst, src); err != nil {
return errwrap.Wrap(err, "error writing ciphertext to file") return errwrap.Wrap(err, "error writing ciphertext to file")
} }
s.file = gpgFile s.file = encFile
s.logger.Info( s.logger.Info(
fmt.Sprintf("Encrypted backup using given passphrase, saving as `%s`.", s.file), fmt.Sprintf("Encrypted backup using %q, saving as %q", extension, s.file),
) )
return nil
return
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
// Portions of this file are taken and adapted from `moby`, Copyright 2012-2017 Docker, Inc. // Portions of this file are taken and adapted from `moby`, Copyright 2012-2017 Docker, Inc.
@@ -16,7 +16,7 @@ import (
"strings" "strings"
"github.com/cosiner/argv" "github.com/cosiner/argv"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
"github.com/offen/docker-volume-backup/internal/errwrap" "github.com/offen/docker-volume-backup/internal/errwrap"
@@ -24,11 +24,19 @@ import (
) )
func (s *script) exec(containerRef string, command string, user string) ([]byte, []byte, error) { func (s *script) exec(containerRef string, command string, user string) ([]byte, []byte, error) {
args, _ := argv.Argv(command, nil, nil) args, err := argv.Argv(command, nil, nil)
if err != nil {
return nil, nil, errwrap.Wrap(err, fmt.Sprintf("error parsing argv from '%s'", command))
}
if len(args) == 0 {
return nil, nil, errwrap.Wrap(nil, "received unexpected empty command")
}
commandEnv := []string{ commandEnv := []string{
fmt.Sprintf("COMMAND_RUNTIME_ARCHIVE_FILEPATH=%s", s.file), fmt.Sprintf("COMMAND_RUNTIME_ARCHIVE_FILEPATH=%s", s.file),
} }
execID, err := s.cli.ContainerExecCreate(context.Background(), containerRef, types.ExecConfig{
execID, err := s.cli.ContainerExecCreate(context.Background(), containerRef, container.ExecOptions{
Cmd: args[0], Cmd: args[0],
AttachStdin: true, AttachStdin: true,
AttachStderr: true, AttachStderr: true,
@@ -39,21 +47,29 @@ func (s *script) exec(containerRef string, command string, user string) ([]byte,
return nil, nil, errwrap.Wrap(err, "error creating container exec") return nil, nil, errwrap.Wrap(err, "error creating container exec")
} }
resp, err := s.cli.ContainerExecAttach(context.Background(), execID.ID, types.ExecStartCheck{}) resp, err := s.cli.ContainerExecAttach(context.Background(), execID.ID, container.ExecStartOptions{})
if err != nil { if err != nil {
return nil, nil, errwrap.Wrap(err, "error attaching container exec") return nil, nil, errwrap.Wrap(err, "error attaching container exec")
} }
defer resp.Close() defer resp.Close()
var outBuf, errBuf bytes.Buffer var outBuf, errBuf, fullRespBuf bytes.Buffer
outputDone := make(chan error) outputDone := make(chan error)
tee := io.TeeReader(resp.Reader, &fullRespBuf)
go func() { go func() {
_, err := stdcopy.StdCopy(&outBuf, &errBuf, resp.Reader) _, err := stdcopy.StdCopy(&outBuf, &errBuf, tee)
outputDone <- err outputDone <- err
}() }()
if err := <-outputDone; err != nil { if err := <-outputDone; err != nil {
if body, bErr := io.ReadAll(&fullRespBuf); bErr == nil {
// if possible, try to append the exec output to the error
// as it's likely to be more relevant for users than the error from
// calling stdcopy.Copy
err = errwrap.Wrap(errors.New(string(body)), err.Error())
}
return nil, nil, errwrap.Wrap(err, "error demultiplexing output") return nil, nil, errwrap.Wrap(err, "error demultiplexing output")
} }
@@ -88,7 +104,7 @@ func (s *script) runLabeledCommands(label string) error {
Value: fmt.Sprintf("docker-volume-backup.exec-label=%s", s.c.ExecLabel), Value: fmt.Sprintf("docker-volume-backup.exec-label=%s", s.c.ExecLabel),
}) })
} }
containersWithCommand, err := s.cli.ContainerList(context.Background(), types.ContainerListOptions{ containersWithCommand, err := s.cli.ContainerList(context.Background(), container.ListOptions{
Filters: filters.NewArgs(f...), Filters: filters.NewArgs(f...),
}) })
if err != nil { if err != nil {
@@ -101,7 +117,7 @@ func (s *script) runLabeledCommands(label string) error {
Key: "label", Key: "label",
Value: "docker-volume-backup.exec-pre", Value: "docker-volume-backup.exec-pre",
} }
deprecatedContainers, err := s.cli.ContainerList(context.Background(), types.ContainerListOptions{ deprecatedContainers, err := s.cli.ContainerList(context.Background(), container.ListOptions{
Filters: filters.NewArgs(f...), Filters: filters.NewArgs(f...),
}) })
if err != nil { if err != nil {
@@ -118,7 +134,7 @@ func (s *script) runLabeledCommands(label string) error {
Key: "label", Key: "label",
Value: "docker-volume-backup.exec-post", Value: "docker-volume-backup.exec-post",
} }
deprecatedContainers, err := s.cli.ContainerList(context.Background(), types.ContainerListOptions{ deprecatedContainers, err := s.cli.ContainerList(context.Background(), container.ListOptions{
Filters: filters.NewArgs(f...), Filters: filters.NewArgs(f...),
}) })
if err != nil { if err != nil {

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main

View File

@@ -1,4 +1,4 @@
// Copyright 2021-2022 - Offen Authors <hioffen@posteo.de> // Copyright 2021-2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main

View File

@@ -1,4 +1,4 @@
// Copyright 2024 - Offen Authors <hioffen@posteo.de> // Copyright 2024 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main

View File

@@ -1,4 +1,4 @@
// Copyright 2024 - Offen Authors <hioffen@posteo.de> // Copyright 2024 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main

View File

@@ -1,4 +1,4 @@
// Copyright 2024 - Offen Authors <hioffen@posteo.de> // Copyright 2024 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main
@@ -6,6 +6,7 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"runtime/debug"
"github.com/offen/docker-volume-backup/internal/errwrap" "github.com/offen/docker-volume-backup/internal/errwrap"
) )
@@ -17,6 +18,7 @@ import (
func runScript(c *Config) (err error) { func runScript(c *Config) (err error) {
defer func() { defer func() {
if derr := recover(); derr != nil { if derr := recover(); derr != nil {
fmt.Printf("%s: %s\n", derr, debug.Stack())
asErr, ok := derr.(error) asErr, ok := derr.(error)
if ok { if ok {
err = errwrap.Wrap(asErr, "unexpected panic running script") err = errwrap.Wrap(asErr, "unexpected panic running script")

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main
@@ -86,7 +86,12 @@ func (s *script) init() error {
var bf bytes.Buffer var bf bytes.Buffer
if tErr := tmplFileName.Execute(&bf, map[string]string{ if tErr := tmplFileName.Execute(&bf, map[string]string{
"Extension": fmt.Sprintf("tar.%s", s.c.BackupCompression), "Extension": func() string {
if s.c.BackupCompression == "none" {
return "tar"
}
return fmt.Sprintf("tar.%s", s.c.BackupCompression)
}(),
}); tErr != nil { }); tErr != nil {
return errwrap.Wrap(tErr, "error executing backup file extension template") return errwrap.Wrap(tErr, "error executing backup file extension template")
} }
@@ -193,6 +198,8 @@ func (s *script) init() error {
PrimaryAccountKey: s.c.AzureStoragePrimaryAccountKey, PrimaryAccountKey: s.c.AzureStoragePrimaryAccountKey,
Endpoint: s.c.AzureStorageEndpoint, Endpoint: s.c.AzureStorageEndpoint,
RemotePath: s.c.AzureStoragePath, RemotePath: s.c.AzureStoragePath,
ConnectionString: s.c.AzureStorageConnectionString,
AccessTier: s.c.AzureStorageAccessTier,
} }
azureBackend, err := azure.NewStorageBackend(azureConfig, logFunc) azureBackend, err := azure.NewStorageBackend(azureConfig, logFunc)
if err != nil { if err != nil {

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main

View File

@@ -1,4 +1,4 @@
// Copyright 2024 - Offen Authors <hioffen@posteo.de> // Copyright 2024 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main
@@ -14,9 +14,11 @@ import (
"github.com/docker/cli/cli/command/service/progress" "github.com/docker/cli/cli/command/service/progress"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
ctr "github.com/docker/docker/api/types/container" ctr "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/offen/docker-volume-backup/internal/errwrap" "github.com/offen/docker-volume-backup/internal/errwrap"
) )
@@ -65,7 +67,7 @@ func awaitContainerCountForService(cli *client.Client, serviceID string, count i
), ),
) )
case <-poll.C: case <-poll.C:
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{ containers, err := cli.ContainerList(context.Background(), container.ListOptions{
Filters: filters.NewArgs(filters.KeyValuePair{ Filters: filters.NewArgs(filters.KeyValuePair{
Key: "label", Key: "label",
Value: fmt.Sprintf("com.docker.swarm.service.id=%s", serviceID), Value: fmt.Sprintf("com.docker.swarm.service.id=%s", serviceID),
@@ -81,6 +83,16 @@ func awaitContainerCountForService(cli *client.Client, serviceID string, count i
} }
} }
func isSwarm(c interface {
Info(context.Context) (system.Info, error)
}) (bool, error) {
info, err := c.Info(context.Background())
if err != nil {
return false, errwrap.Wrap(err, "error getting docker info")
}
return info.Swarm.LocalNodeState != "" && info.Swarm.LocalNodeState != swarm.LocalNodeStateInactive, nil
}
// stopContainersAndServices stops all Docker containers that are marked as to being // stopContainersAndServices stops all Docker containers that are marked as to being
// stopped during the backup and returns a function that can be called to // stopped during the backup and returns a function that can be called to
// restart everything that has been stopped. // restart everything that has been stopped.
@@ -89,11 +101,10 @@ func (s *script) stopContainersAndServices() (func() error, error) {
return noop, nil return noop, nil
} }
dockerInfo, err := s.cli.Info(context.Background()) isDockerSwarm, err := isSwarm(s.cli)
if err != nil { if err != nil {
return noop, errwrap.Wrap(err, "error getting docker info") return noop, errwrap.Wrap(err, "error determining swarm state")
} }
isDockerSwarm := dockerInfo.Swarm.LocalNodeState != "inactive"
labelValue := s.c.BackupStopDuringBackupLabel labelValue := s.c.BackupStopDuringBackupLabel
if s.c.BackupStopContainerLabel != "" { if s.c.BackupStopContainerLabel != "" {
@@ -114,11 +125,11 @@ func (s *script) stopContainersAndServices() (func() error, error) {
labelValue, labelValue,
) )
allContainers, err := s.cli.ContainerList(context.Background(), types.ContainerListOptions{}) allContainers, err := s.cli.ContainerList(context.Background(), container.ListOptions{})
if err != nil { if err != nil {
return noop, errwrap.Wrap(err, "error querying for containers") return noop, errwrap.Wrap(err, "error querying for containers")
} }
containersToStop, err := s.cli.ContainerList(context.Background(), types.ContainerListOptions{ containersToStop, err := s.cli.ContainerList(context.Background(), container.ListOptions{
Filters: filters.NewArgs(filters.KeyValuePair{ Filters: filters.NewArgs(filters.KeyValuePair{
Key: "label", Key: "label",
Value: filterMatchLabel, Value: filterMatchLabel,
@@ -142,15 +153,21 @@ func (s *script) stopContainersAndServices() (func() error, error) {
}), }),
Status: true, Status: true,
}) })
if err != nil {
return noop, errwrap.Wrap(err, "error querying for services to scale down")
}
for _, s := range matchingServices { for _, s := range matchingServices {
if s.Spec.Mode.Replicated == nil {
return noop, errwrap.Wrap(
nil,
fmt.Sprintf("only replicated services can be restarted, but found a label on service %s", s.Spec.Name),
)
}
servicesToScaleDown = append(servicesToScaleDown, handledSwarmService{ servicesToScaleDown = append(servicesToScaleDown, handledSwarmService{
serviceID: s.ID, serviceID: s.ID,
initialReplicaCount: *s.Spec.Mode.Replicated.Replicas, initialReplicaCount: *s.Spec.Mode.Replicated.Replicas,
}) })
} }
if err != nil {
return noop, errwrap.Wrap(err, "error querying for services to scale down")
}
} }
if len(containersToStop) == 0 && len(servicesToScaleDown) == 0 { if len(containersToStop) == 0 && len(servicesToScaleDown) == 0 {
@@ -294,7 +311,7 @@ func (s *script) stopContainersAndServices() (func() error, error) {
continue continue
} }
if err := s.cli.ContainerStart(context.Background(), container.ID, types.ContainerStartOptions{}); err != nil { if err := s.cli.ContainerStart(context.Background(), container.ID, ctr.StartOptions{}); err != nil {
restartErrors = append(restartErrors, err) restartErrors = append(restartErrors, err)
} }
} }

View File

@@ -0,0 +1,85 @@
package main
import (
"context"
"errors"
"testing"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/system"
)
type mockInfoClient struct {
result system.Info
err error
}
func (m *mockInfoClient) Info(context.Context) (system.Info, error) {
return m.result, m.err
}
func TestIsSwarm(t *testing.T) {
tests := []struct {
name string
client *mockInfoClient
expected bool
expectError bool
}{
{
"swarm",
&mockInfoClient{
result: system.Info{
Swarm: swarm.Info{
LocalNodeState: swarm.LocalNodeStateActive,
},
},
},
true,
false,
},
{
"compose",
&mockInfoClient{
result: system.Info{
Swarm: swarm.Info{
LocalNodeState: swarm.LocalNodeStateInactive,
},
},
},
false,
false,
},
{
"balena",
&mockInfoClient{
result: system.Info{
Swarm: swarm.Info{
LocalNodeState: "",
},
},
},
false,
false,
},
{
"error",
&mockInfoClient{
err: errors.New("the dinosaurs escaped"),
},
false,
true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result, err := isSwarm(test.client)
if (err != nil) != test.expectError {
t.Errorf("Unexpected error value %v", err)
}
if test.expected != result {
t.Errorf("Expected %v, got %v", test.expected, result)
}
})
}
}

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package main package main

View File

@@ -59,7 +59,7 @@ GEM
rb-fsevent (0.11.2) rb-fsevent (0.11.2)
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
rexml (3.2.6) rexml (3.3.9)
rouge (3.30.0) rouge (3.30.0)
safe_yaml (1.0.5) safe_yaml (1.0.5)
sassc (2.4.0) sassc (2.4.0)

View File

@@ -30,6 +30,6 @@ nav_external_links:
url: https://github.com/offen/docker-volume-backup url: https://github.com/offen/docker-volume-backup
footer_content: >- footer_content: >-
Copyright &copy; 2021 Offen Authors and contributors. Copyright &copy; 2024 <a target="_blank" href="https://www.offen.software">offen.software</a> and contributors.
Distributed under the <a href="https://github.com/offen/docker-volume-backup/tree/main/LICENSE">MPL-2.0 License.</a><br> Distributed under the <a href="https://github.com/offen/docker-volume-backup/tree/main/LICENSE">MPL-2.0 License.</a><br>
Something missing, unclear or not working? Open <a href="https://github.com/offen/docker-volume-backup/issues">an issue</a>. Something missing, unclear or not working? Open <a href="https://github.com/offen/docker-volume-backup/issues">an issue</a>.

View File

@@ -3,15 +3,7 @@ title: Encrypt backups using GPG
layout: default layout: default
parent: How Tos parent: How Tos
nav_order: 7 nav_order: 7
nav_exclude: true
--- ---
# Encrypt backups using GPG See: [Encrypt Backups](encrypt-backups)
The image supports encrypting backups using GPG out of the box.
In case a `GPG_PASSPHRASE` environment variable is set, the backup archive will be encrypted using the given key and saved as a `.gpg` file instead.
Assuming you have `gpg` installed, you can decrypt such a backup using (your OS will prompt for the passphrase before decryption can happen):
```console
gpg -o backup.tar.gz -d backup.tar.gz.gpg
```

View File

@@ -0,0 +1,32 @@
---
title: Encrypting backups
layout: default
parent: How Tos
nav_order: 7
---
# Encrypting backups
The image supports encrypting backups using one of two available methods: **GPG** or **[age](https://age-encryption.org/)**
## Using GPG encryption
In case a `GPG_PASSPHRASE` or `GPG_PUBLIC_KEY_RING` environment variable is set, the backup archive will be encrypted using the given key and saved as a `.gpg` file instead.
Assuming you have `gpg` installed, you can decrypt such a backup using (your OS will prompt for the passphrase before decryption can happen):
```console
gpg -o backup.tar.gz -d backup.tar.gz.gpg
```
## Using age encryption
{: .note }
Even though the `age` CLI tools supports encryption using SSH keys, this is not supported by this tool.
`AGE_PUBLIC_KEYS` currently expects `age` keys to be given.
age allows backups to be encrypted with either a symmetric key (password) or a public key. One of those options are available for use.
Given `AGE_PASSPHRASE` being provided, the backup archive will be encrypted with the passphrase and saved as a `.age` file instead. Refer to age documentation for how to properly decrypt.
Given `AGE_PUBLIC_KEYS` being provided (allowing multiple by separating each public key with `,`), the backup archive will be encrypted with the provided public keys. It will also result in the archive being saved as a `.age` file.

View File

@@ -33,7 +33,7 @@ services:
- docker-volume-backup.copy-post=/bin/sh -c 'rsync $$COMMAND_RUNTIME_ARCHIVE_FILEPATH /destination' - docker-volume-backup.copy-post=/bin/sh -c 'rsync $$COMMAND_RUNTIME_ARCHIVE_FILEPATH /destination'
volumes: volumes:
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
# other services defined here ... # other services defined here ...
volumes: volumes:

View File

@@ -9,6 +9,11 @@ parent: How Tos
In certain scenarios it can be required to run specific commands before and after a backup is taken (e.g. dumping a database). In certain scenarios it can be required to run specific commands before and after a backup is taken (e.g. dumping a database).
When mounting the Docker socket into the `docker-volume-backup` container, you can define pre- and post-commands that will be run in the context of the target container (it is also possible to run commands inside the `docker-volume-backup` container itself using this feature). When mounting the Docker socket into the `docker-volume-backup` container, you can define pre- and post-commands that will be run in the context of the target container (it is also possible to run commands inside the `docker-volume-backup` container itself using this feature).
{: .important }
In a multi-node Swarm setup, commands can currently only be run on the node the `offen/docker-volume-backup` container is running on.
Labeled containers on other nodes are not visible to the backup command.
Such commands are defined by specifying the command in a `docker-volume-backup.[step]-[pre|post]` label where `step` can be any of the following phases of a backup lifecycle: Such commands are defined by specifying the command in a `docker-volume-backup.[step]-[pre|post]` label where `step` can be any of the following phases of a backup lifecycle:
- `archive` (the tar archive is created) - `archive` (the tar archive is created)
@@ -46,6 +51,10 @@ If you have more than one `docker-volume-backup` container (possibly across seve
multiple backup schedules, you will need to use `EXEC_LABEL` in the configuration and a `docker-volume-backup.exec-label` label on each multiple backup schedules, you will need to use `EXEC_LABEL` in the configuration and a `docker-volume-backup.exec-label` label on each
container using custom commands to ensure that the commands are only run by the correct `docker-volume-backup` instance. container using custom commands to ensure that the commands are only run by the correct `docker-volume-backup` instance.
{: .important }
In case you use `EXEC_LABEL` together with configuration mounted from `conf.d` it's important to understand that a distinct `EXEC_LABEL` __should be set in each configuration__.
Else, schedules that do not specify an `EXEC_LABEL` will still trigger commands on all containers with such labels, no matter whether they specify `docker-volume-backup.exec-label` or not.
```yml ```yml
version: '3' version: '3'

View File

@@ -33,5 +33,7 @@ Note: Using the "Generated access token" in the app console is not supported, as
## Other parameters ## Other parameters
Important: If you chose `App folder` access during the creation of your Dropbox app in step 1 above, you can only write in the app's directory! Important: If you chose `App folder` access during the creation of your Dropbox app in step 1 above, `DROPBOX_REMOTE_PATH` will be a relative path under the App folder!
This means, that `DROPBOX_REMOTE_PATH` must start with e.g. `/Apps/YOUR_APP_NAME` or `/Apps/YOUR_APP_NAME/some_sub_dir` (_For example, DROPBOX_REMOTE_PATH=/somedir means the backup file will be uploaded to /Apps/myapp/somedir_)
On the other hand if you chose `Full Dropbox` access, the value for `DROPBOX_REMOTE_PATH` will represent an absolute path inside your Dropbox storage area.
(_Still considering the same example above, the backup file will be uploaded to /somedir in your Dropbox root_)

View File

@@ -25,7 +25,7 @@ services:
Notification backends other than email are also supported. Notification backends other than email are also supported.
Refer to the documentation of [shoutrrr][shoutrrr-docs] to find out about options and configuration. Refer to the documentation of [shoutrrr][shoutrrr-docs] to find out about options and configuration.
[shoutrrr-docs]: https://containrrr.dev/shoutrrr/0.7/services/overview/ [shoutrrr-docs]: https://containrrr.dev/shoutrrr/v0.8/services/overview/
{: .note } {: .note }
If you also want notifications on successful executions, set `NOTIFICATION_LEVEL` to `info`. If you also want notifications on successful executions, set `NOTIFICATION_LEVEL` to `info`.

View File

@@ -88,7 +88,7 @@ docker run --rm \
Alternatively, pass a `--env-file` in order to use a full config as described below. Alternatively, pass a `--env-file` in order to use a full config as described below.
### Available image registries ## Available image registries
This Docker image is published to both Docker Hub and the GitHub container registry. This Docker image is published to both Docker Hub and the GitHub container registry.
Depending on your preferences and needs, you can reference both `offen/docker-volume-backup` as well as `ghcr.io/offen/docker-volume-backup`: Depending on your preferences and needs, you can reference both `offen/docker-volume-backup` as well as `ghcr.io/offen/docker-volume-backup`:
@@ -100,6 +100,11 @@ docker pull ghcr.io/offen/docker-volume-backup:v2
Documentation references Docker Hub, but all examples will work using ghcr.io just as well. Documentation references Docker Hub, but all examples will work using ghcr.io just as well.
## Supported Engines
This tool is developed and tested against the Docker CE engine exclusively.
While it may work against different implementations (e.g. Balena Engine), there are no guarantees about support for non-Docker engines.
## Differences to `jareware/docker-volume-backup` ## Differences to `jareware/docker-volume-backup`
This image is heavily inspired by `jareware/docker-volume-backup`. We decided to publish this image as a simpler and more lightweight alternative because of the following requirements: This image is heavily inspired by `jareware/docker-volume-backup`. We decided to publish this image as a simpler and more lightweight alternative because of the following requirements:

View File

@@ -190,7 +190,7 @@ services:
DROPBOX_REFRESH_TOKEN: REFRESH_KEY # replace DROPBOX_REFRESH_TOKEN: REFRESH_KEY # replace
DROPBOX_APP_KEY: APP_KEY # replace DROPBOX_APP_KEY: APP_KEY # replace
DROPBOX_APP_SECRET: APP_SECRET # replace DROPBOX_APP_SECRET: APP_SECRET # replace
DROPBOX_REMOTE_PATH: /Apps/my-test-app/some_subdir # replace DROPBOX_REMOTE_PATH: /somedir # replace
volumes: volumes:
- data:/backup/my-app-backup:ro - data:/backup/my-app-backup:ro
- /var/run/docker.sock:/var/run/docker.sock:ro - /var/run/docker.sock:/var/run/docker.sock:ro
@@ -289,7 +289,7 @@ volumes:
data: data:
``` ```
## Encrypting your backups using GPG ## Encrypting your backups symmetrically using GPG
```yml ```yml
version: '3' version: '3'
@@ -311,7 +311,34 @@ volumes:
data: data:
``` ```
## Using mysqldump to prepare the backup ## Encrypting your backups asymmetrically using GPG
```yml
version: '3'
services:
# ... define other services using the `data` volume here
backup:
image: offen/docker-volume-backup:v2
environment:
AWS_S3_BUCKET_NAME: backup-bucket
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
GPG_PUBLIC_KEY_RING: |
-----BEGIN PGP PUBLIC KEY BLOCK-----
D/cIHu6GH/0ghlcUVSbgMg5RRI5QKNNKh04uLAPxr75mKwUg0xPUaWgyyrAChVBi
...
-----END PGP PUBLIC KEY BLOCK-----
volumes:
- data:/backup/my-app-backup:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes:
data:
```
## Using mariadb-dump/mysqldump to prepare the backup
```yml ```yml
version: '3' version: '3'
@@ -320,7 +347,7 @@ services:
database: database:
image: mariadb:latest image: mariadb:latest
labels: labels:
- docker-volume-backup.archive-pre=/bin/sh -c 'mysqldump -psecret --all-databases > /tmp/dumps/dump.sql' - docker-volume-backup.archive-pre=/bin/sh -c 'mariadb-dump -psecret --all-databases > /tmp/dumps/dump.sql'
volumes: volumes:
- data:/tmp/dumps - data:/tmp/dumps
backup: backup:
@@ -331,7 +358,7 @@ services:
volumes: volumes:
- ./local:/archive - ./local:/archive
- data:/backup/data:ro - data:/backup/data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
volumes: volumes:
data: data:

View File

@@ -9,7 +9,7 @@ nav_order: 2
Backup targets, schedule and retention are configured using environment variables. Backup targets, schedule and retention are configured using environment variables.
{: .note } {: .note }
You can use any environment variable from below also with a `_FILE` suffix to be able to load the value from a file. As per established convention, you can use any environment variable key from below with a `_FILE` suffix in order to load the value from a file instead.
This is typically useful when using [Docker Secrets](https://docs.docker.com/engine/swarm/secrets/) or similar. This is typically useful when using [Docker Secrets](https://docs.docker.com/engine/swarm/secrets/) or similar.
Note that secrets will not be trimmed of leading or trailing whitespace. Note that secrets will not be trimmed of leading or trailing whitespace.
@@ -17,13 +17,14 @@ Note that secrets will not be trimmed of leading or trailing whitespace.
In case you encounter double quoted values in your runtime configuration you might still be using an [older version of `docker-compose`][compose-issue]. In case you encounter double quoted values in your runtime configuration you might still be using an [older version of `docker-compose`][compose-issue].
You can work around this by either updating `docker-compose` or unquoting your configuration values. You can work around this by either updating `docker-compose` or unquoting your configuration values.
You can populate below template according to your requirements and use it as your `env_file`: You can populate below template according to your requirements and use it as your `env_file`.
The values for each key currently match its default.
{% raw %} {% raw %}
``` ```
########### BACKUP SCHEDULE ########### BACKUP SCHEDULE
# Backups can be run on fixed scheduled that are defined as a cron expression.
# A cron expression represents a set of times, using 5 or 6 space-separated fields. # A cron expression represents a set of times, using 5 or 6 space-separated fields.
# #
# Field name | Mandatory? | Allowed values | Allowed special characters # Field name | Mandatory? | Allowed values | Allowed special characters
@@ -37,35 +38,45 @@ You can populate below template according to your requirements and use it as you
# #
# Month and Day-of-week field values are case insensitive. # Month and Day-of-week field values are case insensitive.
# "SUN", "Sun", and "sun" are equally accepted. # "SUN", "Sun", and "sun" are equally accepted.
# If no value is set, `@daily` will be used.
# If you do not want the cron to ever run, use `0 0 5 31 2 ?`. # If you do not want the cron to ever run, use `0 0 5 31 2 ?`.
# Refer to sites like <https://crontab.guru> for help.
# If no value is set, `@daily` will be used, which runs every
# day at midnight.
# BACKUP_CRON_EXPRESSION="0 2 * * *" # BACKUP_CRON_EXPRESSION="@daily"
# ---
# The compression algorithm used in conjunction with tar. # The compression algorithm used in conjunction with tar.
# Valid options are: "gz" (Gzip) and "zst" (Zstd). # Valid options are: "gz" (Gzip), "zst" (Zstd) or "none" (tar only).
# Note that the selection affects the file extension. # Default is "gz". Note that the selection affects the file extension.
# BACKUP_COMPRESSION="gz" # BACKUP_COMPRESSION="gz"
# ---
# Parallelism level for "gz" (Gzip) compression. # Parallelism level for "gz" (Gzip) compression.
# Defines how many blocks of data are concurrently processed. # Defines how many blocks of data are concurrently processed.
# Higher values result in faster compression. No effect on decompression # Higher values result in faster compression. No effect on decompression
# Default = 1. Setting this to 0 will use all available threads. # Default = 1. Setting this to 0 will use all available threads.
# GZIP_PARALLELISM=1 # GZIP_PARALLELISM="1"
# The name of the backup file including the extension. # ---
# Format verbs will be replaced as in `strftime`. Omitting them
# The desired name of the backup file including the extension.
# Format verbs will be replaced as in `strftime`. Omitting all verbs
# will result in the same filename for every backup run, which means previous # will result in the same filename for every backup run, which means previous
# versions will be overwritten on subsequent runs. # versions will be overwritten on subsequent runs.
# Extension can be defined literally or via "{{ .Extension }}" template, # Extension can be defined literally or via "{{ .Extension }}" template,
# in which case it will become either "tar.gz" or "tar.zst" (depending # in which case it will become either "tar.gz", "tar.zst" or ".tar" (depending
# on your BACKUP_COMPRESSION setting). # on your BACKUP_COMPRESSION setting).
# The default results in filenames like: `backup-2021-08-29T04-00-00.tar.gz`. # The default results in filenames like: `backup-2021-08-29T04-00-00.tar.gz`.
# BACKUP_FILENAME="backup-%Y-%m-%dT%H-%M-%S.{{ .Extension }}" # BACKUP_FILENAME="backup-%Y-%m-%dT%H-%M-%S.{{ .Extension }}"
# ---
# Setting BACKUP_FILENAME_EXPAND to true allows for environment variable # Setting BACKUP_FILENAME_EXPAND to true allows for environment variable
# placeholders in BACKUP_FILENAME, BACKUP_LATEST_SYMLINK and in # placeholders in BACKUP_FILENAME, BACKUP_LATEST_SYMLINK and in
# BACKUP_PRUNING_PREFIX that will get expanded at runtime, # BACKUP_PRUNING_PREFIX that will get expanded at runtime,
@@ -76,10 +87,15 @@ You can populate below template according to your requirements and use it as you
# BACKUP_FILENAME_EXPAND="true" # BACKUP_FILENAME_EXPAND="true"
# ---
# When storing local backups, a symlink to the latest backup can be created # When storing local backups, a symlink to the latest backup can be created
# in case a value is given for this key. This has no effect on remote backups. # in case a value is given for this key. This has no effect on remote backups.
# Example: "backup.latest.tar.gz"
# BACKUP_LATEST_SYMLINK="backup.latest.tar.gz" # BACKUP_LATEST_SYMLINK=""
# ---
# ************************************************************************ # ************************************************************************
# The BACKUP_FROM_SNAPSHOT option has been deprecated and will be removed # The BACKUP_FROM_SNAPSHOT option has been deprecated and will be removed
@@ -93,191 +109,285 @@ You can populate below template according to your requirements and use it as you
# BACKUP_FROM_SNAPSHOT="false" # BACKUP_FROM_SNAPSHOT="false"
# By default, the `/backup` directory inside the container will be backed up. # ---
# In case you need to use a custom location, set `BACKUP_SOURCES`.
# BACKUP_SOURCES="/other/location" # By default, the contents of the `/backup` directory inside the container
# will be backed up. In case you need to use a custom location, set `BACKUP_SOURCES`.
# Example: "/other/location"
# When given, all files in BACKUP_SOURCES whose full path matches the given # BACKUP_SOURCES="/backup"
# ---
# When a value is given, all files in BACKUP_SOURCES whose full path matches the
# regular expression will be excluded from the archive. Regular Expressions # regular expression will be excluded from the archive. Regular Expressions
# can be used as from the Go standard library https://pkg.go.dev/regexp # can be used as from the Go standard library https://pkg.go.dev/regexp
# Example: "\.log$"
# BACKUP_EXCLUDE_REGEXP="\.log$" # BACKUP_EXCLUDE_REGEXP=""
# ---
# Exclude one or many storage backends from the pruning process. # Exclude one or many storage backends from the pruning process.
# Available backends are: S3, WebDAV, SSH, Local, Dropbox, Azure
# E.g. with one backend excluded: BACKUP_SKIP_BACKENDS_FROM_PRUNE=s3 # E.g. with one backend excluded: BACKUP_SKIP_BACKENDS_FROM_PRUNE=s3
# E.g. with multiple backends excluded: BACKUP_SKIP_BACKENDS_FROM_PRUNE=s3,webdav # E.g. with multiple backends excluded: BACKUP_SKIP_BACKENDS_FROM_PRUNE=s3,webdav
# Available backends are: S3, WebDAV, SSH, Local, Dropbox, Azure # Note: The names of the backends are case insensitive.
# Note: The name of the backends is case insensitive.
# Default: All backends get pruned. # Default: All backends get pruned.
# BACKUP_SKIP_BACKENDS_FROM_PRUNE= # BACKUP_SKIP_BACKENDS_FROM_PRUNE=""
########### BACKUP STORAGE ########### S3 COMPATIBLE STORAGE
# The name of the remote bucket that should be used for storing backups. If # The name of the remote bucket that should be used for storing backups. If
# this is not set, no remote backups will be stored. # this is not set, no remote backups will be stored.
# Example: "backup-bucket"
# AWS_S3_BUCKET_NAME="backup-bucket" # AWS_S3_BUCKET_NAME=""
# ---
# If you want to store the backup in a non-root location on your bucket # If you want to store the backup in a non-root location on your bucket
# you can provide a path. The path must not contain a leading slash. # you can provide a path. The path must not contain a leading slash.
# Example: "my/backup/location"
# AWS_S3_PATH="my/backup/location" # AWS_S3_PATH=""
# ---
# Define credentials for authenticating against the backup storage and a bucket # Define credentials for authenticating against the backup storage and a bucket
# name. Although all of these keys are `AWS`-prefixed, the setup can be used # name. Although all of these keys are `AWS`-prefixed, the setup can be used
# with any S3 compatible storage. # with any S3 compatible storage.
# AWS_ACCESS_KEY_ID="<xxx>" # AWS_ACCESS_KEY_ID=""
# AWS_SECRET_ACCESS_KEY="<xxx>" # AWS_SECRET_ACCESS_KEY=""
# ---
# Instead of providing static credentials, you can also use IAM instance profiles # Instead of providing static credentials, you can also use IAM instance profiles
# or similar to provide authentication. Some possible configuration options on AWS: # or similar to provide authentication. Some possible configuration options on AWS:
# - EC2: http://169.254.169.254 # - EC2: http://169.254.169.254
# - ECS: http://169.254.170.2 # - ECS: http://169.254.170.2
# AWS_IAM_ROLE_ENDPOINT="http://169.254.169.254" # AWS_IAM_ROLE_ENDPOINT=""
# ---
# This is the FQDN of your storage server, e.g. `storage.example.com`. # This is the FQDN of your storage server, e.g. `storage.example.com`.
# Do not set this when working against AWS S3 (the default value is # If you need to set a specific (non-https) protocol, you will need to use the option below.
# `s3.amazonaws.com`). If you need to set a specific (non-https) protocol, you # The default value points to the standard AWS S3 endpoint.
# will need to use the option below.
# AWS_ENDPOINT="storage.example.com" # AWS_ENDPOINT="s3.amazonaws.com"
# The protocol to be used when communicating with your storage server. # ---
# The protocol to be used when communicating with your S3 storage server.
# Defaults to "https". You can set this to "http" when communicating with # Defaults to "https". You can set this to "http" when communicating with
# a different Docker container on the same host for example. # a different Docker container in the same virtual network for example.
# AWS_ENDPOINT_PROTO="https" # AWS_ENDPOINT_PROTO="https"
# ---
# Setting this variable to `true` will disable verification of # Setting this variable to `true` will disable verification of
# SSL certificates for AWS_ENDPOINT. You shouldn't use this unless you use # SSL certificates for AWS_ENDPOINT. You shouldn't use this unless you use
# self-signed certificates for your remote storage backend. This can only be # self-signed certificates for your remote storage backend. This can only be
# used when AWS_ENDPOINT_PROTO is set to `https`. # used when AWS_ENDPOINT_PROTO is set to `https`.
# AWS_ENDPOINT_INSECURE="true" # AWS_ENDPOINT_INSECURE="false"
# ---
# If you wish to use self signed certificates your S3 server, you can pass # If you wish to use self signed certificates your S3 server, you can pass
# the location of a PEM encoded CA certificate and it will be used for # the location of a PEM encoded CA certificate and it will be used for
# validating your certificates. # validating your certificates. Alternatively, pass a PEM encoded string
# Alternatively, pass a PEM encoded string containing the certificate. # containing the certificate.
# Example: "/path/to/cert.pem"
# AWS_ENDPOINT_CA_CERT="/path/to/cert.pem" # AWS_ENDPOINT_CA_CERT=""
# Setting this variable will change the S3 storage class header. # ---
# Defaults to "STANDARD", you can set this value according to your needs.
# AWS_STORAGE_CLASS="GLACIER" # Setting a value for this key will change the S3 storage class header.
# Default behavior is to use the standard class when no value is given.
# Example: "GLACIER"
# AWS_STORAGE_CLASS=""
# ---
# Setting this variable will change the S3 default part size for the copy step. # Setting this variable will change the S3 default part size for the copy step.
# This value is useful when you want to upload large files. # This value is useful when you want to upload large files.
# NB : While using Scaleway as S3 provider, be aware that the parts counter is set to 1.000. # NB: While using Scaleway as S3 provider, be aware that the parts counter is set to 1.000.
# While Minio uses a hard coded value to 10.000. As a workaround, try to set a higher value. # While Minio uses a hard coded value to 10.000. As a workaround, try to set a higher value.
# Defaults to "16" (MB) if unset (from minio), you can set this value according to your needs. # Defaults to "16" (MB) if unset (from minio), you can set this value according to your needs.
# The unit is in MB and an integer. # The unit is in MB and an integer.
# AWS_PART_SIZE=16 # AWS_PART_SIZE="16"
# You can also backup files to any WebDAV server: ########### WEBDAV STORAGE
# The URL of the remote WebDAV server # The URL of the remote WebDAV server
# Example: "https://webdav.example.com"
# WEBDAV_URL="https://webdav.example.com" # WEBDAV_URL=""
# ---
# The Directory to place the backups to on the WebDAV server. # The Directory to place the backups to on the WebDAV server.
# If the path is not present on the server it will be created. # If the path is not present on the server it will be created.
# Example: "/my/directory/"
# WEBDAV_PATH="/my/directory/" # WEBDAV_PATH=""
# ---
# The username for the WebDAV server # The username for the WebDAV server
# Example: "user"
# WEBDAV_USERNAME="user" # WEBDAV_USERNAME=""
# ---
# The password for the WebDAV server # The password for the WebDAV server
# Example: "password"
# WEBDAV_PASSWORD="password" # WEBDAV_PASSWORD=""
# Setting this variable to `true` will disable verification of # ---
# Setting this variable to "true" will disable verification of
# SSL certificates for WEBDAV_URL. You shouldn't use this unless you use # SSL certificates for WEBDAV_URL. You shouldn't use this unless you use
# self-signed certificates for your remote storage backend. # self-signed certificates for your remote storage backend.
# WEBDAV_URL_INSECURE="true" # WEBDAV_URL_INSECURE="false"
# You can also backup files to any SSH server: ########### SSH/SFTP STORAGE
# The URL of the remote SSH server # The FQDN of the remote SSH server
# Example: "server.local"
# SSH_HOST_NAME="server.local" # SSH_HOST_NAME=""
# ---
# The port of the remote SSH server # The port of the remote SSH server
# Optional variable default value is `22`
# SSH_PORT=2222 # SSH_PORT="22"
# ---
# The Directory to place the backups to on the SSH server. # The Directory to place the backups to on the SSH server.
# Example: "/home/user/backups"
# SSH_REMOTE_PATH="/my/directory/" # SSH_REMOTE_PATH=""
# ---
# The username for the SSH server # The username for the SSH server
# Example: "user"
# SSH_USER="user" # SSH_USER=""
# ---
# The password for the SSH server # The password for the SSH server
# Example: "password"
# SSH_PASSWORD="password" # SSH_PASSWORD=""
# The private key path in container for SSH server # ---
# Default value: /root/.ssh/id_rsa
# If file is mounted to /root/.ssh/id_rsa path it will be used. Non-RSA keys will # The private key path in container for SSH server.
# also work. # Consumers can mount a file into /root/.ssh/id_rsa (or the respective value)
# in order to have it being used. Non-RSA keys (e.g. ed25519) will also work.
# SSH_IDENTITY_FILE="/root/.ssh/id_rsa" # SSH_IDENTITY_FILE="/root/.ssh/id_rsa"
# The passphrase for the identity file # ---
# SSH_IDENTITY_PASSPHRASE="pass" # The passphrase for the identity file if applicable
# Example: "pass"
# SSH_IDENTITY_PASSPHRASE=""
########### AZURE BLOB STORAGE
# The credential's account name when using Azure Blob Storage. This has to be # The credential's account name when using Azure Blob Storage. This has to be
# set when using Azure Blob Storage. # set when using Azure Blob Storage.
# Example: "account-name"
# AZURE_STORAGE_ACCOUNT_NAME="account-name" # AZURE_STORAGE_ACCOUNT_NAME=""
# ---
# The credential's primary account key when using Azure Blob Storage. If this # The credential's primary account key when using Azure Blob Storage. If this
# is not given, the command tries to fall back to using a managed identity. # is not given, the command tries to fall back to using a connection string
# (if given) or a managed identity (if neither is set).
# AZURE_STORAGE_PRIMARY_ACCOUNT_KEY="<xxx>" # AZURE_STORAGE_PRIMARY_ACCOUNT_KEY=""
# ---
# A connection string for accessing Azure Blob Storage. If this
# is not given, the command tries to fall back to using a primary account key
# (if given) or a managed identity (if neither is set).
# AZURE_STORAGE_CONNECTION_STRING=""
# ---
# The container name when using Azure Blob Storage. # The container name when using Azure Blob Storage.
# Example: "container-name"
# AZURE_STORAGE_CONTAINER_NAME="container-name" # AZURE_STORAGE_CONTAINER_NAME=""
# ---
# The service endpoint when using Azure Blob Storage. This is a template that # The service endpoint when using Azure Blob Storage. This is a template that
# can be passed the account name as shown in the default value below. # can be passed the account name as shown in the default value below.
# AZURE_STORAGE_ENDPOINT="https://{{ .AccountName }}.blob.core.windows.net/" # AZURE_STORAGE_ENDPOINT="https://{{ .AccountName }}.blob.core.windows.net/"
# ---
# The access tier when using Azure Blob Storage. Possible values are
# https://github.com/Azure/azure-sdk-for-go/blob/sdk/storage/azblob/v1.3.2/sdk/storage/azblob/internal/generated/zz_constants.go#L14-L30
# Example: "Cold"
# AZURE_STORAGE_ACCESS_TIER=""
########### DROPBOX STORAGE
# Absolute remote path in your Dropbox where the backups shall be stored. # Absolute remote path in your Dropbox where the backups shall be stored.
# Note: Use your app's subpath in Dropbox, if it doesn't have global access. # Note: Use your app's subpath in Dropbox, if it doesn't have global access.
# Consulte the README for further information. # Consult the README for further information.
# Example: "/my/directory"
# DROPBOX_REMOTE_PATH="/my/directory" # DROPBOX_REMOTE_PATH=""
# Number of concurrent chunked uploads for Dropbox. # ---
# Values above 6 usually result in no enhancements.
# DROPBOX_CONCURRENCY_LEVEL="6"
# App key and app secret from your app created at https://www.dropbox.com/developers/apps/info # App key and app secret from your app created at https://www.dropbox.com/developers/apps/info
# DROPBOX_APP_KEY="" # DROPBOX_APP_KEY=""
# DROPBOX_APP_SECRET="" # DROPBOX_APP_SECRET=""
# ---
# Number of concurrent chunked uploads for Dropbox.
# Values above 6 usually result in no enhancements.
# DROPBOX_CONCURRENCY_LEVEL="6"
# ---
# Refresh token to request new short-lived tokens (OAuth2). Consult README to see how to get one. # Refresh token to request new short-lived tokens (OAuth2). Consult README to see how to get one.
# DROPBOX_REFRESH_TOKEN="" # DROPBOX_REFRESH_TOKEN=""
########### LOCAL FILE STORAGE
# In addition to storing backups remotely, you can also keep local copies. # In addition to storing backups remotely, you can also keep local copies.
# Pass a container-local path to store your backups if needed. You also need to # Pass a container-local path to store your backups if needed. You also need to
# mount a local folder or Docker volume into that location (`/archive` # mount a local folder or Docker volume into that location (`/archive`
@@ -299,10 +409,12 @@ You can populate below template according to your requirements and use it as you
# for such files, or to configure BACKUP_PRUNING_PREFIX to limit # for such files, or to configure BACKUP_PRUNING_PREFIX to limit
# removal to certain files. # removal to certain files.
# Define this value to enable automatic rotation of old backups. The value # Pass zero or a positive integer value to enable automatic rotation of
# declares the number of days for which a backup is kept. # old backups. The value declares the number of days for which a backup is kept.
# BACKUP_RETENTION_DAYS="7" # BACKUP_RETENTION_DAYS="-1"
# ---
# In case the duration a backup takes fluctuates noticeably in your setup # In case the duration a backup takes fluctuates noticeably in your setup
# you can adjust this setting to make sure there are no race conditions # you can adjust this setting to make sure there are no race conditions
@@ -314,6 +426,8 @@ You can populate below template according to your requirements and use it as you
# BACKUP_PRUNING_LEEWAY="1m" # BACKUP_PRUNING_LEEWAY="1m"
# ---
# In case your target bucket or directory contains other files than the ones # In case your target bucket or directory contains other files than the ones
# managed by this container, you can limit the scope of rotation by setting # managed by this container, you can limit the scope of rotation by setting
# a prefix value. This would usually be the non-parametrized part of your # a prefix value. This would usually be the non-parametrized part of your
@@ -321,13 +435,37 @@ You can populate below template according to your requirements and use it as you
# you can set BACKUP_PRUNING_PREFIX to `db-backup-` and make sure # you can set BACKUP_PRUNING_PREFIX to `db-backup-` and make sure
# unrelated files are not affected by the rotation mechanism. # unrelated files are not affected by the rotation mechanism.
# BACKUP_PRUNING_PREFIX="backup-" # BACKUP_PRUNING_PREFIX=""
########### BACKUP ENCRYPTION ########### BACKUP ENCRYPTION
# Backups can be encrypted using gpg in case a passphrase is given. # All of the encryption options are mutually exclusive. Provide a single option
# for the encryption scheme of your choice.
# GPG_PASSPHRASE="<xxx>" # Backups can be encrypted symmetrically using gpg in case a passphrase is given.
# GPG_PASSPHRASE=""
# ---
# Backups can be encrypted asymmetrically using gpg in case publickeys are given.
# You can use pipe syntax to pass a multiline value.
# GPG_PUBLIC_KEY_RING=""
# ---
# Backups can be encrypted symmetrically using age in case a passphrase is given.
# AGE_PASSPHRASE=""
# ---
# Backups can be encrypted asymmetrically using age in case publickeys are given.
# Multiple keys need to be provided as a comma separated list. Right now, this
# supports `age` and `ssh` keys
# AGE_PUBLIC_KEYS=""
########### STOPPING CONTAINERS AND SERVICES DURING BACKUP ########### STOPPING CONTAINERS AND SERVICES DURING BACKUP
@@ -335,18 +473,17 @@ You can populate below template according to your requirements and use it as you
# `docker-volume-backup.stop-during-backup` label. By default, all containers and # `docker-volume-backup.stop-during-backup` label. By default, all containers and
# services that are labeled with `true` will be stopped. If you need more fine # services that are labeled with `true` will be stopped. If you need more fine
# grained control (e.g. when running multiple containers based on this image), # grained control (e.g. when running multiple containers based on this image),
# you can override this default by specifying a different value here. # you can override this default by specifying a different string value here.
# BACKUP_STOP_DURING_BACKUP_LABEL="service1" # BACKUP_STOP_DURING_BACKUP_LABEL="true"
# When trying to scale down Docker Swarm services, give up after # When trying to scale down Docker Swarm services, give up after
# the specified amount of time in case the service has not converged yet. # the specified amount of time in case the service has not converged yet.
# In case you need to adjust this timeout, supply a duration # In case you need to adjust this timeout, supply a duration
# value as per https://pkg.go.dev/time#ParseDuration to `BACKUP_STOP_SERVICE_TIMEOUT`. # value as per https://pkg.go.dev/time#ParseDuration to `BACKUP_STOP_SERVICE_TIMEOUT`.
# Defaults to 5 minutes.
# BACKUP_STOP_SERVICE_TIMEOUT="5m" # BACKUP_STOP_SERVICE_TIMEOUT="5m"
########### EXECUTING COMMANDS IN CONTAINERS PRE/POST BACKUP ########### EXECUTING COMMANDS IN CONTAINERS DURING THE BACKUP LIFECYCLE
# It is possible to define commands to be run in any container before and after # It is possible to define commands to be run in any container before and after
# a backup is conducted. The commands themselves are defined in labels like # a backup is conducted. The commands themselves are defined in labels like
@@ -357,29 +494,34 @@ You can populate below template according to your requirements and use it as you
# is configured to be "true", command execution output will be forwarded to # is configured to be "true", command execution output will be forwarded to
# the backup container's stdout and stderr. # the backup container's stdout and stderr.
# EXEC_FORWARD_OUTPUT="true" # EXEC_FORWARD_OUTPUT="false"
# ---
# Without any further configuration, all commands defined in labels will be # Without any further configuration, all commands defined in labels will be
# run before and after a backup. If you need more fine grained control, you # run before and after a backup. If you need more fine grained control, you
# can use this option to set a label that will be used for narrowing down # can use this option to set a label that will be used for narrowing down
# the set of eligible containers. When set, an eligible container will also need # the set of eligible containers. E.g. when setting this to `database`,
# to be labeled as `docker-volume-backup.exec-label=database`. # an eligible container will also need to be labeled as `docker-volume-backup.exec-label=database`.
# EXEC_LABEL="database" # EXEC_LABEL=""
########### NOTIFICATIONS ########### NOTIFICATIONS
# Notifications (email, Slack, etc.) can be sent out when a backup run finishes. # Notifications (email, Slack, etc.) can be sent out when a backup run finishes.
# Configuration is provided as a comma-separated list of URLs as consumed # Configuration is provided as a comma-separated list of URLs as consumed
# by `shoutrrr`: https://containrrr.dev/shoutrrr/0.7/services/overview/ # by `shoutrrr`: https://containrrr.dev/shoutrrr/v0.8/services/overview/
# The content of such notifications can be customized. Dedicated documentation # The content of such notifications can be customized. Dedicated documentation
# on how to do this can be found in the README. When providing multiple URLs or # on how to do this can be found in the README. When providing multiple URLs or
# an URL that contains a comma, the values can be URL encoded to avoid ambiguities. # an URL that contains a comma, the values can be URL encoded to avoid ambiguities.
# The below URL demonstrates how to send an email using the provided SMTP # The following example URL demonstrates how to send an email using the provided SMTP
# configuration and credentials. # configuration and credentials.
# Example: "smtp://username:password@host:587/?fromAddress=sender@example.com&toAddresses=recipient@example.com"
# NOTIFICATION_URLS=smtp://username:password@host:587/?fromAddress=sender@example.com&toAddresses=recipient@example.com # NOTIFICATION_URLS=""
# ---
# By default, notifications would only be sent out when a backup run fails # By default, notifications would only be sent out when a backup run fails
# To receive notifications for every run, set `NOTIFICATION_LEVEL` to `info` # To receive notifications for every run, set `NOTIFICATION_LEVEL` to `info`
@@ -391,8 +533,9 @@ You can populate below template according to your requirements and use it as you
# If you are interfacing with Docker via TCP you can set the Docker host here # If you are interfacing with Docker via TCP you can set the Docker host here
# instead of mounting the Docker socket as a volume. This is unset by default. # instead of mounting the Docker socket as a volume. This is unset by default.
# Example: "tcp://docker_socket_proxy:2375"
# DOCKER_HOST="tcp://docker_socket_proxy:2375" # DOCKER_HOST=""
########### LOCK_TIMEOUT ########### LOCK_TIMEOUT
@@ -419,20 +562,25 @@ You can populate below template according to your requirements and use it as you
# The recipient(s) of the notification. Supply a comma separated list # The recipient(s) of the notification. Supply a comma separated list
# of addresses if you want to notify multiple recipients. If this is # of addresses if you want to notify multiple recipients. If this is
# not set, no emails will be sent. # not set, no emails will be sent.
# Example: "you@example.com"
# EMAIL_NOTIFICATION_RECIPIENT="you@example.com" # EMAIL_NOTIFICATION_RECIPIENT=""
# The "From" header of the sent email. Defaults to `noreply@nohost`. # ---
# EMAIL_NOTIFICATION_SENDER="no-reply@example.com" # The "From" header of the sent email.
# Example: "no-reply@example.com"
# EMAIL_NOTIFICATION_SENDER="noreply@nohost"
# ---
# Configuration and credentials for the SMTP server to be used. # Configuration and credentials for the SMTP server to be used.
# EMAIL_SMTP_PORT defaults to 587.
# EMAIL_SMTP_HOST="posteo.de" # EMAIL_SMTP_HOST=""
# EMAIL_SMTP_PASSWORD="<xxx>" # EMAIL_SMTP_PASSWORD=""
# EMAIL_SMTP_USERNAME="no-reply@example.com" # EMAIL_SMTP_USERNAME=""
# EMAIL_SMTP_PORT="<port>" # EMAIL_SMTP_PORT="587"
``` ```
{% endraw %} {% endraw %}

90
go.mod
View File

@@ -1,78 +1,88 @@
module github.com/offen/docker-volume-backup module github.com/offen/docker-volume-backup
go 1.22 go 1.24
require ( require (
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 filippo.io/age v1.2.1
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.1 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2
github.com/containrrr/shoutrrr v0.7.1 github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.6.0
github.com/containrrr/shoutrrr v0.8.0
github.com/cosiner/argv v0.1.0 github.com/cosiner/argv v0.1.0
github.com/docker/cli v24.0.9+incompatible github.com/docker/cli v28.0.0+incompatible
github.com/docker/docker v24.0.7+incompatible github.com/docker/docker v27.1.1+incompatible
github.com/gofrs/flock v0.8.1 github.com/gofrs/flock v0.12.1
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
github.com/klauspost/compress v1.17.6 github.com/klauspost/compress v1.18.0
github.com/leekchan/timeutil v0.0.0-20150802142658-28917288c48d github.com/leekchan/timeutil v0.0.0-20150802142658-28917288c48d
github.com/minio/minio-go/v7 v7.0.67 github.com/minio/minio-go/v7 v7.0.87
github.com/offen/envconfig v1.5.0 github.com/offen/envconfig v1.5.0
github.com/otiai10/copy v1.14.0 github.com/otiai10/copy v1.14.1
github.com/pkg/sftp v1.13.6 github.com/pkg/sftp v1.13.7
github.com/robfig/cron/v3 v3.0.1 github.com/robfig/cron/v3 v3.0.1
github.com/studio-b12/gowebdav v0.9.0 github.com/studio-b12/gowebdav v0.10.0
golang.org/x/crypto v0.19.0 golang.org/x/crypto v0.33.0
golang.org/x/oauth2 v0.17.0 golang.org/x/oauth2 v0.27.0
golang.org/x/sync v0.6.0 golang.org/x/sync v0.11.0
mvdan.cc/sh/v3 v3.10.0
) )
require ( require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/cloudflare/circl v1.3.7 // indirect github.com/cloudflare/circl v1.3.7 // indirect
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect github.com/containerd/log v0.1.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect github.com/distribution/reference v0.6.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/minio/crc64nvme v1.0.1 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/otiai10/mint v1.6.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/otel/sdk v1.26.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/protobuf v1.31.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
mvdan.cc/sh/v3 v3.8.0 // indirect
) )
require ( require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.3.3 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.0 github.com/ProtonMail/go-crypto v1.1.0-alpha.1
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect
github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.5 github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.5
github.com/dustin/go-humanize v1.0.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/color v1.13.0 // indirect github.com/fatih/color v1.17.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.5.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/klauspost/pgzip v1.2.6 github.com/klauspost/pgzip v1.2.6
github.com/kr/fs v0.1.0 // indirect github.com/kr/fs v0.1.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/minio/md5-simd v1.1.2 // indirect github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd // indirect github.com/moby/term v0.0.0-20200312100748-672ec06f55cd // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect github.com/morikuni/aec v1.0.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/rs/xid v1.5.0 // indirect github.com/rs/xid v1.6.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect github.com/sirupsen/logrus v1.9.3 // indirect
golang.org/x/net v0.21.0 // indirect golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.17.0 // indirect golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.14.0 // indirect golang.org/x/text v0.22.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gotest.tools/v3 v3.0.3 // indirect gotest.tools/v3 v3.0.3 // indirect
) )

965
go.sum

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
// Copyright 2024 - Offen Authors <hioffen@posteo.de> // Copyright 2024 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package errwrap package errwrap
@@ -21,7 +21,7 @@ func Wrap(err error, msg string) error {
chunks := strings.Split(frame.Function, "/") chunks := strings.Split(frame.Function, "/")
withCaller := fmt.Sprintf("%s: %s", chunks[len(chunks)-1], msg) withCaller := fmt.Sprintf("%s: %s", chunks[len(chunks)-1], msg)
if err == nil { if err == nil {
return fmt.Errorf(withCaller) return errors.New(withCaller)
} }
return fmt.Errorf("%s: %w", withCaller, err) return fmt.Errorf("%s: %w", withCaller, err)
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package azure package azure
@@ -9,6 +9,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
"sync" "sync"
@@ -17,6 +18,8 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container"
"github.com/offen/docker-volume-backup/internal/errwrap" "github.com/offen/docker-volume-backup/internal/errwrap"
"github.com/offen/docker-volume-backup/internal/storage" "github.com/offen/docker-volume-backup/internal/storage"
@@ -24,8 +27,9 @@ import (
type azureBlobStorage struct { type azureBlobStorage struct {
*storage.StorageBackend *storage.StorageBackend
client *azblob.Client client *azblob.Client
containerName string uploadStreamOptions *blockblob.UploadStreamOptions
containerName string
} }
// Config contains values that define the configuration of an Azure Blob Storage. // Config contains values that define the configuration of an Azure Blob Storage.
@@ -33,12 +37,18 @@ type Config struct {
AccountName string AccountName string
ContainerName string ContainerName string
PrimaryAccountKey string PrimaryAccountKey string
ConnectionString string
Endpoint string Endpoint string
RemotePath string RemotePath string
AccessTier string
} }
// NewStorageBackend creates and initializes a new Azure Blob Storage backend. // NewStorageBackend creates and initializes a new Azure Blob Storage backend.
func NewStorageBackend(opts Config, logFunc storage.Log) (storage.Backend, error) { func NewStorageBackend(opts Config, logFunc storage.Log) (storage.Backend, error) {
if opts.PrimaryAccountKey != "" && opts.ConnectionString != "" {
return nil, errwrap.Wrap(nil, "using primary account key and connection string are mutually exclusive")
}
endpointTemplate, err := template.New("endpoint").Parse(opts.Endpoint) endpointTemplate, err := template.New("endpoint").Parse(opts.Endpoint)
if err != nil { if err != nil {
return nil, errwrap.Wrap(err, "error parsing endpoint template") return nil, errwrap.Wrap(err, "error parsing endpoint template")
@@ -58,7 +68,12 @@ func NewStorageBackend(opts Config, logFunc storage.Log) (storage.Backend, error
client, err = azblob.NewClientWithSharedKeyCredential(normalizedEndpoint, cred, nil) client, err = azblob.NewClientWithSharedKeyCredential(normalizedEndpoint, cred, nil)
if err != nil { if err != nil {
return nil, errwrap.Wrap(err, "error creating Azure client") return nil, errwrap.Wrap(err, "error creating azure client from primary account key")
}
} else if opts.ConnectionString != "" {
client, err = azblob.NewClientFromConnectionString(opts.ConnectionString, nil)
if err != nil {
return nil, errwrap.Wrap(err, "error creating azure client from connection string")
} }
} else { } else {
cred, err := azidentity.NewManagedIdentityCredential(nil) cred, err := azidentity.NewManagedIdentityCredential(nil)
@@ -67,13 +82,30 @@ func NewStorageBackend(opts Config, logFunc storage.Log) (storage.Backend, error
} }
client, err = azblob.NewClient(normalizedEndpoint, cred, nil) client, err = azblob.NewClient(normalizedEndpoint, cred, nil)
if err != nil { if err != nil {
return nil, errwrap.Wrap(err, "error creating Azure client") return nil, errwrap.Wrap(err, "error creating azure client from managed identity")
}
}
var uploadStreamOptions *blockblob.UploadStreamOptions
if opts.AccessTier != "" {
var found bool
for _, t := range blob.PossibleAccessTierValues() {
if string(t) == opts.AccessTier {
found = true
uploadStreamOptions = &blockblob.UploadStreamOptions{
AccessTier: &t,
}
}
}
if !found {
return nil, errwrap.Wrap(nil, fmt.Sprintf("%s is not a possible access tier value", opts.AccessTier))
} }
} }
storage := azureBlobStorage{ storage := azureBlobStorage{
client: client, client: client,
containerName: opts.ContainerName, uploadStreamOptions: uploadStreamOptions,
containerName: opts.ContainerName,
StorageBackend: &storage.StorageBackend{ StorageBackend: &storage.StorageBackend{
DestinationPath: opts.RemotePath, DestinationPath: opts.RemotePath,
Log: logFunc, Log: logFunc,
@@ -93,12 +125,13 @@ func (b *azureBlobStorage) Copy(file string) error {
if err != nil { if err != nil {
return errwrap.Wrap(err, fmt.Sprintf("error opening file %s", file)) return errwrap.Wrap(err, fmt.Sprintf("error opening file %s", file))
} }
_, err = b.client.UploadStream( _, err = b.client.UploadStream(
context.Background(), context.Background(),
b.containerName, b.containerName,
filepath.Join(b.DestinationPath, filepath.Base(file)), path.Join(b.DestinationPath, filepath.Base(file)),
fileReader, fileReader,
nil, b.uploadStreamOptions,
) )
if err != nil { if err != nil {
return errwrap.Wrap(err, fmt.Sprintf("error uploading file %s", file)) return errwrap.Wrap(err, fmt.Sprintf("error uploading file %s", file))
@@ -109,7 +142,7 @@ func (b *azureBlobStorage) Copy(file string) error {
// Prune rotates away backups according to the configuration and provided // Prune rotates away backups according to the configuration and provided
// deadline for the Azure Blob storage backend. // deadline for the Azure Blob storage backend.
func (b *azureBlobStorage) Prune(deadline time.Time, pruningPrefix string) (*storage.PruneStats, error) { func (b *azureBlobStorage) Prune(deadline time.Time, pruningPrefix string) (*storage.PruneStats, error) {
lookupPrefix := filepath.Join(b.DestinationPath, pruningPrefix) lookupPrefix := path.Join(b.DestinationPath, pruningPrefix)
pager := b.client.NewListBlobsFlatPager(b.containerName, &container.ListBlobsFlatOptions{ pager := b.client.NewListBlobsFlatPager(b.containerName, &container.ListBlobsFlatOptions{
Prefix: &lookupPrefix, Prefix: &lookupPrefix,
}) })

View File

@@ -7,7 +7,6 @@ import (
"net/url" "net/url"
"os" "os"
"path" "path"
"path/filepath"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -195,7 +194,7 @@ loop:
_, err = b.client.UploadSessionFinish( _, err = b.client.UploadSessionFinish(
files.NewUploadSessionFinishArg( files.NewUploadSessionFinishArg(
files.NewUploadSessionCursor(sessionId, 0), files.NewUploadSessionCursor(sessionId, 0),
files.NewCommitInfo(filepath.Join(b.DestinationPath, name)), files.NewCommitInfo(path.Join(b.DestinationPath, name)),
), nil) ), nil)
if err != nil { if err != nil {
return errwrap.Wrap(err, "error finishing the upload session") return errwrap.Wrap(err, "error finishing the upload session")
@@ -247,7 +246,7 @@ func (b *dropboxStorage) Prune(deadline time.Time, pruningPrefix string) (*stora
pruneErr := b.DoPrune(b.Name(), len(matches), lenCandidates, deadline, func() error { pruneErr := b.DoPrune(b.Name(), len(matches), lenCandidates, deadline, func() error {
for _, match := range matches { for _, match := range matches {
if _, err := b.client.DeleteV2(files.NewDeleteArg(filepath.Join(b.DestinationPath, match.Name))); err != nil { if _, err := b.client.DeleteV2(files.NewDeleteArg(path.Join(b.DestinationPath, match.Name))); err != nil {
return errwrap.Wrap(err, "error removing file from Dropbox storage") return errwrap.Wrap(err, "error removing file from Dropbox storage")
} }
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package local package local
@@ -96,7 +96,7 @@ func (b *localStorage) Prune(deadline time.Time, pruningPrefix string) (*storage
) )
} }
if fi.Mode()&os.ModeSymlink != os.ModeSymlink { if !fi.IsDir() && fi.Mode()&os.ModeSymlink != os.ModeSymlink {
candidates = append(candidates, candidate) candidates = append(candidates, candidate)
} }
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package s3 package s3
@@ -10,7 +10,6 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"path/filepath"
"time" "time"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7"
@@ -124,7 +123,7 @@ func (b *s3Storage) Copy(file string) error {
putObjectOptions.PartSize = uint64(partSize) putObjectOptions.PartSize = uint64(partSize)
} }
if _, err := b.client.FPutObject(context.Background(), b.bucket, filepath.Join(b.DestinationPath, name), file, putObjectOptions); err != nil { if _, err := b.client.FPutObject(context.Background(), b.bucket, path.Join(b.DestinationPath, name), file, putObjectOptions); err != nil {
if errResp := minio.ToErrorResponse(err); errResp.Message != "" { if errResp := minio.ToErrorResponse(err); errResp.Message != "" {
return errwrap.Wrap( return errwrap.Wrap(
nil, nil,
@@ -147,7 +146,7 @@ func (b *s3Storage) Copy(file string) error {
// Prune rotates away backups according to the configuration and provided deadline for the S3/Minio storage backend. // Prune rotates away backups according to the configuration and provided deadline for the S3/Minio storage backend.
func (b *s3Storage) Prune(deadline time.Time, pruningPrefix string) (*storage.PruneStats, error) { func (b *s3Storage) Prune(deadline time.Time, pruningPrefix string) (*storage.PruneStats, error) {
candidates := b.client.ListObjects(context.Background(), b.bucket, minio.ListObjectsOptions{ candidates := b.client.ListObjects(context.Background(), b.bucket, minio.ListObjectsOptions{
Prefix: filepath.Join(b.DestinationPath, pruningPrefix), Prefix: path.Join(b.DestinationPath, pruningPrefix),
Recursive: true, Recursive: true,
}) })

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package ssh package ssh
@@ -8,7 +8,6 @@ import (
"io" "io"
"os" "os"
"path" "path"
"path/filepath"
"strings" "strings"
"time" "time"
@@ -115,7 +114,7 @@ func (b *sshStorage) Copy(file string) error {
} }
defer source.Close() defer source.Close()
destination, err := b.sftpClient.Create(filepath.Join(b.DestinationPath, name)) destination, err := b.sftpClient.Create(path.Join(b.DestinationPath, name))
if err != nil { if err != nil {
return errwrap.Wrap(err, "error creating file") return errwrap.Wrap(err, "error creating file")
} }
@@ -164,24 +163,28 @@ func (b *sshStorage) Prune(deadline time.Time, pruningPrefix string) (*storage.P
} }
var matches []string var matches []string
var numCandidates int
for _, candidate := range candidates { for _, candidate := range candidates {
if !strings.HasPrefix(candidate.Name(), pruningPrefix) { if candidate.IsDir() || !strings.HasPrefix(candidate.Name(), pruningPrefix) {
continue continue
} }
numCandidates++
if candidate.ModTime().Before(deadline) { if candidate.ModTime().Before(deadline) {
matches = append(matches, candidate.Name()) matches = append(matches, candidate.Name())
} }
} }
stats := &storage.PruneStats{ stats := &storage.PruneStats{
Total: uint(len(candidates)), Total: uint(numCandidates),
Pruned: uint(len(matches)), Pruned: uint(len(matches)),
} }
pruneErr := b.DoPrune(b.Name(), len(matches), len(candidates), deadline, func() error { pruneErr := b.DoPrune(b.Name(), len(matches), numCandidates, deadline, func() error {
for _, match := range matches { for _, match := range matches {
if err := b.sftpClient.Remove(filepath.Join(b.DestinationPath, match)); err != nil { p := path.Join(b.DestinationPath, match)
return errwrap.Wrap(err, "error removing file") if err := b.sftpClient.Remove(p); err != nil {
return errwrap.Wrap(err, fmt.Sprintf("error removing file %s", p))
} }
} }
return nil return nil

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package storage package storage

View File

@@ -1,4 +1,4 @@
// Copyright 2022 - Offen Authors <hioffen@posteo.de> // Copyright 2022 - offen.software <hioffen@posteo.de>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
package webdav package webdav
@@ -9,7 +9,6 @@ import (
"net/http" "net/http"
"os" "os"
"path" "path"
"path/filepath"
"strings" "strings"
"time" "time"
@@ -77,7 +76,7 @@ func (b *webDavStorage) Copy(file string) error {
return errwrap.Wrap(err, "error opening the file to be uploaded") return errwrap.Wrap(err, "error opening the file to be uploaded")
} }
if err := b.client.WriteStream(filepath.Join(b.DestinationPath, name), r, 0644); err != nil { if err := b.client.WriteStream(path.Join(b.DestinationPath, name), r, 0644); err != nil {
return errwrap.Wrap(err, "error uploading the file") return errwrap.Wrap(err, "error uploading the file")
} }
b.Log(storage.LogLevelInfo, b.Name(), "Uploaded a copy of backup '%s' to '%s' at path '%s'.", file, b.url, b.DestinationPath) b.Log(storage.LogLevelInfo, b.Name(), "Uploaded a copy of backup '%s' to '%s' at path '%s'.", file, b.url, b.DestinationPath)
@@ -91,26 +90,27 @@ func (b *webDavStorage) Prune(deadline time.Time, pruningPrefix string) (*storag
if err != nil { if err != nil {
return nil, errwrap.Wrap(err, "error looking up candidates from remote storage") return nil, errwrap.Wrap(err, "error looking up candidates from remote storage")
} }
var matches []fs.FileInfo var matches []fs.FileInfo
var lenCandidates int var numCandidates int
for _, candidate := range candidates { for _, candidate := range candidates {
if !strings.HasPrefix(candidate.Name(), pruningPrefix) { if candidate.IsDir() || !strings.HasPrefix(candidate.Name(), pruningPrefix) {
continue continue
} }
lenCandidates++ numCandidates++
if candidate.ModTime().Before(deadline) { if candidate.ModTime().Before(deadline) {
matches = append(matches, candidate) matches = append(matches, candidate)
} }
} }
stats := &storage.PruneStats{ stats := &storage.PruneStats{
Total: uint(lenCandidates), Total: uint(numCandidates),
Pruned: uint(len(matches)), Pruned: uint(len(matches)),
} }
pruneErr := b.DoPrune(b.Name(), len(matches), lenCandidates, deadline, func() error { pruneErr := b.DoPrune(b.Name(), len(matches), numCandidates, deadline, func() error {
for _, match := range matches { for _, match := range matches {
if err := b.client.Remove(filepath.Join(b.DestinationPath, match.Name())); err != nil { if err := b.client.Remove(path.Join(b.DestinationPath, match.Name())); err != nil {
return errwrap.Wrap(err, "error removing file") return errwrap.Wrap(err, "error removing file")
} }
} }

View File

@@ -1,9 +1,12 @@
FROM docker:24-dind FROM docker:27-dind
RUN apk add \ RUN apk add \
age \
coreutils \ coreutils \
curl \ curl \
expect \
gpg \ gpg \
gpg-agent \
jq \ jq \
moreutils \ moreutils \
tar \ tar \

View File

@@ -0,0 +1,24 @@
services:
backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary}
restart: always
environment:
BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ?
BACKUP_FILENAME: test.tar.gz
BACKUP_LATEST_SYMLINK: test-latest.tar.gz.age
BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7}
AGE_PASSPHRASE: "Dance.0Tonight.Go.Typical"
volumes:
- ${LOCAL_DIR:-./local}:/archive
- app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
offen:
image: offen/offen:latest
labels:
- docker-volume-backup.stop-during-backup=true
volumes:
- app_data:/var/opt/offen
volumes:
app_data:

39
test/age-passphrase/run.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/bin/sh
set -e
cd "$(dirname "$0")"
. ../util.sh
current_test=$(basename "$(pwd)")
export LOCAL_DIR="$(mktemp -d)"
docker compose up -d --quiet-pull
sleep 5
docker compose exec backup backup
expect_running_containers "2"
TMP_DIR=$(mktemp -d)
# complex usage of expect(1) due to age not have a way to programmatically
# provide the passphrase
expect -i <<EOL
spawn age --decrypt -o "$LOCAL_DIR/decrypted.tar.gz" "$LOCAL_DIR/test.tar.gz.age"
expect -exact "Enter passphrase: "
send -- "Dance.0Tonight.Go.Typical\r"
sleep 1
EOL
tar -xf "$LOCAL_DIR/decrypted.tar.gz" -C "$TMP_DIR"
if [ ! -f "$TMP_DIR/backup/app_data/offen.db" ]; then
fail "Could not find expected file in untared archive."
fi
rm -vf "$LOCAL_DIR/decrypted.tar.gz"
pass "Found relevant files in decrypted and untared local backup."
if [ ! -L "$LOCAL_DIR/test-latest.tar.gz.age" ]; then
fail "Could not find local symlink to latest encrypted backup."
fi

1
test/age-publickey/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
pk-*.txt

View File

@@ -0,0 +1,24 @@
services:
backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary}
restart: always
environment:
BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ?
BACKUP_FILENAME: test.tar.gz
BACKUP_LATEST_SYMLINK: test-latest.tar.gz.age
BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7}
AGE_PUBLIC_KEYS: "${BACKUP_AGE_PUBLIC_KEYS}"
volumes:
- ${LOCAL_DIR:-./local}:/archive
- app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
offen:
image: offen/offen:latest
labels:
- docker-volume-backup.stop-during-backup=true
volumes:
- app_data:/var/opt/offen
volumes:
app_data:

47
test/age-publickey/run.sh Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/sh
set -e
cd "$(dirname "$0")"
. ../util.sh
current_test=$(basename "$(pwd)")
export LOCAL_DIR="$(mktemp -d)"
age-keygen >"$LOCAL_DIR/pk-a.txt"
PK_A="$(grep -E 'public key' <"$LOCAL_DIR/pk-a.txt" | cut -d: -f2 | xargs)"
age-keygen >"$LOCAL_DIR/pk-b.txt"
PK_B="$(grep -E 'public key' <"$LOCAL_DIR/pk-b.txt" | cut -d: -f2 | xargs)"
ssh-keygen -t ed25519 -m pem -f "$LOCAL_DIR/id_ed25519" -C "docker-volume-backup@local"
PK_C="$(cat $LOCAL_DIR/id_ed25519.pub)"
export BACKUP_AGE_PUBLIC_KEYS="$PK_A,$PK_B,$PK_C"
docker compose up -d --quiet-pull
sleep 5
docker compose exec backup backup
expect_running_containers "2"
do_decrypt() {
TMP_DIR=$(mktemp -d)
age --decrypt -i "$1" -o "$LOCAL_DIR/decrypted.tar.gz" "$LOCAL_DIR/test.tar.gz.age"
tar -xf "$LOCAL_DIR/decrypted.tar.gz" -C "$TMP_DIR"
if [ ! -f "$TMP_DIR/backup/app_data/offen.db" ]; then
fail "Could not find expected file in untared archive."
fi
rm -vf "$LOCAL_DIR/decrypted.tar.gz"
pass "Found relevant files in decrypted and untared local backup."
if [ ! -L "$LOCAL_DIR/test-latest.tar.gz.age" ]; then
fail "Could not find local symlink to latest encrypted backup."
fi
}
do_decrypt "$LOCAL_DIR/pk-a.txt"
do_decrypt "$LOCAL_DIR/pk-b.txt"
do_decrypt "$LOCAL_DIR/id_ed25519"

View File

@@ -1,8 +1,6 @@
version: '3'
services: services:
storage: storage:
image: mcr.microsoft.com/azure-storage/azurite:3.26.0 image: mcr.microsoft.com/azure-storage/azurite:3.33.0
volumes: volumes:
- ${DATA_DIR:-./data}:/data - ${DATA_DIR:-./data}:/data
command: azurite-blob --blobHost 0.0.0.0 --blobPort 10000 --location /data command: azurite-blob --blobHost 0.0.0.0 --blobPort 10000 --location /data
@@ -36,6 +34,7 @@ services:
AZURE_STORAGE_CONTAINER_NAME: test-container AZURE_STORAGE_CONTAINER_NAME: test-container
AZURE_STORAGE_ENDPOINT: http://storage:10000/{{ .AccountName }}/ AZURE_STORAGE_ENDPOINT: http://storage:10000/{{ .AccountName }}/
AZURE_STORAGE_PATH: 'path/to/backup' AZURE_STORAGE_PATH: 'path/to/backup'
AZURE_STORAGE_ACCESS_TIER: Hot
BACKUP_FILENAME: test.tar.gz BACKUP_FILENAME: test.tar.gz
BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ? BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ?
BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7} BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7}
@@ -43,7 +42,7 @@ services:
BACKUP_PRUNING_PREFIX: test BACKUP_PRUNING_PREFIX: test
volumes: volumes:
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
offen: offen:
image: offen/offen:latest image: offen/offen:latest

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
minio: minio:
hostname: minio.local hostname: minio.local
@@ -32,7 +30,7 @@ services:
BACKUP_PRUNING_LEEWAY: 5s BACKUP_PRUNING_LEEWAY: 5s
volumes: volumes:
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
- ${CERT_DIR:-.}/rootCA.crt:/root/minio-rootCA.crt - ${CERT_DIR:-.}/rootCA.crt:/root/minio-rootCA.crt
offen: offen:

View File

@@ -37,7 +37,7 @@ docker run --rm -q \
--network test_network \ --network test_network \
-v app_data:/backup/app_data \ -v app_data:/backup/app_data \
-v empty_data:/backup/empty_data \ -v empty_data:/backup/empty_data \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock:ro \
--env AWS_ACCESS_KEY_ID=test \ --env AWS_ACCESS_KEY_ID=test \
--env AWS_SECRET_ACCESS_KEY=GMusLtUmILge2by+z890kQ \ --env AWS_SECRET_ACCESS_KEY=GMusLtUmILge2by+z890kQ \
--env AWS_ENDPOINT=minio:9000 \ --env AWS_ENDPOINT=minio:9000 \

View File

@@ -1,8 +1,6 @@
# Copyright 2020-2021 - Offen Authors <hioffen@posteo.de> # Copyright 2020-2021 - offen.software <hioffen@posteo.de>
# SPDX-License-Identifier: Unlicense # SPDX-License-Identifier: Unlicense
version: '3.8'
services: services:
backup: backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary} image: offen/docker-volume-backup:${TEST_VERSION:-canary}
@@ -11,7 +9,7 @@ services:
volumes: volumes:
- offen_data:/backup/offen_data:ro - offen_data:/backup/offen_data:ro
- ${LOCAL_DIR:-./local}:/archive - ${LOCAL_DIR:-./local}:/archive
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
offen: offen:
image: offen/offen:latest image: offen/offen:latest

View File

@@ -1,5 +1,3 @@
version: '3.8'
services: services:
database: database:
image: mariadb:10.7 image: mariadb:10.7
@@ -44,7 +42,7 @@ services:
volumes: volumes:
- ${LOCAL_DIR:-./local}:/archive - ${LOCAL_DIR:-./local}:/archive
- app_data:/backup/data:ro - app_data:/backup/data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
volumes: volumes:
app_data: app_data:

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
backup: backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary} image: offen/docker-volume-backup:${TEST_VERSION:-canary}
@@ -14,7 +12,7 @@ services:
- ./01backup.env:/etc/dockervolumebackup/conf.d/01backup.env - ./01backup.env:/etc/dockervolumebackup/conf.d/01backup.env
- ./02backup.env:/etc/dockervolumebackup/conf.d/02backup.env - ./02backup.env:/etc/dockervolumebackup/conf.d/02backup.env
- ./03never.env:/etc/dockervolumebackup/conf.d/03never.env - ./03never.env:/etc/dockervolumebackup/conf.d/03never.env
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
offen: offen:
image: offen/offen:latest image: offen/offen:latest

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
openapi_mock: openapi_mock:
image: muonsoft/openapi-mock:0.3.9 image: muonsoft/openapi-mock:0.3.9
@@ -44,7 +42,7 @@ services:
DROPBOX_CONCURRENCY_LEVEL: 6 DROPBOX_CONCURRENCY_LEVEL: 6
volumes: volumes:
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
offen: offen:
image: offen/offen:latest image: offen/offen:latest

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
backup: backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary} image: offen/docker-volume-backup:${TEST_VERSION:-canary}
@@ -13,7 +11,7 @@ services:
volumes: volumes:
- ${LOCAL_DIR:-local}:/local - ${LOCAL_DIR:-local}:/local
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
offen: offen:
image: offen/offen:latest image: offen/offen:latest

View File

@@ -0,0 +1,25 @@
services:
backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary}
restart: always
environment:
BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ?
BACKUP_FILENAME: test.tar.gz
BACKUP_LATEST_SYMLINK: test-latest.tar.gz.gpg
BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7}
GPG_PUBLIC_KEY_RING_FILE: /keys/public_key.asc
volumes:
- ${KEY_DIR:-.}/public_key.asc:/keys/public_key.asc
- ${LOCAL_DIR:-./local}:/archive
- app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
offen:
image: offen/offen:latest
labels:
- docker-volume-backup.stop-during-backup=true
volumes:
- app_data:/var/opt/offen
volumes:
app_data:

49
test/gpg-asym/run.sh Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/sh
set -e
cd "$(dirname "$0")"
. ../util.sh
current_test=$(basename $(pwd))
export LOCAL_DIR=$(mktemp -d)
export KEY_DIR=$(mktemp -d)
export PASSPHRASE="test"
gpg --batch --gen-key <<EOF
Key-Type: RSA
Key-Length: 4096
Name-Real: offen
Name-Email: docker-volume-backup@local
Expire-Date: 0
Passphrase: $PASSPHRASE
%commit
EOF
gpg --export --armor --batch --yes --pinentry-mode loopback --passphrase $PASSPHRASE --output $KEY_DIR/public_key.asc
docker compose up -d --quiet-pull
sleep 5
docker compose exec backup backup
expect_running_containers "2"
TMP_DIR=$(mktemp -d)
gpg -d --pinentry-mode loopback --yes --passphrase $PASSPHRASE "$LOCAL_DIR/test.tar.gz.gpg" > "$LOCAL_DIR/decrypted.tar.gz"
tar -xf "$LOCAL_DIR/decrypted.tar.gz" -C $TMP_DIR
if [ ! -f $TMP_DIR/backup/app_data/offen.db ]; then
fail "Could not find expected file in untared archive."
fi
rm "$LOCAL_DIR/decrypted.tar.gz"
pass "Found relevant files in decrypted and untared local backup."
if [ ! -L "$LOCAL_DIR/test-latest.tar.gz.gpg" ]; then
fail "Could not find local symlink to latest encrypted backup."
fi

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
backup: backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary} image: offen/docker-volume-backup:${TEST_VERSION:-canary}
@@ -13,7 +11,7 @@ services:
volumes: volumes:
- ${LOCAL_DIR:-./local}:/archive - ${LOCAL_DIR:-./local}:/archive
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
offen: offen:
image: offen/offen:latest image: offen/offen:latest

View File

@@ -1,5 +1,3 @@
version: '3.8'
services: services:
backup: backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary} image: offen/docker-volume-backup:${TEST_VERSION:-canary}

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
backup: backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary} image: offen/docker-volume-backup:${TEST_VERSION:-canary}
@@ -15,7 +13,7 @@ services:
BACKUP_PRUNING_PREFIX: test BACKUP_PRUNING_PREFIX: test
volumes: volumes:
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
- ${LOCAL_DIR:-./local}:/archive - ${LOCAL_DIR:-./local}:/archive
offen: offen:

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
backup: backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary} image: offen/docker-volume-backup:${TEST_VERSION:-canary}
@@ -9,7 +7,7 @@ services:
BACKUP_RETENTION_DAYS: '7' BACKUP_RETENTION_DAYS: '7'
volumes: volumes:
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
- ${LOCAL_DIR:-./local}:/archive - ${LOCAL_DIR:-./local}:/archive
offen: offen:

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
minio: minio:
image: minio/minio:RELEASE.2020-08-04T23-10-51Z image: minio/minio:RELEASE.2020-08-04T23-10-51Z

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
backup: backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary} image: offen/docker-volume-backup:${TEST_VERSION:-canary}

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
db: db:
image: postgres:14-alpine image: postgres:14-alpine

View File

@@ -23,7 +23,7 @@ docker run --rm -q \
--network test_network \ --network test_network \
-v app_data:/backup/app_data \ -v app_data:/backup/app_data \
-v $LOCAL_DIR:/archive \ -v $LOCAL_DIR:/archive \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock:ro \
--env BACKUP_COMPRESSION=gz \ --env BACKUP_COMPRESSION=gz \
--env GZIP_PARALLELISM=0 \ --env GZIP_PARALLELISM=0 \
--env BACKUP_FILENAME='test.{{ .Extension }}' \ --env BACKUP_FILENAME='test.{{ .Extension }}' \

View File

@@ -1,8 +1,6 @@
# Copyright 2020-2021 - Offen Authors <hioffen@posteo.de> # Copyright 2020-2021 - offen.software <hioffen@posteo.de>
# SPDX-License-Identifier: Unlicense # SPDX-License-Identifier: Unlicense
version: '3.8'
services: services:
backup: backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary} image: offen/docker-volume-backup:${TEST_VERSION:-canary}
@@ -24,7 +22,7 @@ services:
TASKS: ${ALLOW_TASKS:-1} TASKS: ${ALLOW_TASKS:-1}
NODES: ${ALLOW_NODES:-1} NODES: ${ALLOW_NODES:-1}
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
pg: pg:
image: postgres:14-alpine image: postgres:14-alpine

View File

@@ -1,8 +1,6 @@
# Copyright 2020-2021 - Offen Authors <hioffen@posteo.de> # Copyright 2020-2021 - offen.software <hioffen@posteo.de>
# SPDX-License-Identifier: Unlicense # SPDX-License-Identifier: Unlicense
version: '3.8'
services: services:
backup: backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary} image: offen/docker-volume-backup:${TEST_VERSION:-canary}
@@ -21,7 +19,7 @@ services:
CONTAINERS: ${ALLOW_CONTAINERS:-1} CONTAINERS: ${ALLOW_CONTAINERS:-1}
POST: ${ALLOW_POST:-1} POST: ${ALLOW_POST:-1}
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
pg: pg:
image: postgres:14-alpine image: postgres:14-alpine

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
minio: minio:
image: minio/minio:RELEASE.2020-08-04T23-10-51Z image: minio/minio:RELEASE.2020-08-04T23-10-51Z
@@ -34,7 +32,7 @@ services:
BACKUP_SKIP_BACKENDS_FROM_PRUNE: 's3' BACKUP_SKIP_BACKENDS_FROM_PRUNE: 's3'
volumes: volumes:
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
- ${LOCAL_DIR:-./local}:/archive - ${LOCAL_DIR:-./local}:/archive
offen: offen:

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
minio: minio:
image: minio/minio:RELEASE.2020-08-04T23-10-51Z image: minio/minio:RELEASE.2020-08-04T23-10-51Z
@@ -32,7 +30,7 @@ services:
BACKUP_PRUNING_PREFIX: test BACKUP_PRUNING_PREFIX: test
volumes: volumes:
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
offen: offen:
image: offen/offen:latest image: offen/offen:latest

View File

@@ -1,8 +1,6 @@
# Copyright 2020-2021 - Offen Authors <hioffen@posteo.de> # Copyright 2020-2021 - offen.software <hioffen@posteo.de>
# SPDX-License-Identifier: Unlicense # SPDX-License-Identifier: Unlicense
version: '3.8'
services: services:
minio: minio:
image: minio/minio:RELEASE.2020-08-04T23-10-51Z image: minio/minio:RELEASE.2020-08-04T23-10-51Z
@@ -37,7 +35,7 @@ services:
BACKUP_PRUNING_LEEWAY: 5s BACKUP_PRUNING_LEEWAY: 5s
volumes: volumes:
- pg_data:/backup/pg_data:ro - pg_data:/backup/pg_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
secrets: secrets:
- minio_root_user - minio_root_user
- minio_root_password - minio_root_password

View File

@@ -1,8 +1,6 @@
# Copyright 2020-2021 - Offen Authors <hioffen@posteo.de> # Copyright 2020-2021 - offen.software <hioffen@posteo.de>
# SPDX-License-Identifier: Unlicense # SPDX-License-Identifier: Unlicense
version: '3.8'
services: services:
minio: minio:
image: minio/minio:RELEASE.2020-08-04T23-10-51Z image: minio/minio:RELEASE.2020-08-04T23-10-51Z
@@ -31,7 +29,7 @@ services:
BACKUP_PRUNING_LEEWAY: 5s BACKUP_PRUNING_LEEWAY: 5s
volumes: volumes:
- pg_data:/backup/pg_data:ro - pg_data:/backup/pg_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
offen: offen:
image: offen/offen:latest image: offen/offen:latest

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
ssh: ssh:
image: linuxserver/openssh-server:version-8.6_p1-r3 image: linuxserver/openssh-server:version-8.6_p1-r3
@@ -32,7 +30,7 @@ services:
volumes: volumes:
- ${KEY_DIR:-.}/id_rsa:/root/.ssh/id_rsa - ${KEY_DIR:-.}/id_rsa:/root/.ssh/id_rsa
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
offen: offen:
image: offen/offen:latest image: offen/offen:latest

View File

@@ -1,8 +1,6 @@
# Copyright 2020-2021 - Offen Authors <hioffen@posteo.de> # Copyright 2020-2021 - offen.software <hioffen@posteo.de>
# SPDX-License-Identifier: Unlicense # SPDX-License-Identifier: Unlicense
version: '3.8'
services: services:
minio: minio:
image: minio/minio:RELEASE.2020-08-04T23-10-51Z image: minio/minio:RELEASE.2020-08-04T23-10-51Z
@@ -37,7 +35,7 @@ services:
BACKUP_PRUNING_LEEWAY: 5s BACKUP_PRUNING_LEEWAY: 5s
volumes: volumes:
- pg_data:/backup/pg_data:ro - pg_data:/backup/pg_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
offen: offen:
image: offen/offen:latest image: offen/offen:latest

View File

@@ -0,0 +1,21 @@
services:
backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary}
restart: always
environment:
BACKUP_FILENAME: test.{{ .Extension }}
BACKUP_COMPRESSION: none
volumes:
- app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ${LOCAL_DIR:-./local}:/archive
offen:
image: offen/offen:latest
labels:
- docker-volume-backup.stop-during-backup=true
volumes:
- app_data:/var/opt/offen
volumes:
app_data:

25
test/tar/run.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/sh
set -e
cd "$(dirname "$0")"
. ../util.sh
current_test=$(basename $(pwd))
export LOCAL_DIR=$(mktemp -d)
docker compose up -d --quiet-pull
sleep 5
docker compose exec backup backup
sleep 5
expect_running_containers "2"
tmp_dir=$(mktemp -d)
tar -xvf "$LOCAL_DIR/test.tar" -C $tmp_dir
if [ ! -f "$tmp_dir/backup/app_data/offen.db" ]; then
fail "Could not find expected file in untared archive."
fi
pass "Expected file was found."

View File

@@ -1,5 +1,3 @@
version: '2.4'
services: services:
alpine: alpine:
image: alpine:3.17.3 image: alpine:3.17.3
@@ -22,7 +20,7 @@ services:
volumes: volumes:
- ${LOCAL_DIR:-./local}:/archive - ${LOCAL_DIR:-./local}:/archive
- app_data:/backup/data:ro - app_data:/backup/data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
volumes: volumes:
app_data: app_data:

View File

@@ -1,5 +1,3 @@
version: '3'
services: services:
webdav: webdav:
image: bytemark/webdav:2.4 image: bytemark/webdav:2.4
@@ -30,7 +28,7 @@ services:
WEBDAV_PASSWORD: test WEBDAV_PASSWORD: test
volumes: volumes:
- app_data:/backup/app_data:ro - app_data:/backup/app_data:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock:ro
offen: offen:
image: offen/offen:latest image: offen/offen:latest

View File

@@ -23,7 +23,7 @@ docker run --rm -q \
--network test_network \ --network test_network \
-v app_data:/backup/app_data \ -v app_data:/backup/app_data \
-v $LOCAL_DIR:/archive \ -v $LOCAL_DIR:/archive \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock:ro \
--env BACKUP_COMPRESSION=zst \ --env BACKUP_COMPRESSION=zst \
--env BACKUP_FILENAME='test.{{ .Extension }}' \ --env BACKUP_FILENAME='test.{{ .Extension }}' \
--entrypoint backup \ --entrypoint backup \