[IMP] database manager: options on dump format
authorcod-odoo <cod@openerp.com>
Fri, 12 Sep 2014 10:02:16 +0000 (15:32 +0530)
committerRichard Mathot <rim@openerp.com>
Fri, 3 Oct 2014 13:30:46 +0000 (15:30 +0200)
addons/web/controllers/main.py
addons/web/static/src/xml/base.xml
openerp/service/db.py

index 0f4b3d3..1bdaa3e 100644 (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'),
index e489898..cf785a5 100644 (file)
                         <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; ">
index 048c160..b4bf124 100644 (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]