From 6fe629ce87bac87e404434b96173383c91fe67cd Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Tue, 25 Jan 2022 21:16:16 +0100 Subject: [PATCH] Allow path to be set for bucket storage (#52) --- README.md | 7 ++++++- cmd/backup/main.go | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f376352..b41be0e 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ You can populate below template according to your requirements and use it as you # Please note that you will need to escape the `$` when providing the value # in a docker-compose.yml file, i.e. using $$VAR instead of $VAR. -# BACKUP_FILENAME_TEMPLATE="true" +# BACKUP_FILENAME_EXPAND="true" # 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. @@ -156,6 +156,11 @@ You can populate below template according to your requirements and use it as you # AWS_S3_BUCKET_NAME="backup-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. + +# AWS_S3_PATH="my/backup/location" + # 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 # with any S3 compatible storage. diff --git a/cmd/backup/main.go b/cmd/backup/main.go index ca3cf67..fd67f1e 100644 --- a/cmd/backup/main.go +++ b/cmd/backup/main.go @@ -115,6 +115,7 @@ type config struct { BackupStopContainerLabel string `split_words:"true" default:"true"` BackupFromSnapshot bool `split_words:"true"` AwsS3BucketName string `split_words:"true"` + AwsS3Path string `split_words:"true"` AwsEndpoint string `split_words:"true" default:"s3.amazonaws.com"` AwsEndpointProto string `split_words:"true" default:"https"` AwsEndpointInsecure bool `split_words:"true"` @@ -525,7 +526,7 @@ func (s *script) encryptBackup() error { func (s *script) copyBackup() error { _, name := path.Split(s.file) if s.minioClient != nil { - if _, err := s.minioClient.FPutObject(context.Background(), s.c.AwsS3BucketName, name, s.file, minio.PutObjectOptions{ + if _, err := s.minioClient.FPutObject(context.Background(), s.c.AwsS3BucketName, filepath.Join(s.c.AwsS3Path, name), s.file, minio.PutObjectOptions{ ContentType: "application/tar+gzip", }); err != nil { return fmt.Errorf("copyBackup: error uploading backup to remote storage: %w", err)