Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
restoredb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
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
infra
restoredb
Commits
72d9fa22
Commit
72d9fa22
authored
2 years ago
by
Jose Luis Zanotti
Browse files
Options
Downloads
Patches
Plain Diff
[IMP] Add option to skip aws download
parent
b1481e04
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
restorerdb.sh
+50
-0
50 additions, 0 deletions
restorerdb.sh
with
50 additions
and
0 deletions
restorerdb.sh
0 → 100755
+
50
−
0
View file @
72d9fa22
#!/bin/bash
# Abort if any command fails...
set
-e
function
get_aws_backup
{
echo
"Getting last backup available..."
BACKUP_NAME
=
$(
docker run
-e
AWS_ACCESS_KEY_ID
=
$AWS_ACCESS_KEY_ID
-e
AWS_SECRET_ACCESS_KEY
=
$AWS_SECRET_ACCESS_KEY
--rm
-v
/tmp:/tmp amazon/aws-cli s3
ls
$BASE_URL
|tail
-1
|tr
-s
' '
|cut
-d
' '
-f4
)
echo
"-> Latest backup:
$BACKUP_NAME
"
echo
"Downloading to /tmp/db.sql.gz..."
docker run
-e
AWS_ACCESS_KEY_ID
=
$AWS_ACCESS_KEY_ID
-e
AWS_SECRET_ACCESS_KEY
=
$AWS_SECRET_ACCESS_KEY
--rm
-v
/tmp:/tmp amazon/aws-cli s3
cp
$BASE_URL$BACKUP_NAME
/tmp/db.sql.gz
echo
"-> Downloaded"
}
function
stop_container
{
docker-compose stop
docker-compose up
-d
db
}
function
restore_db
{
echo
"drop database
$DB_DEST
"
|docker-compose
exec
-u
postgres
-T
db psql
-U
odoo
-d
postgres
echo
"create database
$DB_DEST
"
|docker-compose
exec
-u
postgres
-T
db psql
-U
odoo
-d
postgres
gunzip
-c
/tmp/db.sql.gz|docker-compose
exec
-u
postgres
-T
db psql
-U
odoo
-d
$DB_DEST
curl https://gitlab.eynes.com.ar/infra/eeutils/raw/master/eeutils/templates/auto_clean.sql | docker-compose
exec
-u
postgres
-T
db psql
-U
odoo
-d
$DB_DEST
}
VALID_ARGS
=
$(
getopt
-o
s
--long
skip-aws
--
"
$@
"
)
if
[[
$?
-ne
0
]]
;
then
exit
1
;
fi
eval set
--
"
$VALID_ARGS
"
while
[
:
]
;
do
case
"
$1
"
in
-s
|
--skip-aws
)
echo
"Processing from local file located in /tmp"
stop_container
restore_db
break
;;
*
)
shift
;
get_aws_backup
stop_container
restore_db
break
;;
esac
done
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