forked from wal-g/wal-g
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add get/put/rm to storage tools (wal-g#1069)
- Loading branch information
1 parent
eaa57be
commit 68a7a2b
Showing
14 changed files
with
451 additions
and
20 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package st | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/wal-g/tracelog" | ||
"github.com/wal-g/wal-g/internal" | ||
"github.com/wal-g/wal-g/internal/storagetools" | ||
) | ||
|
||
const deleteObjectShortDescription = "Delete the specified storage object" | ||
|
||
// deleteObjectCmd represents the deleteObject command | ||
var deleteObjectCmd = &cobra.Command{ | ||
Use: "rm relative_object_path", | ||
Short: deleteObjectShortDescription, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
folder, err := internal.ConfigureFolder() | ||
tracelog.ErrorLogger.FatalOnError(err) | ||
|
||
storagetools.HandleDeleteObject(args[0], folder) | ||
}, | ||
} | ||
|
||
func init() { | ||
StorageToolsCmd.AddCommand(deleteObjectCmd) | ||
} |
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,40 @@ | ||
package st | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/wal-g/tracelog" | ||
"github.com/wal-g/wal-g/internal" | ||
"github.com/wal-g/wal-g/internal/storagetools" | ||
) | ||
|
||
const ( | ||
getObjectShortDescription = "Download the specified storage object" | ||
|
||
noDecryptFlag = "no-decrypt" | ||
noDecompressFlag = "no-decompress" | ||
) | ||
|
||
// getObjectCmd represents the getObject command | ||
var getObjectCmd = &cobra.Command{ | ||
Use: "get relative_object_path destination_path", | ||
Short: getObjectShortDescription, | ||
Args: cobra.ExactArgs(2), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
objectPath := args[0] | ||
dstPath := args[1] | ||
|
||
folder, err := internal.ConfigureFolder() | ||
tracelog.ErrorLogger.FatalOnError(err) | ||
|
||
storagetools.HandleGetObject(objectPath, dstPath, folder, !noDecrypt, !noDecompress) | ||
}, | ||
} | ||
|
||
var noDecrypt bool | ||
var noDecompress bool | ||
|
||
func init() { | ||
StorageToolsCmd.AddCommand(getObjectCmd) | ||
getObjectCmd.Flags().BoolVar(&noDecrypt, noDecryptFlag, false, "Do not decrypt the object") | ||
getObjectCmd.Flags().BoolVar(&noDecompress, noDecompressFlag, false, "Do not decompress the object") | ||
} |
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,45 @@ | ||
package st | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/wal-g/tracelog" | ||
"github.com/wal-g/wal-g/internal" | ||
"github.com/wal-g/wal-g/internal/storagetools" | ||
) | ||
|
||
const ( | ||
putObjectShortDescription = "Upload the specified file to the storage" | ||
|
||
noEncryptFlag = "no-encrypt" | ||
noCompressFlag = "no-compress" | ||
overwriteFlag = "force" | ||
overwriteShorthand = "f" | ||
) | ||
|
||
// putObjectCmd represents the putObject command | ||
var putObjectCmd = &cobra.Command{ | ||
Use: "put local_path destination_path", | ||
Short: putObjectShortDescription, | ||
Args: cobra.ExactArgs(2), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
uploader, err := internal.ConfigureUploader() | ||
tracelog.ErrorLogger.FatalOnError(err) | ||
|
||
localPath := args[0] | ||
dstPath := args[1] | ||
|
||
storagetools.HandlePutObject(localPath, dstPath, uploader, overwrite, !noEncrypt, !noCompress) | ||
}, | ||
} | ||
|
||
var noEncrypt bool | ||
var noCompress bool | ||
var overwrite bool | ||
|
||
func init() { | ||
StorageToolsCmd.AddCommand(putObjectCmd) | ||
putObjectCmd.Flags().BoolVar(&noEncrypt, noEncryptFlag, false, "Do not encrypt the object") | ||
putObjectCmd.Flags().BoolVar(&noCompress, noCompressFlag, false, "Do not compress the object") | ||
putObjectCmd.Flags().BoolVarP(&overwrite, overwriteFlag, overwriteShorthand, | ||
false, "Overwrite the existing object") | ||
} |
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,34 @@ | ||
FROM wal-g/golang:latest as build | ||
|
||
WORKDIR /go/src/github.com/wal-g/wal-g | ||
|
||
RUN apt-get update && \ | ||
apt-get install --yes --no-install-recommends --no-install-suggests \ | ||
liblzo2-dev | ||
|
||
RUN ls | ||
|
||
COPY go.mod go.mod | ||
COPY vendor/ vendor/ | ||
COPY internal/ internal/ | ||
COPY pkg/ pkg/ | ||
COPY cmd/ cmd/ | ||
COPY main/ main/ | ||
COPY utility/ utility/ | ||
|
||
RUN sed -i 's|#cgo LDFLAGS: -lbrotli.*|&-static -lbrotlicommon-static -lm|' \ | ||
vendor/github.com/google/brotli/go/cbrotli/cgo.go && \ | ||
sed -i 's|\(#cgo LDFLAGS:\) .*|\1 -Wl,-Bstatic -llzo2 -Wl,-Bdynamic|' \ | ||
vendor/github.com/cyberdelia/lzo/lzo.go && \ | ||
cd main/pg && \ | ||
go build -mod vendor -race -o wal-g -tags "brotli lzo" -ldflags "-s -w -X main.buildDate=`date -u +%Y.%m.%d_%H:%M:%S`" | ||
|
||
FROM wal-g/ubuntu:latest | ||
|
||
RUN apt-get update && apt-get install --yes --no-install-recommends --no-install-suggests brotli | ||
|
||
COPY --from=build /go/src/github.com/wal-g/wal-g/main/pg/wal-g /usr/bin | ||
|
||
COPY docker/st_tests/scripts/ /tmp | ||
|
||
CMD /tmp/tests/storage_tool_tests.sh |
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,54 @@ | ||
#!/bin/sh | ||
set -e -x | ||
|
||
export WALE_S3_PREFIX=s3://storagetoolsbucket | ||
|
||
# Empty list on empty storage | ||
test "1" -eq "$(wal-g st ls | wc -l)" | ||
|
||
# Generate and upload some file to storage | ||
head -c 100M </dev/urandom >testfile | ||
wal-g st put testfile testfolder/testfile | ||
|
||
# Should not upload the duplicate file by default | ||
wal-g st put testfile testfolder/testfile && EXIT_STATUS=$? || EXIT_STATUS=$? | ||
|
||
if [ "$EXIT_STATUS" -eq 0 ] ; then | ||
echo "Error: Duplicate object was uploaded without the -f flag" | ||
exit 1 | ||
fi | ||
|
||
# Should upload the duplicate file if -f flag is present | ||
wal-g st put testfile testfolder/testfile -f | ||
|
||
wal-g st ls | ||
# WAL-G should show the uploaded file in the wal-g st ls output | ||
test "2" -eq "$(wal-g st ls | wc -l)" | ||
|
||
# WAL-G should be able to download the uploaded file | ||
wal-g st get testfolder/testfile.br fetched_testfile | ||
|
||
# Downloaded file should be identical to the original one | ||
diff testfile fetched_testfile | ||
rm fetched_testfile | ||
|
||
# WAL-G should be able to download the uploaded file without decompression | ||
wal-g st get testfolder/testfile.br uncompressed_testfile.br --no-decompress | ||
|
||
brotli --decompress uncompressed_testfile.br | ||
diff testfile uncompressed_testfile | ||
rm uncompressed_testfile | ||
|
||
# WAL-G should be able to delete the uploaded file | ||
wal-g st rm testfolder/testfile.br | ||
|
||
# Should get empty storage after file removal | ||
test "1" -eq "$(wal-g st ls | wc -l)" | ||
|
||
# Should upload the file uncompressed without error | ||
wal-g st put testfile testfolder/testfile --no-compress | ||
|
||
# Should download the file uncompressed without error | ||
wal-g st get testfolder/testfile uncompressed_file --no-decompress | ||
|
||
diff testfile uncompressed_file |
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
Oops, something went wrong.