mirror of
https://github.com/kolaente/docker-db-backup.git
synced 2026-03-24 21:43:48 +01:00
Also updates all affected new types. --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: kolaente <k@knt.li>
49 lines
832 B
Go
49 lines
832 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"sync"
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
"github.com/docker/docker/client"
|
|
)
|
|
|
|
var (
|
|
store map[string]Dumper
|
|
lock sync.Mutex
|
|
)
|
|
|
|
func init() {
|
|
store = make(map[string]Dumper)
|
|
}
|
|
|
|
func storeContainers(c *client.Client, containers []container.Summary) {
|
|
lock.Lock()
|
|
defer lock.Unlock()
|
|
|
|
for _, container := range containers {
|
|
delete(store, container.ID)
|
|
}
|
|
|
|
for _, container := range containers {
|
|
if container.State != "running" {
|
|
continue
|
|
}
|
|
|
|
info, err := c.ContainerInspect(context.Background(), container.ID)
|
|
if err != nil {
|
|
log.Fatalf("Could not get Container info: %s", err)
|
|
}
|
|
|
|
dumper := NewDumperFromContainer(&info)
|
|
if dumper == nil {
|
|
continue
|
|
}
|
|
|
|
log.Printf("Found container %s\n", container.Names)
|
|
|
|
store[container.ID] = dumper
|
|
}
|
|
}
|