mirror of
https://github.com/offen/docker-volume-backup.git
synced 2026-01-03 07:25:48 +08:00
Support "BackupFilenameExpand" option
This commit is contained in:
parent
13e54e1ba0
commit
a826828d76
3 changed files with 23 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"github.com/offen/docker-volume-backup/internal/errwrap"
|
||||
|
|
@ -22,6 +23,20 @@ func runShowConfig() error {
|
|||
fmt.Println("source=<nil>\n<nil>")
|
||||
continue
|
||||
}
|
||||
if config.BackupFilenameExpand {
|
||||
unset, err := config.applyEnv()
|
||||
if err != nil {
|
||||
fmt.Printf("error applying env: %v\n", err) // print error to stdout for debugging
|
||||
return errwrap.Wrap(err, "error applying env")
|
||||
}
|
||||
config.BackupFilename = os.ExpandEnv(config.BackupFilename)
|
||||
config.BackupLatestSymlink = os.ExpandEnv(config.BackupLatestSymlink)
|
||||
config.BackupPruningPrefix = os.ExpandEnv(config.BackupPruningPrefix)
|
||||
if err := unset(); err != nil {
|
||||
fmt.Printf("error unsetting env: %v\n", err) // print error to stdout for debugging
|
||||
return errwrap.Wrap(err, "error unsetting environment variables")
|
||||
}
|
||||
}
|
||||
// insert line breaks before each field name, assuming field names start with uppercase letters
|
||||
formatted := regexp.MustCompile(`\s([A-Z])`).ReplaceAllString(fmt.Sprintf("%+v", *config), "\n$1")
|
||||
fmt.Printf("source=%s\n%s\n", config.source, formatted)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ services:
|
|||
backup:
|
||||
image: offen/docker-volume-backup:${TEST_VERSION:-canary}
|
||||
environment:
|
||||
BACKUP_FILENAME: "backup-$${BACKUP_TAG}.tar"
|
||||
BACKUP_FILENAME_EXPAND: true
|
||||
BACKUP_TAG: expanded
|
||||
BACKUP_SOURCES: /backup
|
||||
NOTIFICATION_URLS: "stdout://"
|
||||
AWS_S3_BUCKET_NAME: example-bucket
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@ if ! echo "$logs" | grep -q "BackupSources:/backup"; then
|
|||
fi
|
||||
pass "BACKUP_SOURCES present."
|
||||
|
||||
if ! echo "$logs" | grep -q "BackupFilename:backup-expanded.tar"; then
|
||||
fail "Missing expanded BACKUP_FILENAME in output."
|
||||
fi
|
||||
pass "Expanded BACKUP_FILENAME present."
|
||||
|
||||
if ! echo "$logs" | grep -q "NotificationURLs:\[stdout://\]"; then
|
||||
fail "Missing NOTIFICATION_URLS in output."
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue