Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Dockerfiles
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
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
shore
Dockerfiles
Commits
64f5d0f8
Commit
64f5d0f8
authored
1 year ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
Postgres: Backup and restore scripts.
parent
3537690f
No related branches found
No related tags found
No related merge requests found
Pipeline
#3640
passed
1 year ago
Stage: .pre
Stage: build
Stage: deploy
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
postgres/Dockerfile
+1
-1
1 addition, 1 deletion
postgres/Dockerfile
postgres/README.md
+24
-0
24 additions, 0 deletions
postgres/README.md
postgres/backup
+6
-0
6 additions, 0 deletions
postgres/backup
postgres/restore
+6
-0
6 additions, 0 deletions
postgres/restore
with
37 additions
and
1 deletion
postgres/Dockerfile
+
1
−
1
View file @
64f5d0f8
FROM
docker.io/postgres:16.1-alpine3.19
COPY
--chown=root:root healthcheck /usr/local/bin/
COPY
--chown=root:root healthcheck
backup restore
/usr/local/bin/
HEALTHCHECK
--start-period=3m CMD healthcheck
This diff is collapsed.
Click to expand it.
postgres/README.md
+
24
−
0
View file @
64f5d0f8
# postgres
Just the upstream image but with a healthcheck.
## Backups
The image includes a
`backup`
and
`restore`
scripts. The
`backup`
scripts dumps
all of the databases using
`pg_dumpall`
and compresses the output using
`zstd`
to stdout. This is meant so that backups are run by an external process and it
saves the output to a file, for example:
```
docker exec pg1 backup > /var/backups/pg1/dump.sql.zstd
```
The
`restore`
script matches the
`backup`
script in that the it reads a zstd
compress SQL dump from stdin. An example restore:
```
cat dump.sql.zstd | docker exec -i pg2 restore
```
In fact you're able to migrate data from 1 instance to another like so:
```
docker exec pg1 backup | docker exec -i pg2 restore
```
This diff is collapsed.
Click to expand it.
postgres/backup
0 → 100755
+
6
−
0
View file @
64f5d0f8
#!/usr/bin/env bash
set
-euo
pipefail
export
PGUSER
=
"
${
POSTGRES_USER
:-
postgres
}
"
pg_dumpall | zstd
This diff is collapsed.
Click to expand it.
postgres/restore
0 → 100755
+
6
−
0
View file @
64f5d0f8
#!/usr/bin/env bash
set
-euo
pipefail
export
PGUSER
=
"
${
POSTGRES_USER
:-
postgres
}
"
zstd
--decompress
- | psql
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