mirror of
https://github.com/offen/docker-volume-backup.git
synced 2026-02-04 09:19:06 +08: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:
parent
614d325c5a
commit
2d777ad76a
2 changed files with 10 additions and 0 deletions
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue