feat: add support for labels to discover additional containers
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
064d2ce66e
commit
96d61fd6e0
|
@ -14,11 +14,18 @@ Simply point it at your docker socket, mount a backup volume and be done:
|
||||||
docker run -v $PWD/backups:/backups -v /var/run/docker.sock:/var/run/docker.sock kolaente/db-backup
|
docker run -v $PWD/backups:/backups -v /var/run/docker.sock:/var/run/docker.sock kolaente/db-backup
|
||||||
```
|
```
|
||||||
|
|
||||||
The tool will find all database containers and create backups of them periodically. It will also discover new containers
|
The tool will find all database containers running an official [`mysql`](https://hub.docker.com/_/mysql),
|
||||||
|
[`mariadb`](https://hub.docker.com/_/mariadb) or [`postgres`](https://hub.docker.com/_/postgres) image and
|
||||||
|
create backups of them periodically. It will also discover new containers
|
||||||
as they are started and won't try to back up containers which have gone away.
|
as they are started and won't try to back up containers which have gone away.
|
||||||
|
|
||||||
When running, all backups for the current run are time-stamped into a sub folder of the backup directory (see below).
|
When running, all backups for the current run are time-stamped into a sub folder of the backup directory (see below).
|
||||||
|
|
||||||
|
### Using labels
|
||||||
|
|
||||||
|
To make the backup tool discover other non-offical containers as well you can add the label `de.kolaente.db-backup` to
|
||||||
|
any container with a value of `mysql` or `postgres` to treat it as a mysql or postgres container.
|
||||||
|
|
||||||
### Docker Compose
|
### Docker Compose
|
||||||
|
|
||||||
If you're running docker-compose, you can use a setup similar to the following compose file to run the backup:
|
If you're running docker-compose, you can use a setup similar to the following compose file to run the backup:
|
||||||
|
|
6
dump.go
6
dump.go
|
@ -6,6 +6,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const containerLabelName = `de.kolaente.db-backup`
|
||||||
|
|
||||||
type Dumper interface {
|
type Dumper interface {
|
||||||
Dump(c *client.Client) error
|
Dump(c *client.Client) error
|
||||||
}
|
}
|
||||||
|
@ -13,11 +15,11 @@ type Dumper interface {
|
||||||
func NewDumperFromContainer(container *types.ContainerJSON) Dumper {
|
func NewDumperFromContainer(container *types.ContainerJSON) Dumper {
|
||||||
|
|
||||||
// Containers contain the tags, therefore we need to check them one by one
|
// 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)
|
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)
|
return NewPostgresDumper(container)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue