mirror of
https://github.com/offen/docker-volume-backup.git
synced 2024-11-10 00:30:29 +01:00
Tweak README, improve client naming, tidy go.mod file
This commit is contained in:
parent
6ded00aa06
commit
1db896f7cf
@ -7,7 +7,7 @@
|
|||||||
Backup Docker volumes locally or to any S3 compatible storage.
|
Backup Docker volumes locally or to any S3 compatible storage.
|
||||||
|
|
||||||
The [offen/docker-volume-backup](https://hub.docker.com/r/offen/docker-volume-backup) Docker image can be used as a lightweight (below 15MB) sidecar container to an existing Docker setup.
|
The [offen/docker-volume-backup](https://hub.docker.com/r/offen/docker-volume-backup) Docker image can be used as a lightweight (below 15MB) sidecar container to an existing Docker setup.
|
||||||
It handles __recurring or one-off backups of Docker volumes__ to a __local directory__, __any S3 or WebDAV compatible storage (or any combination) and __rotates away old backups__ if configured. It also supports __encrypting your backups using GPG__ and __sending notifications for failed backup runs__.
|
It handles __recurring or one-off backups of Docker volumes__ to a __local directory__, __any S3 or WebDAV compatible storage (or any combination) and rotates away old backups__ if configured. It also supports __encrypting your backups using GPG__ and __sending notifications for failed backup runs__.
|
||||||
|
|
||||||
<!-- MarkdownTOC -->
|
<!-- MarkdownTOC -->
|
||||||
|
|
||||||
@ -190,13 +190,14 @@ You can populate below template according to your requirements and use it as you
|
|||||||
|
|
||||||
# AWS_ENDPOINT_INSECURE="true"
|
# AWS_ENDPOINT_INSECURE="true"
|
||||||
|
|
||||||
# In addition, you can also backup files to any WebDAV server.
|
# You can also backup files to any WebDAV server:
|
||||||
|
|
||||||
# The URL of the remote WebDAV server
|
# The URL of the remote WebDAV server
|
||||||
|
|
||||||
# WEBDAV_URL="https://webdav.example.com"
|
# WEBDAV_URL="https://webdav.example.com"
|
||||||
|
|
||||||
# The Directory to place the backups to on the WebDAV server.
|
# The Directory to place the backups to on the WebDAV server.
|
||||||
# If the path is not present on the server it will be created!
|
# If the path is not present on the server it will be created.
|
||||||
|
|
||||||
# WEBDAV_PATH="/my/directory/"
|
# WEBDAV_PATH="/my/directory/"
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ import (
|
|||||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||||
"github.com/otiai10/copy"
|
"github.com/otiai10/copy"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/crypto/openpgp"
|
|
||||||
"github.com/studio-b12/gowebdav"
|
"github.com/studio-b12/gowebdav"
|
||||||
|
"golang.org/x/crypto/openpgp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -88,13 +88,13 @@ func main() {
|
|||||||
// script holds all the stateful information required to orchestrate a
|
// script holds all the stateful information required to orchestrate a
|
||||||
// single backup run.
|
// single backup run.
|
||||||
type script struct {
|
type script struct {
|
||||||
cli *client.Client
|
cli *client.Client
|
||||||
mc *minio.Client
|
minioClient *minio.Client
|
||||||
webdavClient *gowebdav.Client
|
webdavClient *gowebdav.Client
|
||||||
logger *logrus.Logger
|
logger *logrus.Logger
|
||||||
sender *router.ServiceRouter
|
sender *router.ServiceRouter
|
||||||
hooks []hook
|
hooks []hook
|
||||||
hookLevel hookLevel
|
hookLevel hookLevel
|
||||||
|
|
||||||
start time.Time
|
start time.Time
|
||||||
file string
|
file string
|
||||||
@ -213,11 +213,9 @@ func newScript() (*script, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("newScript: error setting up minio client: %w", err)
|
return nil, fmt.Errorf("newScript: error setting up minio client: %w", err)
|
||||||
}
|
}
|
||||||
s.mc = mc
|
s.minioClient = mc
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebDAV check for env variables
|
|
||||||
// WebDAV instanciate client
|
|
||||||
if s.c.WebdavUrl != "" {
|
if s.c.WebdavUrl != "" {
|
||||||
if s.c.WebdavUsername == "" || s.c.WebdavPassword == "" {
|
if s.c.WebdavUsername == "" || s.c.WebdavPassword == "" {
|
||||||
return nil, errors.New("newScript: WEBDAV_URL is defined, but no credentials were provided")
|
return nil, errors.New("newScript: WEBDAV_URL is defined, but no credentials were provided")
|
||||||
@ -526,8 +524,8 @@ func (s *script) encryptBackup() error {
|
|||||||
// as per the given configuration.
|
// as per the given configuration.
|
||||||
func (s *script) copyBackup() error {
|
func (s *script) copyBackup() error {
|
||||||
_, name := path.Split(s.file)
|
_, name := path.Split(s.file)
|
||||||
if s.mc != nil {
|
if s.minioClient != nil {
|
||||||
if _, err := s.mc.FPutObject(context.Background(), s.c.AwsS3BucketName, name, s.file, minio.PutObjectOptions{
|
if _, err := s.minioClient.FPutObject(context.Background(), s.c.AwsS3BucketName, name, s.file, minio.PutObjectOptions{
|
||||||
ContentType: "application/tar+gzip",
|
ContentType: "application/tar+gzip",
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return fmt.Errorf("copyBackup: error uploading backup to remote storage: %w", err)
|
return fmt.Errorf("copyBackup: error uploading backup to remote storage: %w", err)
|
||||||
@ -535,7 +533,6 @@ func (s *script) copyBackup() error {
|
|||||||
s.logger.Infof("Uploaded a copy of backup `%s` to bucket `%s`.", s.file, s.c.AwsS3BucketName)
|
s.logger.Infof("Uploaded a copy of backup `%s` to bucket `%s`.", s.file, s.c.AwsS3BucketName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebDAV file upload
|
|
||||||
if s.webdavClient != nil {
|
if s.webdavClient != nil {
|
||||||
bytes, err := os.ReadFile(s.file)
|
bytes, err := os.ReadFile(s.file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -585,8 +582,8 @@ func (s *script) pruneOldBackups() error {
|
|||||||
deadline := time.Now().AddDate(0, 0, -int(s.c.BackupRetentionDays))
|
deadline := time.Now().AddDate(0, 0, -int(s.c.BackupRetentionDays))
|
||||||
|
|
||||||
// Prune minio/S3 backups
|
// Prune minio/S3 backups
|
||||||
if s.mc != nil {
|
if s.minioClient != nil {
|
||||||
candidates := s.mc.ListObjects(context.Background(), s.c.AwsS3BucketName, minio.ListObjectsOptions{
|
candidates := s.minioClient.ListObjects(context.Background(), s.c.AwsS3BucketName, minio.ListObjectsOptions{
|
||||||
WithMetadata: true,
|
WithMetadata: true,
|
||||||
Prefix: s.c.BackupPruningPrefix,
|
Prefix: s.c.BackupPruningPrefix,
|
||||||
})
|
})
|
||||||
@ -614,7 +611,7 @@ func (s *script) pruneOldBackups() error {
|
|||||||
}
|
}
|
||||||
close(objectsCh)
|
close(objectsCh)
|
||||||
}()
|
}()
|
||||||
errChan := s.mc.RemoveObjects(context.Background(), s.c.AwsS3BucketName, objectsCh, minio.RemoveObjectsOptions{})
|
errChan := s.minioClient.RemoveObjects(context.Background(), s.c.AwsS3BucketName, objectsCh, minio.RemoveObjectsOptions{})
|
||||||
var removeErrors []error
|
var removeErrors []error
|
||||||
for result := range errChan {
|
for result := range errChan {
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
|
2
go.mod
2
go.mod
@ -12,6 +12,7 @@ require (
|
|||||||
github.com/minio/minio-go/v7 v7.0.16
|
github.com/minio/minio-go/v7 v7.0.16
|
||||||
github.com/otiai10/copy v1.7.0
|
github.com/otiai10/copy v1.7.0
|
||||||
github.com/sirupsen/logrus v1.8.1
|
github.com/sirupsen/logrus v1.8.1
|
||||||
|
github.com/studio-b12/gowebdav v0.0.0-20211109083228-3f8721cd4b6f
|
||||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
|
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,7 +46,6 @@ require (
|
|||||||
github.com/opencontainers/image-spec v1.0.1 // indirect
|
github.com/opencontainers/image-spec v1.0.1 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/rs/xid v1.3.0 // indirect
|
github.com/rs/xid v1.3.0 // indirect
|
||||||
github.com/studio-b12/gowebdav v0.0.0-20211109083228-3f8721cd4b6f // indirect
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
|
||||||
golang.org/x/text v0.3.6 // indirect
|
golang.org/x/text v0.3.6 // indirect
|
||||||
|
Loading…
Reference in New Issue
Block a user