mirror of
https://github.com/offen/docker-volume-backup.git
synced 2025-12-11 23:25:58 +08:00
Add label to optionally skip container restart after backup
This commit is contained in:
parent
bda5133574
commit
cccc3883b6
2 changed files with 21 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue