-
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.
migrate snapshot file utilities to unified storage func
- Loading branch information
1 parent
e232a22
commit 6e4efe5
Showing
3 changed files
with
34 additions
and
24 deletions.
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 |
---|---|---|
@@ -1,7 +1,34 @@ | ||
package storage | ||
|
||
import "github.com/aws/aws-sdk-go/service/s3/s3manager" | ||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/aws/aws-sdk-go/service/s3/s3manager" | ||
|
||
"github.com/mschuchard/vault-raft-backup/util" | ||
) | ||
|
||
func StorageTransfer(config *awsConfig, snapshotPath string, cleanup bool) (*s3manager.UploadOutput, error) { | ||
return snapshotS3Upload(config, snapshotPath, cleanup) | ||
// use supplied prefix and snapshot base filename for full name | ||
snapshotName := config.s3Prefix + "-" + filepath.Base(snapshotPath) | ||
|
||
// open snapshot file | ||
snapshotFile, err := os.Open(snapshotPath) | ||
if err != nil { | ||
log.Printf("failed to open snapshot file %q: %v", snapshotPath, err) | ||
return nil, err | ||
} | ||
|
||
// defer snapshot close and remove | ||
defer func() { | ||
err = util.SnapshotFileClose(snapshotFile) | ||
if cleanup { | ||
err = util.SnapshotFileRemove(snapshotFile) | ||
} | ||
}() | ||
|
||
// TODO: clobbers deferred err from snapshot close and remove | ||
return snapshotS3Upload(config, snapshotFile, snapshotName) | ||
} |