From 3661a4b49b75562bf0a33e4cabf24c62daea777f Mon Sep 17 00:00:00 2001 From: Erwan LE PRADO Date: Wed, 6 Jul 2022 13:18:12 +0200 Subject: [PATCH] feat: Add storage class header (#119) * feat: Add storage class header * doc: change the readme * chore: Remove the unnecessary default value --- README.md | 5 +++++ cmd/backup/config.go | 1 + cmd/backup/script.go | 8 +++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1102edf..2351641 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,11 @@ You can populate below template according to your requirements and use it as you # AWS_ENDPOINT_INSECURE="true" +# 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" + # You can also backup files to any WebDAV server: # The URL of the remote WebDAV server diff --git a/cmd/backup/config.go b/cmd/backup/config.go index 7c2862e..e12d682 100644 --- a/cmd/backup/config.go +++ b/cmd/backup/config.go @@ -28,6 +28,7 @@ type Config struct { AwsEndpoint string `split_words:"true" default:"s3.amazonaws.com"` AwsEndpointProto string `split_words:"true" default:"https"` AwsEndpointInsecure bool `split_words:"true"` + AwsStorageClass string `split_words:"true"` AwsAccessKeyID string `envconfig:"AWS_ACCESS_KEY_ID"` AwsSecretAccessKey string `split_words:"true"` AwsIamRoleEndpoint string `split_words:"true"` diff --git a/cmd/backup/script.go b/cmd/backup/script.go index 6480e4a..99657be 100644 --- a/cmd/backup/script.go +++ b/cmd/backup/script.go @@ -7,8 +7,6 @@ import ( "context" "errors" "fmt" - "github.com/pkg/sftp" - "golang.org/x/crypto/ssh" "io" "io/fs" "io/ioutil" @@ -20,6 +18,9 @@ import ( "text/template" "time" + "github.com/pkg/sftp" + "golang.org/x/crypto/ssh" + "github.com/containrrr/shoutrrr" "github.com/containrrr/shoutrrr/pkg/router" "github.com/docker/docker/api/types" @@ -547,7 +548,8 @@ func (s *script) copyBackup() error { if s.minioClient != nil { if _, err := s.minioClient.FPutObject(context.Background(), s.c.AwsS3BucketName, filepath.Join(s.c.AwsS3Path, name), s.file, minio.PutObjectOptions{ - ContentType: "application/tar+gzip", + ContentType: "application/tar+gzip", + StorageClass: s.c.AwsStorageClass, }); err != nil { return fmt.Errorf("copyBackup: error uploading backup to remote storage: %w", err) }