Skip to content

Commit 41e5ab1

Browse files
committed
Fix umask and add minio save test
1 parent 8f95cba commit 41e5ab1

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

commands/common.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ parse_options() {
8686

8787
# Options and long options
8888
local options="h:p:U:d:W:"
89-
local longopts="host:,port:,username:,dbname:,password:,password-file:,no-create-database,no-revoke-public-create,drop-database,format:,compression:,skip-globals,skip-database:,skip-analyze,full-count"
89+
local longopts="host:,port:,username:,dbname:,password:,password-file:,no-create-database,no-revoke-public-create,drop-database,format:,compression:,umask:,skip-globals,skip-database:,skip-analyze,full-count,aws-args:"
9090
local parsed
9191

9292
# Parse with getopt (not getopts)
@@ -138,6 +138,10 @@ parse_options() {
138138
format="${2}"
139139
shift 2
140140
;;
141+
--umask)
142+
umask="${2}"
143+
shift 2
144+
;;
141145
--compression)
142146
compression="${2}"
143147
shift 2
@@ -154,6 +158,10 @@ parse_options() {
154158
full_count="true"
155159
shift
156160
;;
161+
--aws-args)
162+
IFS=$' \n\t' read -r -a aws_args <<<"${2}"
163+
shift 2
164+
;;
157165
--)
158166
shift
159167
break

commands/save

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ usage() {
2828
echoerr ""
2929
echoerr "Options:"
3030
echoerr " --pgdump-args NOT IMPLEMENTED"
31+
echoerr " --aws-args OPTIONS"
3132
echoerr " --format plain|custom"
3233
echoerr " --compression gzip|lz4|bz2|none"
3334
echoerr " --date-format %Y%m%d%H%M%S"
@@ -61,7 +62,7 @@ case "${dest}" in
6162
;;
6263
s3://*)
6364
echo ">> aws s3"
64-
save_cmd=( "aws" "s3" "sync" "--no-progress" )
65+
save_cmd=( "aws" "${aws_args[@]}" "s3" "sync" "--no-progress" )
6566
dest_type="s3"
6667
;;
6768
file://*|/*|./*)
@@ -195,6 +196,7 @@ if [[ "${dest_type}" == "file" ]]; then
195196
ls -l "${full_path}"
196197
else
197198
echo ">> Uploading to ${full_path}"
199+
echoerr "${save_cmd[@]}" "${save_path}" "${full_path}"
198200
"${save_cmd[@]}" "${save_path}" "${full_path}"
199201

200202
# Clean up the save path if successful and not a file type save

tests/minio_setup.bash

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
setup() {
2+
minio_container="$(docker run -d \
3+
-e MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE \
4+
-e MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \
5+
-p "9000:9000" \
6+
-v $(DATA_DIR)/minio:/export \
7+
--entrypoint /bin/sh minio/minio:latest -c "mkdir -p /export/db-dumps && /usr/bin/minio server /export")"
8+
minio_container_ip="$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${minio_container})"
9+
}
10+
11+
teardown() {
12+
# teardown runs after each test
13+
docker rm -f "${minio_container}"
14+
}

tests/save.bats

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load test_functions.bash
2+
load minio_setup.bash
23

34
setup_file() {
45
export postgres_container="$(docker run -d -e POSTGRES_PASSWORD=password postgres:${POSTGRES_TARGET_VERSION})"
@@ -31,7 +32,19 @@ teardown_file() {
3132
-e DATABASE_USERNAME=postgres \
3233
-e DATABASE_PASSWORD=password \
3334
-v "${working_volume}:/db-dumps" \
34-
"${TOOLBOX_IMAGE}" save /db-dumps
35+
"${TOOLBOX_IMAGE}" save --umask 022 /db-dumps
36+
diag "${output}"
37+
[[ "${status}" -eq 0 ]]
38+
}
39+
40+
@test "save to minio/s3" {
41+
run docker run --rm \
42+
-e DATABASE_HOST=${postgres_container_ip} \
43+
-e DATABASE_USERNAME=postgres \
44+
-e DATABASE_PASSWORD=password \
45+
-e AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE \
46+
-e AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \
47+
"${TOOLBOX_IMAGE}" save --aws-args "--endpoint-url http://${minio_container_ip}:9000" --format custom --compression lz4 s3://db-dumps
3548
diag "${output}"
3649
[[ "${status}" -eq 0 ]]
3750
}

0 commit comments

Comments
 (0)