Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Odoo scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo scripts
Commits
a7fbd57807c5
Commit
a7fbd57807c5
authored
6 years ago
by
Vincent Hatakeyama
Browse files
Options
Downloads
Patches
Plain Diff
add option to restore database
parent
1b7e1f5bc641
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docker_dev_start.py
+65
-9
65 additions, 9 deletions
docker_dev_start.py
with
65 additions
and
9 deletions
docker_dev_start.py
+
65
−
9
View file @
a7fbd578
...
...
@@ -5,6 +5,7 @@
"""
# Version 2.17
import
argparse
import
atexit
import
glob
import
logging
import
os
...
...
@@ -31,7 +32,7 @@
_logger
=
logging
.
getLogger
(
__name__
)
__version__
=
'
1.1.
1
'
__version__
=
'
1.1.
2
'
__date__
=
'
2017-08-11
'
__updated__
=
'
2018-07-12
'
...
...
@@ -78,7 +79,7 @@
program_license
=
'''
%s
Created by Vincent Hatakeyama on %s.
Copyright 2017 XCG Consulting. All rights reserved.
Copyright 2017
, 2018
XCG Consulting. All rights reserved.
Licensed under the MIT License
...
...
@@ -249,6 +250,12 @@
default
=
None
,
choices
=
odoo_log_levels
,
)
parser
.
add_argument
(
'
--restore
'
,
help
=
"
Database to restore [default: %(default)s]
"
,
default
=
None
,
dest
=
'
DUMP
'
,
)
# TODO detect that user is member of docker group
...
...
@@ -270,6 +277,13 @@
run_flake8
=
nmspc
.
flake8
odoo_help
=
nmspc
.
odoo_help
dev
=
nmspc
.
dev
restore_filename
=
nmspc
.
DUMP
database
=
nmspc
.
database
if
restore_filename
:
if
not
database
:
logging
.
fatal
(
'
No database name given for restore
'
)
return
13
c
=
ConfigParser
()
if
not
os
.
path
.
exists
(
setup_path
):
...
...
@@ -359,8 +373,8 @@
if
odoo_type
==
'
odoo7
'
:
arg
.
append
(
'
--log-level=test
'
)
arg
.
append
(
'
--stop-after-init
'
)
if
nmspc
.
database
:
arg
.
append
(
'
-d %s
'
%
nmspc
.
database
)
if
database
:
arg
.
append
(
'
-d %s
'
%
database
)
if
nmspc
.
install
or
nmspc
.
install_default
:
modules_to_install
=
[]
if
nmspc
.
install
:
...
...
@@ -374,7 +388,7 @@
arg
.
append
(
'
-i
'
)
arg
.
append
(
'
,
'
.
join
(
modules_to_install
))
if
nmspc
.
without_demo
:
arg
.
append
(
'
--without-demo %s
'
%
nmspc
.
database
)
arg
.
append
(
'
--without-demo %s
'
%
database
)
if
nmspc
.
max_cron_threads
:
arg
.
append
(
'
--max-cron-threads=%s
'
%
nmspc
.
max_cron_threads
)
if
nmspc
.
log_level
:
...
...
@@ -494,6 +508,14 @@
logging
.
debug
(
'
Starting postgresql container
'
)
docker_client
.
start
(
pg
.
get
(
'
Id
'
))
def
stop_postgresql
():
logging
.
info
(
'
Stopping postgresql
'
)
docker_client
.
stop
(
pg
.
get
(
'
Id
'
))
logging
.
info
(
'
Removing container postgresql
'
)
docker_client
.
remove_container
(
pg
.
get
(
'
Id
'
))
atexit
.
register
(
stop_postgresql
)
# give pg the time to start up
import
time
time
.
sleep
(
5
)
...
...
@@ -522,8 +544,8 @@
except
OperationalError
as
exception
:
if
nmspc
.
create_user
:
logging
.
info
(
'
Cannot connect to database with user %s
'
,
user
)
logging
.
info
(
exception
)
logging
.
debug
(
'
Cannot connect to database with user %s
'
,
user
)
logging
.
debug
(
exception
)
logging
.
info
(
'
Creating user %s
'
,
user
)
if
start_postgresql
:
connection
=
connect
(
...
...
@@ -544,5 +566,5 @@
connection
.
commit
()
connection
.
close
()
else
:
logging
.
warning
(
logging
.
fatal
(
'
Cannot connect to database with user %s
'
,
user
)
...
...
@@ -548,5 +570,39 @@
'
Cannot connect to database with user %s
'
,
user
)
logging
.
warning
(
exception
)
logging
.
fatal
(
exception
)
logging
.
info
(
"
You can add the --create-user argument to create it
"
)
return
16
# restore
if
restore_filename
:
restore_basename
=
os
.
path
.
basename
(
restore_filename
)
logging
.
info
(
"
Copying dump file in docker
"
)
call
([
'
docker
'
,
'
cp
'
,
restore_filename
,
'
%s:/tmp/%s
'
%
(
name
,
restore_basename
)])
logging
.
info
(
"
Creating database %s
"
,
database
)
call
([
'
docker
'
,
'
exec
'
,
name
,
'
createdb
'
,
'
-U
'
,
user
,
database
])
logging
.
info
(
"
Restoring database %s
"
,
database
)
restore
=
call
([
'
docker
'
,
'
exec
'
,
name
,
'
pg_restore
'
,
'
-U
'
,
user
,
'
-O
'
,
'
-d
'
,
database
,
'
/tmp/%s
'
%
restore_basename
])
if
not
restore
:
return
15
logging
.
info
(
"
Removing dump file in docker
"
)
call
([
'
docker
'
,
'
exec
'
,
name
,
'
/tmp/%s
'
%
restore_basename
])
if
not
start_postgresql
and
not
odoo_help
and
restore_filename
:
logging
.
info
(
"
Creating database %s
"
,
database
)
createdb
=
call
([
'
createdb
'
,
'
-U
'
,
user
,
database
])
if
not
createdb
:
return
17
logging
.
info
(
"
Restoring database %s
"
,
database
)
restore
=
call
([
'
pg_restore
'
,
'
-U
'
,
user
,
'
-O
'
,
'
-d
'
,
database
,
restore_filename
])
if
not
restore
:
return
15
# volume magic
for
module
in
modules
:
...
...
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