From 7244725c5b96101e2f70c0b77ce50ca0d8170525 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Sun, 22 Aug 2021 20:42:25 +0200 Subject: [PATCH] fix location of success message for having created local backup --- README.md | 4 ++-- cmd/backup/main.go | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index df032b5..218c1ed 100644 --- a/README.md +++ b/README.md @@ -176,9 +176,9 @@ docker exec backup This image is heavily inspired by the `futurice/docker-volume-backup`. We decided to publish this image as a simpler and more lightweight alternative because of the following requirements: -- The original image is based on `ubuntu`, making it very heavy. This version is roughly 1/3 in compressed size. +- The original image is based on `ubuntu` and additional tools, making it very heavy. This version is roughly 1/25 in compressed size (it's ~12MB). - The original image uses a shell script, when this is written in Go. -- The original image proposed to handle backup rotation through AWS S3 lifecycle policies. This image adds the option to rotate away old backups through the same command so this functionality can also be offered for non-AWS storage backends like MinIO. Local backups can also be pruned once they reach a certain age. +- The original image proposed to handle backup rotation through AWS S3 lifecycle policies. This image adds the option to rotate away old backups through the same command so this functionality can also be offered for non-AWS storage backends like MinIO. Local copies of backups can also be pruned once they reach a certain age. - InfluxDB specific functionality was removed. - `arm64` and `arm/v7` architectures are supported. - Docker in Swarm mode is supported. diff --git a/cmd/backup/main.go b/cmd/backup/main.go index f6bfdc4..16d7d72 100644 --- a/cmd/backup/main.go +++ b/cmd/backup/main.go @@ -41,6 +41,7 @@ func main() { s.must(s.copyBackup()) s.must(s.cleanBackup()) s.must(s.pruneOldBackups()) + s.logger.Info("Finished running backup tasks.") } type script struct { @@ -305,11 +306,9 @@ func (s *script) copyBackup() error { s.logger.Infof("Successfully uploaded a copy of backup `%s` to bucket `%s`", s.file, s.bucket) } - if s.archive != "" { - if _, err := os.Stat(s.archive); !os.IsNotExist(err) { - if err := copy(s.file, path.Join(s.archive, name)); err != nil { - return fmt.Errorf("copyBackup: error copying file to local archive: %w", err) - } + if _, err := os.Stat(s.archive); !os.IsNotExist(err) { + if err := copy(s.file, path.Join(s.archive, name)); err != nil { + return fmt.Errorf("copyBackup: error copying file to local archive: %w", err) } s.logger.Infof("Successfully stored copy of backup `%s` in local archive `%s`", s.file, s.archive) } @@ -404,7 +403,7 @@ func (s *script) pruneOldBackups() error { } } - if s.archive != "" { + if _, err := os.Stat(s.archive); !os.IsNotExist(err) { candidates, err := filepath.Glob( path.Join(s.archive, fmt.Sprintf("%s*", os.Getenv("BACKUP_PRUNING_PREFIX"))), )