3
0
mirror of https://kolaente.dev/konrad/docker-db-backup.git synced 2026-01-10 02:50:08 +01:00

feat: add support for labels to discover additional containers

This commit is contained in:
kolaente
2022-08-09 11:02:47 +02:00
parent 064d2ce66e
commit 96d61fd6e0
2 changed files with 12 additions and 3 deletions

View File

@@ -6,6 +6,8 @@ import (
"strings"
)
const containerLabelName = `de.kolaente.db-backup`
type Dumper interface {
Dump(c *client.Client) error
}
@@ -13,11 +15,11 @@ type Dumper interface {
func NewDumperFromContainer(container *types.ContainerJSON) Dumper {
// Containers contain the tags, therefore we need to check them one by one
if strings.HasPrefix(container.Config.Image, "mysql") || strings.HasPrefix(container.Config.Image, "mariadb") {
if strings.HasPrefix(container.Config.Image, "mysql") || strings.HasPrefix(container.Config.Image, "mariadb") || container.Config.Labels[containerLabelName] == "mysql" {
return NewMysqlDumper(container)
}
if strings.HasPrefix(container.Config.Image, "postgres") {
if strings.HasPrefix(container.Config.Image, "postgres") || container.Config.Labels[containerLabelName] == "postgres" {
return NewPostgresDumper(container)
}