You've already forked docker-volume-backup
mirror of
https://github.com/offen/docker-volume-backup.git
synced 2025-11-23 21:44:40 +02:00
Ensure destination exists when using SSH storage (#646)
* Ensure destination exists when using SSH storage * Import "errors" * New feature doc
This commit is contained in:
@@ -278,6 +278,7 @@ The values for each key currently match its default.
|
||||
# ---
|
||||
|
||||
# The Directory to place the backups to on the SSH server.
|
||||
# If the directory does not exist, it will be created automatically.
|
||||
# Example: "/home/user/backups"
|
||||
|
||||
# SSH_REMOTE_PATH=""
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -107,6 +108,10 @@ func (b *sshStorage) Name() string {
|
||||
|
||||
// Copy copies the given file to the SSH storage backend.
|
||||
func (b *sshStorage) Copy(file string) (returnErr error) {
|
||||
if err := b.sftpClient.MkdirAll(b.DestinationPath); err != nil {
|
||||
return errwrap.Wrap(err, "error ensuring destination directory")
|
||||
}
|
||||
|
||||
source, err := os.Open(file)
|
||||
_, name := path.Split(file)
|
||||
if err != nil {
|
||||
@@ -170,6 +175,10 @@ func (b *sshStorage) Copy(file string) (returnErr error) {
|
||||
func (b *sshStorage) Prune(deadline time.Time, pruningPrefix string) (*storage.PruneStats, error) {
|
||||
candidates, err := b.sftpClient.ReadDir(b.DestinationPath)
|
||||
if err != nil {
|
||||
// If directory doesn't exist yet, nothing to prune
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return &storage.PruneStats{}, nil
|
||||
}
|
||||
return nil, errwrap.Wrap(err, "error reading directory")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user