diff --git a/storage/aws.go b/storage/aws.go index 3fea642..9170155 100644 --- a/storage/aws.go +++ b/storage/aws.go @@ -38,6 +38,5 @@ func snapshotS3Upload(s3Bucket string, snapshotFile io.Reader, snapshotName stri // output s3 uploader location info log.Printf("Vault Raft snapshot uploaded to %s with key %s", uploadResult.Location, *uploadResult.Key) - return err } diff --git a/storage/gcp.go b/storage/gcp.go index 171e72f..2db3d7c 100644 --- a/storage/gcp.go +++ b/storage/gcp.go @@ -42,5 +42,6 @@ func snapshotCSUpload(csBucket string, snapshotFile io.Reader, snapshotName stri return err } + log.Printf("Vault Raft snapshot successfully uploaded to %s bucket with name %s", csBucket, snapshotName) return nil } diff --git a/storage/local.go b/storage/local.go new file mode 100644 index 0000000..b41f2b1 --- /dev/null +++ b/storage/local.go @@ -0,0 +1,44 @@ +package storage + +import ( + "io" + "log" + "os" + + "github.com/mschuchard/vault-raft-backup/util" +) + +// snapshot copy to local filesystem +func snapshotFSCopy(directory string, snapshotFile io.Reader, snapshotName string) error { + // validate destination directory + if _, err := os.ReadDir(directory); err != nil { + log.Printf("the destination directory at %s is unsuitable for copying the snapshot file", directory) + return err + } + + // open output file + destination := directory + snapshotName + destinationWriter, err := os.Open(destination) + if err != nil { + log.Printf("a destination file at %s could not be opened for streaming", destination) + return err + } + + // defer snapshot destination close + defer func() { + err = util.SnapshotFileClose(destinationWriter) + }() + + // copy snapshot to destination + if _, err = io.Copy(destinationWriter, snapshotFile); err != nil { + log.Printf("the snapshot file at %s could not be copied to the destination at %s", snapshotFile, destination) + return err + } + if err := destinationWriter.Sync(); err != nil { + log.Printf("the snapshot file at %s could not be copied to the destination at %s", snapshotFile, destination) + return err + } + + log.Printf("snapshotfile successfully copied to %s", destination) + return nil +}