From cccc3883b6ed2d5e91bb546e5123febd13877fe7 Mon Sep 17 00:00:00 2001 From: Jean Michel Moll Date: Sun, 26 Oct 2025 15:35:10 +0100 Subject: [PATCH] Add label to optionally skip container restart after backup --- README.md | 4 ++++ cmd/backup/stop_restart.go | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cdf1ccb..fede104 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ services: # backup integrity. You can omit this label if stopping during backup # not required. - docker-volume-backup.stop-during-backup=true + # This means the container will be restarted after the backup completes. + # It is optional, only used together with the stop-during-backup label, + # and defaults to true. + - docker-volume-backup.restart-after-backup=true backup: # In production, it is advised to lock your image tag to a proper diff --git a/cmd/backup/stop_restart.go b/cmd/backup/stop_restart.go index cbca129..e80213b 100644 --- a/cmd/backup/stop_restart.go +++ b/cmd/backup/stop_restart.go @@ -282,7 +282,22 @@ func (s *script) stopContainersAndServices() (func() error, error) { return func() error { var restartErrors []error matchedServices := map[string]bool{} + var restartedContainers []ctr.Summary for _, container := range stoppedContainers { + var restartValue string = container.Labels["docker-volume-backup.restart-after-backup"] + + if len(restartValue) != 0 { + if restartValue == "false" { + continue + } else if restartValue != "true" { + s.logger.Warn( + fmt.Sprintf("Ignoring invalid label docker-volume-backup.restart-after-backup=%s", restartValue), + ) + } + } + + restartedContainers = append(restartedContainers, container) + if swarmServiceID, ok := container.Labels["com.docker.swarm.service.id"]; ok && isDockerSwarm { if _, ok := matchedServices[swarmServiceID]; ok { continue @@ -349,7 +364,8 @@ func (s *script) stopContainersAndServices() (func() error, error) { s.logger.Info( fmt.Sprintf( - "Restarted %d container(s).", + "Restarted %d of %d container(s).", + len(restartedContainers), len(stoppedContainers), ), )