@@ -83,6 +83,15 @@ class DbBackup(models.Model):
8383 "read permissions for that file." ,
8484 )
8585
86+ backup_format = fields .Selection (
87+ [
88+ ("zip" , "zip (includes filestore)" ),
89+ ("dump" , "pg_dump custom format (without filestore)" )
90+ ],
91+ default = 'zip' ,
92+ help = "Choose the format for this backup."
93+ )
94+
8695 @api .model
8796 def _default_folder (self ):
8897 """Default to ``backups`` folder inside current server datadir."""
@@ -131,11 +140,11 @@ def action_sftp_test_connection(self):
131140 def action_backup (self ):
132141 """Run selected backups."""
133142 backup = None
134- filename = self .filename (datetime .now ())
135143 successful = self .browse ()
136144
137145 # Start with local storage
138146 for rec in self .filtered (lambda r : r .method == "local" ):
147+ filename = self .filename (datetime .now (), ext = rec .backup_format )
139148 with rec .backup_log ():
140149 # Directory must exist
141150 try :
@@ -151,21 +160,28 @@ def action_backup(self):
151160 shutil .copyfileobj (cached , destiny )
152161 # Generate new backup
153162 else :
154- db .dump_db (self .env .cr .dbname , destiny )
163+ db .dump_db (
164+ self .env .cr .dbname ,
165+ destiny ,
166+ backup_format = rec .backup_format
167+ )
155168 backup = backup or destiny .name
156169 successful |= rec
157170
158171 # Ensure a local backup exists if we are going to write it remotely
159172 sftp = self .filtered (lambda r : r .method == "sftp" )
160173 if sftp :
161- if backup :
162- cached = open (backup )
163- else :
164- cached = db .dump_db (self .env .cr .dbname , None )
174+ for rec in sftp :
175+ filename = self .filename (datetime .now (), ext = rec .backup_format )
176+ with rec .backup_log ():
165177
166- with cached :
167- for rec in sftp :
168- with rec .backup_log ():
178+ cached = db .dump_db (
179+ self .env .cr .dbname ,
180+ None ,
181+ backup_format = rec .backup_format
182+ )
183+
184+ with cached :
169185 with rec .sftp_connection () as remote :
170186 # Directory must exist
171187 try :
@@ -255,13 +271,16 @@ def cleanup_log(self):
255271 self .name )
256272
257273 @staticmethod
258- def filename (when ):
274+ def filename (when , ext = 'zip' ):
259275 """Generate a file name for a backup.
260276
261277 :param datetime.datetime when:
262278 Use this datetime instead of :meth:`datetime.datetime.now`.
279+ :param str ext: Extension of the file. Default: dump.zip
263280 """
264- return "{:%Y_%m_%d_%H_%M_%S}.dump.zip" .format (when )
281+ return "{:%Y_%m_%d_%H_%M_%S}.{ext}" .format (
282+ when , ext = 'dump.zip' if ext == 'zip' else ext
283+ )
265284
266285 @api .multi
267286 def sftp_connection (self ):
0 commit comments