mirror of
https://github.com/offen/docker-volume-backup.git
synced 2025-12-10 11:11:10 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
907deecdd0 | ||
|
|
92b888e72c | ||
|
|
3925ac1ee0 | ||
|
|
5c7856feb3 |
@@ -4,8 +4,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -62,14 +62,14 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) resolveSecret(envVar string, secretPath string) (string, error) {
|
func (c *Config) resolveSecret(envVar string, secretPath string) (string, error) {
|
||||||
if secretPath != "" {
|
if secretPath == "" {
|
||||||
data, err := os.ReadFile(secretPath)
|
return envVar, nil
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("resolveSecret: error reading secret path: %w", err)
|
|
||||||
}
|
|
||||||
return string(data), nil
|
|
||||||
}
|
}
|
||||||
return envVar, nil
|
data, err := os.ReadFile(secretPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("resolveSecret: error reading secret path: %w", err)
|
||||||
|
}
|
||||||
|
return string(data), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type RegexpDecoder struct {
|
type RegexpDecoder struct {
|
||||||
|
|||||||
@@ -100,8 +100,10 @@ func (b *s3Storage) Copy(file string) error {
|
|||||||
ContentType: "application/tar+gzip",
|
ContentType: "application/tar+gzip",
|
||||||
StorageClass: b.storageClass,
|
StorageClass: b.storageClass,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
errResp := minio.ToErrorResponse(err)
|
if errResp := minio.ToErrorResponse(err); errResp.Message != "" {
|
||||||
return fmt.Errorf("(*s3Storage).Copy: error uploading backup to remote storage: [Message]: '%s', [Code]: %s, [StatusCode]: %d", errResp.Message, errResp.Code, errResp.StatusCode)
|
return fmt.Errorf("(*s3Storage).Copy: error uploading backup to remote storage: [Message]: '%s', [Code]: %s, [StatusCode]: %d", errResp.Message, errResp.Code, errResp.StatusCode)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("(*s3Storage).Copy: error uploading backup to remote storage: %w", err)
|
||||||
}
|
}
|
||||||
b.Log(storage.LogLevelInfo, b.Name(), "Uploaded a copy of backup `%s` to bucket `%s`.", file, b.bucket)
|
b.Log(storage.LogLevelInfo, b.Name(), "Uploaded a copy of backup `%s` to bucket `%s`.", file, b.bucket)
|
||||||
|
|
||||||
@@ -111,9 +113,8 @@ 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{
|
||||||
WithMetadata: true,
|
Prefix: filepath.Join(b.DestinationPath, pruningPrefix),
|
||||||
Prefix: filepath.Join(b.DestinationPath, pruningPrefix),
|
Recursive: true,
|
||||||
Recursive: true,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
var matches []minio.ObjectInfo
|
var matches []minio.ObjectInfo
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ services:
|
|||||||
BACKUP_FILENAME: test.tar.gz
|
BACKUP_FILENAME: test.tar.gz
|
||||||
BACKUP_LATEST_SYMLINK: test-latest.tar.gz.gpg
|
BACKUP_LATEST_SYMLINK: test-latest.tar.gz.gpg
|
||||||
BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7}
|
BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7}
|
||||||
GPG_PASSPHRASE: 1234secret
|
GPG_PASSPHRASE: 1234#$$ecret
|
||||||
volumes:
|
volumes:
|
||||||
- ./local:/archive
|
- ./local:/archive
|
||||||
- app_data:/backup/app_data:ro
|
- app_data:/backup/app_data:ro
|
||||||
|
|||||||
@@ -17,9 +17,8 @@ expect_running_containers "2"
|
|||||||
|
|
||||||
tmp_dir=$(mktemp -d)
|
tmp_dir=$(mktemp -d)
|
||||||
|
|
||||||
echo 1234secret | gpg -d --pinentry-mode loopback --yes --passphrase-fd 0 ./local/test.tar.gz.gpg > ./local/decrypted.tar.gz
|
echo "1234#\$ecret" | gpg -d --pinentry-mode loopback --yes --passphrase-fd 0 ./local/test.tar.gz.gpg > ./local/decrypted.tar.gz
|
||||||
tar -xf ./local/decrypted.tar.gz -C $tmp_dir
|
tar -xf ./local/decrypted.tar.gz -C $tmp_dir
|
||||||
ls -lah $tmp_dir
|
|
||||||
if [ ! -f $tmp_dir/backup/app_data/offen.db ]; then
|
if [ ! -f $tmp_dir/backup/app_data/offen.db ]; then
|
||||||
fail "Could not find expected file in untared archive."
|
fail "Could not find expected file in untared archive."
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -4,31 +4,19 @@
|
|||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
minio_setup:
|
|
||||||
image: alpine:latest
|
|
||||||
deploy:
|
|
||||||
restart_policy:
|
|
||||||
condition: none
|
|
||||||
volumes:
|
|
||||||
- backup_data:/data
|
|
||||||
command: mkdir -p /data/backup
|
|
||||||
|
|
||||||
minio:
|
minio:
|
||||||
image: minio/minio:RELEASE.2021-12-20T22-07-16Z
|
image: minio/minio:RELEASE.2020-08-04T23-10-51Z
|
||||||
deploy:
|
deploy:
|
||||||
restart_policy:
|
restart_policy:
|
||||||
condition: on-failure
|
condition: on-failure
|
||||||
environment:
|
environment:
|
||||||
MINIO_ROOT_USER_FILE: /run/secrets/minio_root_user
|
MINIO_ROOT_USER: test
|
||||||
MINIO_ROOT_PASSWORD_FILE: /run/secrets/minio_root_password
|
MINIO_ROOT_PASSWORD: test
|
||||||
command: minio server /data
|
MINIO_ACCESS_KEY: test
|
||||||
|
MINIO_SECRET_KEY: GMusLtUmILge2by+z890kQ
|
||||||
|
entrypoint: /bin/ash -c 'mkdir -p /data/backup && minio server /data'
|
||||||
volumes:
|
volumes:
|
||||||
- backup_data:/data
|
- backup_data:/data
|
||||||
secrets:
|
|
||||||
- minio_root_user
|
|
||||||
- minio_root_password
|
|
||||||
depends_on:
|
|
||||||
- minio_setup
|
|
||||||
|
|
||||||
backup:
|
backup:
|
||||||
image: offen/docker-volume-backup:${TEST_VERSION:-canary}
|
image: offen/docker-volume-backup:${TEST_VERSION:-canary}
|
||||||
@@ -81,6 +69,7 @@ volumes:
|
|||||||
backup_data:
|
backup_data:
|
||||||
name: backup_data
|
name: backup_data
|
||||||
pg_data:
|
pg_data:
|
||||||
|
name: pg_data
|
||||||
|
|
||||||
secrets:
|
secrets:
|
||||||
minio_root_user:
|
minio_root_user:
|
||||||
@@ -41,4 +41,4 @@ docker swarm leave --force
|
|||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
docker volume rm backup_data
|
docker volume rm backup_data
|
||||||
docker volume rm test_stack_pg_data
|
docker volume rm pg_data
|
||||||
@@ -66,3 +66,4 @@ volumes:
|
|||||||
backup_data:
|
backup_data:
|
||||||
name: backup_data
|
name: backup_data
|
||||||
pg_data:
|
pg_data:
|
||||||
|
name: pg_data
|
||||||
|
|||||||
@@ -34,4 +34,4 @@ docker swarm leave --force
|
|||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
docker volume rm backup_data
|
docker volume rm backup_data
|
||||||
docker volume rm test_stack_pg_data
|
docker volume rm pg_data
|
||||||
|
|||||||
Reference in New Issue
Block a user