Begin volume listing

This commit is contained in:
Romain de Laage 2021-12-22 08:09:27 +01:00
parent c06b72f8e8
commit 5043bad469
Signed by: rdelaage
GPG Key ID: 534845FADDF0C329
2 changed files with 44 additions and 0 deletions

4
go.mod
View File

@ -1,3 +1,7 @@
module git.rdelaage.ovh/rdelaage/VolumesAndDatabasesBackup
require (
github.com/docker/docker v20.10.11
)
go 1.17

40
volumes/volumes.go Normal file
View File

@ -0,0 +1,40 @@
package volumes
import (
"fmt"
"context"
"github.com/docker/docker/client"
"github.com/docker/docker/api/types"
"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)
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 {
//check no disable label
//add hash in volume list
}
return volumesList, nil
}