42 lines
941 B
Go
42 lines
941 B
Go
package volumes
|
|
|
|
import (
|
|
"fmt"
|
|
"context"
|
|
|
|
"github.com/docker/docker/client"
|
|
"github.com/docker/docker/api/types/volume"
|
|
"github.com/docker/docker/api/types/filters"
|
|
)
|
|
|
|
func ListVolumesToBeBackedUp() ([]string, error) {
|
|
var (
|
|
cli *client.Client
|
|
err error
|
|
volumeListOKBody volume.VolumeListOKBody
|
|
ctx context.Context
|
|
)
|
|
|
|
volumesList := make([]string, 0)
|
|
|
|
cli, err = client.NewClientWithOpts()
|
|
if err != nil {
|
|
return volumesList, fmt.Errorf("Could not create client: %s", err.Error())
|
|
}
|
|
|
|
ctx = context.Background()
|
|
volumeListOKBody, err = cli.VolumeList(ctx, filters.NewArgs())
|
|
if err != nil {
|
|
return volumesList, fmt.Errorf("Could not list volumes: %s", err.Error())
|
|
}
|
|
|
|
for _, volume := range volumeListOKBody.Volumes {
|
|
val, ok := volume.Labels["backup.disabled"]
|
|
if !ok || val != "1" {
|
|
volumesList = append(volumesList, volume.Name)
|
|
}
|
|
}
|
|
|
|
return volumesList, nil
|
|
}
|