[IMP] database manager: options on dump format

This commit is contained in:
cod-odoo
2014-10-03 15:30:46 +02:00
committed by Richard Mathot
parent 0b42e36da3
commit 4e272542ea
3 changed files with 24 additions and 11 deletions
+7 -4
View File
@@ -748,14 +748,17 @@ class Database(http.Controller):
return {'error': _('Could not drop database !'), 'title': _('Drop Database')}
@http.route('/web/database/backup', type='http', auth="none")
def backup(self, backup_db, backup_pwd, token):
def backup(self, backup_db, backup_pwd, token, **kwargs):
try:
format = kwargs.get('format')
ext = "zip" if format == 'zip' else "dump"
db_dump = base64.b64decode(
request.session.proxy("db").dump(backup_pwd, backup_db))
filename = "%(db)s_%(timestamp)s.dump" % {
request.session.proxy("db").dump(backup_pwd, backup_db, format))
filename = "%(db)s_%(timestamp)s.%(ext)s" % {
'db': backup_db,
'timestamp': datetime.datetime.utcnow().strftime(
"%Y-%m-%d_%H-%M-%SZ")
"%Y-%m-%d_%H-%M-%SZ"),
'ext': ext
}
return request.make_response(db_dump,
[('Content-Type', 'application/octet-stream; charset=binary'),
+9
View File
@@ -228,6 +228,15 @@
<td><label for="backup_pwd">Master Password:</label></td>
<td><input type="password" name="backup_pwd" class="required" /></td>
</tr>
<tr>
<td><label>Format:</label></td>
<td>
<input type="radio" name="format" checked="checked" value="zip" />
<label for="format" title="Archive containing a dump of your database and your whole filestore">Zip</label>
<input type="radio" name="format" value="binary" />
<label for="format" title="Binary dump of your database (PostgreSQL dump)">Binary</label>
</td>
</tr>
</table>
</form>
<form id="db_restore" name="restore_db_form" style="display: none; ">
+8 -7
View File
@@ -171,21 +171,22 @@ def _set_pg_password_in_environment(func):
del os.environ['PGPASSWORD']
return wrapper
def exp_dump(db_name):
def exp_dump(db_name, format):
with tempfile.TemporaryFile() as t:
dump_db(db_name, t)
dump_db(db_name, t, format)
t.seek(0)
return t.read().encode('base64')
@_set_pg_password_in_environment
def dump_db(db, stream):
def dump_db(db, stream, format):
"""Dump database `db` into file-like object `stream`"""
with openerp.tools.osutil.tempdir() as dump_dir:
registry = openerp.modules.registry.RegistryManager.get(db)
with registry.cursor() as cr:
filestore = registry['ir.attachment']._filestore(cr, SUPERUSER_ID)
if os.path.exists(filestore):
shutil.copytree(filestore, os.path.join(dump_dir, 'filestore'))
if format == 'zip':
with registry.cursor() as cr:
filestore = registry['ir.attachment']._filestore(cr, SUPERUSER_ID)
if os.path.exists(filestore):
shutil.copytree(filestore, os.path.join(dump_dir, 'filestore'))
dump_file = os.path.join(dump_dir, 'dump.sql')
cmd = ['pg_dump', '--format=p', '--no-owner', '--file=' + dump_file]