Skip to content

Commit

Permalink
add prototype for local storage support
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Jan 22, 2025
1 parent 0c17606 commit f21e29d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 0 additions & 1 deletion storage/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions storage/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
44 changes: 44 additions & 0 deletions storage/local.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit f21e29d

Please sign in to comment.