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
4b809ff8
Commit
4b809ff8
authored
8 months ago
by
Michael Hollister
Browse files
Options
Downloads
Patches
Plain Diff
Revert "Merge branch 'michael/multiple-database-restore' into 'master'"
This reverts commit
be87fe1d
, reversing changes made to
9beb7d7a
.
parent
be87fe1d
Branches
master
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/restore.sh
+27
-34
27 additions, 34 deletions
src/restore.sh
with
27 additions
and
34 deletions
src/restore.sh
+
27
−
34
View file @
4b809ff8
...
...
@@ -13,39 +13,32 @@ else
file_type
=
".dump.gpg"
fi
OIFS
=
"
$IFS
"
IFS
=
','
for
DB
in
$POSTGRES_DATABASE
do
IFS
=
"
$OIFS
"
if
[
$#
-eq
1
]
;
then
timestamp
=
"
$1
"
key_suffix
=
"
${
DB
}
_
${
timestamp
}${
file_type
}
"
else
echo
"Finding latest backup..."
key_suffix
=
$(
aws
$aws_args
s3
ls
"
${
s3_uri_base
}
/
${
DB
}
"
\
|
sort
\
|
tail
-n
1
\
|
awk
'{ print $4 }'
)
fi
echo
"Fetching backup from S3..."
aws
$aws_args
s3
cp
"
${
s3_uri_base
}
/
${
key_suffix
}
"
"db
${
file_type
}
"
if
[
-n
"
$PASSPHRASE
"
]
;
then
echo
"Decrypting backup..."
gpg
--decrypt
--batch
--passphrase
"
$PASSPHRASE
"
db.dump.gpg
>
db.dump
rm
db.dump.gpg
fi
conn_opts
=
"-h
$POSTGRES_HOST
-p
$POSTGRES_PORT
-U
$POSTGRES_USER
-d
$DB
"
echo
"Restoring from backup..."
pg_restore
$conn_opts
--clean
--if-exists
db.dump
rm
db.dump
done
if
[
$#
-eq
1
]
;
then
timestamp
=
"
$1
"
key_suffix
=
"
${
POSTGRES_DATABASE
}
_
${
timestamp
}${
file_type
}
"
else
echo
"Finding latest backup..."
key_suffix
=
$(
aws
$aws_args
s3
ls
"
${
s3_uri_base
}
/
${
POSTGRES_DATABASE
}
"
\
|
sort
\
|
tail
-n
1
\
|
awk
'{ print $4 }'
)
fi
echo
"Fetching backup from S3..."
aws
$aws_args
s3
cp
"
${
s3_uri_base
}
/
${
key_suffix
}
"
"db
${
file_type
}
"
if
[
-n
"
$PASSPHRASE
"
]
;
then
echo
"Decrypting backup..."
gpg
--decrypt
--batch
--passphrase
"
$PASSPHRASE
"
db.dump.gpg
>
db.dump
rm
db.dump.gpg
fi
conn_opts
=
"-h
$POSTGRES_HOST
-p
$POSTGRES_PORT
-U
$POSTGRES_USER
-d
$POSTGRES_DATABASE
"
echo
"Restoring from backup..."
pg_restore
$conn_opts
--clean
--if-exists
db.dump
rm
db.dump
echo
"Restore complete."
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