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
be87fe1d
Commit
be87fe1d
authored
8 months ago
by
Michael Hollister
Browse files
Options
Downloads
Plain Diff
Merge branch 'michael/multiple-database-restore' into 'master'
Added support for multi database restore See merge request
!2
parents
9beb7d7a
426f3e92
Branches
master
No related tags found
1 merge request
!2
Added support for multi database restore
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/restore.sh
+34
-27
34 additions, 27 deletions
src/restore.sh
with
34 additions
and
27 deletions
src/restore.sh
+
34
−
27
View file @
be87fe1d
...
...
@@ -13,32 +13,39 @@ else
file_type
=
".dump.gpg"
fi
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
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
echo
"Restore complete."
This diff is collapsed.
Click to expand it.
Michael Hollister
@michael
mentioned in commit
4b809ff8
·
8 months ago
mentioned in commit
4b809ff8
mentioned in commit 4b809ff8ad8fd7ba6de003ee8ac1ecdd73d876e1
Toggle commit list
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