-
Notifications
You must be signed in to change notification settings - Fork 16
Pm 663 control dump scratch area location #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
8c21f91
292491d
1d59094
2fcb593
7c779ce
dfbd82b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,9 @@ set -e | |
|
|
||
| setup.sh | ||
|
|
||
| max_pg_wait_count=120 | ||
| work_area=${PGDUMP_BACKUP_AREA:-/pg_dump} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does the work area need to be configurable? Do you want to bind mount it from a different host volume, and are then unable to Maybe we just
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we're wanting this in a different volume, and force making this in Making the path configurable lets you tune things without hand configuring the container build with a bind mount. Far better to have the script be somewhat generic by being able to tell it where to work. One stong advantage of the mkdir is that we know we make the work and nobody else might be using it. Otherwise the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure I follow. Are you using this script outside of a container? From what I have seen, it is fairly common for Docker images to store data in a subdirectory of As far as I can tell, there is no point in making the directory configurable unless you are wanting to use a bind mount, which must be hand configured by you in your compose file or I think we could just use Fair point about the safety of retaining the mkdir and exit if it already exists. Though, if something ever goes wrong and a container exits (e.g. OOM killed) before having removed the directory, the container will not be able to restart resume backups without intervention? |
||
|
|
||
| for i in {1..5}; do | ||
| export HOSTNAME_VAR="HOSTNAME_$i" | ||
| export PGHOST_VAR="PGHOST_$i" | ||
|
|
@@ -28,37 +31,42 @@ for i in {1..5}; do | |
| echo "Dumping database cluster $i: $PGUSER@$PGHOST:$PGPORT" | ||
|
|
||
| # Wait for PostgreSQL to become available. | ||
| COUNT=0 | ||
| count=0 | ||
| until psql -l > /dev/null 2>&1; do | ||
| if [[ "$COUNT" == 0 ]]; then | ||
| if [[ "$count" == 0 ]]; then | ||
| echo "Waiting for PostgreSQL to become available..." | ||
| fi | ||
| (( COUNT += 1 )) | ||
| (( count += 1 )) | ||
| [ $count -lt $max_pg_wait_count ] || break | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly because I pretty much never use [[ in my own scripts - its utility is generally tiny and it is less portable. I'll tweak this for consistency though. |
||
| sleep 1 | ||
| done | ||
| if (( COUNT > 0 )); then | ||
| echo "Waited $COUNT seconds." | ||
| if (( count > 0 )); then | ||
| echo "Waited $count seconds." | ||
| psql -l > /dev/null 2>&1 || { | ||
| echo "PostgreSQL still not available, trying next backup." | ||
| continue | ||
| } | ||
| fi | ||
|
|
||
| mkdir -p "/pg_dump" | ||
| mkdir "$work_area" || exit 1 | ||
|
Comment on lines
-43
to
+54
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elaborate on the problem with
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue with
Why might 2 scripts be running? If the backups take a very long time, something which creeps up on one for a fixed cronlike schedule. Forcing a mkdir is robust. I like |
||
|
|
||
| # Dump individual databases directly to restic repository. | ||
| DBLIST=$(psql -d postgres -q -t -c "SELECT datname FROM pg_database WHERE datname NOT IN ('postgres', 'rdsadmin', 'template0', 'template1')") | ||
| for dbname in $DBLIST; do | ||
| dblist=$(psql -d postgres -q -t -c "SELECT datname FROM pg_database WHERE datname NOT IN ('postgres', 'rdsadmin', 'template0', 'template1')") | ||
| for dbname in $dblist; do | ||
| echo "Dumping database '$dbname'" | ||
| pg_dump --file="/pg_dump/$dbname.sql" --no-owner --no-privileges --dbname="$dbname" || true # Ignore failures | ||
| pg_dump --file="$work_area/$dbname.sql" --no-owner --no-privileges --dbname="$dbname" || true # Ignore failures | ||
| done | ||
|
|
||
| # echo "Dumping global objects for '$PGHOST'" | ||
| # pg_dumpall --file="/pg_dump/!globals.sql" --globals-only | ||
| # pg_dumpall --file="$work_area/!globals.sql" --globals-only | ||
|
|
||
| echo "Sending database dumps to S3" | ||
| while ! restic backup --host "$HOSTNAME" "/pg_dump"; do | ||
| while ! restic backup --host "$HOSTNAME" "$work_area"; do | ||
| echo "Sleeping for 10 seconds before retry..." | ||
| sleep 10 | ||
| done | ||
|
|
||
| echo 'Finished sending database dumps to S3' | ||
|
|
||
| rm -rf "/pg_dump" | ||
| rm -rf "$work_area" | ||
| done | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this configurable via env var and default to 120?