-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add prototype for local storage support
- Loading branch information
1 parent
0c17606
commit f21e29d
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |