Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Postgres Backup S3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Circles
Postgres Backup S3
Commits
53c5ca4b
Commit
53c5ca4b
authored
2 years ago
by
Elliott Shugerman
Browse files
Options
Downloads
Patches
Plain Diff
share common env var code
parent
abbe4b37
Branches
master
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Dockerfile
+1
-0
1 addition, 0 deletions
Dockerfile
src/backup.sh
+1
-45
1 addition, 45 deletions
src/backup.sh
src/env.sh
+46
-0
46 additions, 0 deletions
src/env.sh
src/restore.sh
+1
-46
1 addition, 46 deletions
src/restore.sh
with
49 additions
and
91 deletions
Dockerfile
+
1
−
0
View file @
53c5ca4b
...
...
@@ -23,6 +23,7 @@ ENV PASSPHRASE ''
ENV
BACKUP_KEEP_DAYS ''
ADD
src/run.sh run.sh
ADD
src/env.sh env.sh
ADD
src/backup.sh backup.sh
ADD
src/restore.sh restore.sh
...
...
This diff is collapsed.
Click to expand it.
src/backup.sh
+
1
−
45
View file @
53c5ca4b
...
...
@@ -3,51 +3,7 @@
set
-eu
set
-o
pipefail
if
[
-z
"
$S3_BUCKET
"
]
;
then
echo
"You need to set the S3_BUCKET environment variable."
exit
1
fi
if
[
-z
"
$POSTGRES_DATABASE
"
]
;
then
echo
"You need to set the POSTGRES_DATABASE environment variable."
exit
1
fi
if
[
-z
"
$POSTGRES_HOST
"
]
;
then
if
[
-n
"
$POSTGRES_PORT_5432_TCP_ADDR
"
]
;
then
POSTGRES_HOST
=
$POSTGRES_PORT_5432_TCP_ADDR
POSTGRES_PORT
=
$POSTGRES_PORT_5432_TCP_PORT
else
echo
"You need to set the POSTGRES_HOST environment variable."
exit
1
fi
fi
if
[
-z
"
$POSTGRES_USER
"
]
;
then
echo
"You need to set the POSTGRES_USER environment variable."
exit
1
fi
if
[
-z
"
$POSTGRES_PASSWORD
"
]
;
then
echo
"You need to set the POSTGRES_PASSWORD environment variable."
exit
1
fi
if
[
-z
"
$S3_ENDPOINT
"
]
;
then
aws_args
=
""
else
aws_args
=
"--endpoint-url
$S3_ENDPOINT
"
fi
if
[
-n
"
$S3_ACCESS_KEY_ID
"
]
;
then
export
AWS_ACCESS_KEY_ID
=
$S3_ACCESS_KEY_ID
fi
if
[
-n
"
$S3_SECRET_ACCESS_KEY
"
]
;
then
export
AWS_SECRET_ACCESS_KEY
=
$S3_SECRET_ACCESS_KEY
fi
export
AWS_DEFAULT_REGION
=
$S3_REGION
export
PGPASSWORD
=
$POSTGRES_PASSWORD
source
./env.sh
echo
"Creating backup of
$POSTGRES_DATABASE
database..."
pg_dump
--format
=
custom
\
...
...
This diff is collapsed.
Click to expand it.
src/env.sh
0 → 100644
+
46
−
0
View file @
53c5ca4b
if
[
-z
"
$S3_BUCKET
"
]
;
then
echo
"You need to set the S3_BUCKET environment variable."
exit
1
fi
if
[
-z
"
$POSTGRES_DATABASE
"
]
;
then
echo
"You need to set the POSTGRES_DATABASE environment variable."
exit
1
fi
if
[
-z
"
$POSTGRES_HOST
"
]
;
then
# https://docs.docker.com/network/links/#environment-variables
if
[
-n
"
$POSTGRES_PORT_5432_TCP_ADDR
"
]
;
then
POSTGRES_HOST
=
$POSTGRES_PORT_5432_TCP_ADDR
POSTGRES_PORT
=
$POSTGRES_PORT_5432_TCP_PORT
else
echo
"You need to set the POSTGRES_HOST environment variable."
exit
1
fi
fi
if
[
-z
"
$POSTGRES_USER
"
]
;
then
echo
"You need to set the POSTGRES_USER environment variable."
exit
1
fi
if
[
-z
"
$POSTGRES_PASSWORD
"
]
;
then
echo
"You need to set the POSTGRES_PASSWORD environment variable."
exit
1
fi
if
[
-z
"
$S3_ENDPOINT
"
]
;
then
aws_args
=
""
else
aws_args
=
"--endpoint-url
$S3_ENDPOINT
"
fi
if
[
-n
"
$S3_ACCESS_KEY_ID
"
]
;
then
export
AWS_ACCESS_KEY_ID
=
$S3_ACCESS_KEY_ID
fi
if
[
-n
"
$S3_SECRET_ACCESS_KEY
"
]
;
then
export
AWS_SECRET_ACCESS_KEY
=
$S3_SECRET_ACCESS_KEY
fi
export
AWS_DEFAULT_REGION
=
$S3_REGION
export
PGPASSWORD
=
$POSTGRES_PASSWORD
This diff is collapsed.
Click to expand it.
src/restore.sh
+
1
−
46
View file @
53c5ca4b
...
...
@@ -3,52 +3,7 @@
set
-u
# `-e` omitted intentionally, but i can't remember why exactly :'(
set
-o
pipefail
if
[
-z
"
$S3_BUCKET
"
]
;
then
echo
"You need to set the S3_BUCKET environment variable."
exit
1
fi
if
[
-z
"
$POSTGRES_DATABASE
"
]
;
then
echo
"You need to set the POSTGRES_DATABASE environment variable."
exit
1
fi
if
[
-z
"
$POSTGRES_HOST
"
]
;
then
# https://docs.docker.com/network/links/#environment-variables
if
[
-n
"
$POSTGRES_PORT_5432_TCP_ADDR
"
]
;
then
POSTGRES_HOST
=
$POSTGRES_PORT_5432_TCP_ADDR
POSTGRES_PORT
=
$POSTGRES_PORT_5432_TCP_PORT
else
echo
"You need to set the POSTGRES_HOST environment variable."
exit
1
fi
fi
if
[
-z
"
$POSTGRES_USER
"
]
;
then
echo
"You need to set the POSTGRES_USER environment variable."
exit
1
fi
if
[
-z
"
$POSTGRES_PASSWORD
"
]
;
then
echo
"You need to set the POSTGRES_PASSWORD environment variable."
exit
1
fi
if
[
-z
"
$S3_ENDPOINT
"
]
;
then
aws_args
=
""
else
aws_args
=
"--endpoint-url
$S3_ENDPOINT
"
fi
if
[
-n
"
$S3_ACCESS_KEY_ID
"
]
;
then
export
AWS_ACCESS_KEY_ID
=
$S3_ACCESS_KEY_ID
fi
if
[
-n
"
$S3_SECRET_ACCESS_KEY
"
]
;
then
export
AWS_SECRET_ACCESS_KEY
=
$S3_SECRET_ACCESS_KEY
fi
export
AWS_DEFAULT_REGION
=
$S3_REGION
export
PGPASSWORD
=
$POSTGRES_PASSWORD
source
./env.sh
s3_uri_base
=
"s3://
${
S3_BUCKET
}
/
${
S3_PREFIX
}
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment