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'),
<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; ">
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]