Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions database_tools/models/database.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- encoding: utf-8 -*-
import os
import shutil
import base64
from datetime import datetime
from datetime import date
from openerp import fields, models, api, _, modules
Expand Down Expand Up @@ -70,6 +69,13 @@ def _get_preserve_rules(self):
default='daily',
required=True,
)
backup_format = fields.Selection([
('zip', 'zip (With Filestore)'),
('pg_dump', 'pg_dump (Without Filestore)')],
'Backup Format',
default='pg_dump',
required=True,
)
backup_interval = fields.Integer(
string='Repeat Every',
default=1,
Expand Down Expand Up @@ -172,7 +178,12 @@ def cron_database_backup(self):
])

# make bakcup
databases.database_backup('automatic')
# we make a loop to commit after each backup
for database in databases:
database.database_backup(
'automatic',
backup_format=self.backup_format)
database._cr.commit()

# clean databases
databases = self.search([])
Expand Down Expand Up @@ -251,11 +262,11 @@ def database_backup_clean(self, bu_type=None):
def action_database_backup(self):
"""Action to be call from buttons"""
_logger.info('Action database backup called manually')
res = self.database_backup('manual')
res = self.database_backup('manual', backup_format=self.backup_format)
return res

@api.multi
def database_backup(self, bu_type):
def database_backup(self, bu_type, backup_format='zip'):
"""Returns a dictionary where:
* keys = database name
* value = dictionary with:
Expand Down Expand Up @@ -288,15 +299,20 @@ def database_backup(self, bu_type):
%s" % (database.backups_path, e)
_logger.warning(error)
else:
backup_name = '%s_%s_%s.zip' % (
database.name, bu_type, now.strftime('%Y%m%d_%H%M%S'))
backup_name = '%s_%s_%s.%s' % (
database.name,
bu_type,
now.strftime('%Y%m%d_%H%M%S'),
backup_format)
backup_path = os.path.join(
database.backups_path, backup_name)
backup = open(backup_path, 'wb')
# backup
try:
backup.write(base64.b64decode(
db_ws.exp_dump(database.name)))
db_ws.dump_db(
database.name,
backup,
backup_format=backup_format)
except:
error = 'Unable to dump Database.\
If you are working in an instance with\
Expand Down Expand Up @@ -345,7 +361,7 @@ def database_backup(self, bu_type):
try:
syncked_backup = os.path.join(
database.syncked_backup_path,
self.name + '.zip')
self.name + '.%s' % backup_format)
shutil.copy2(backup_path, syncked_backup)
except Exception, e:
error = "Could not copy into syncked folder.\
Expand Down
1 change: 1 addition & 0 deletions database_tools/views/database_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<field name="syncked_backup_path"/>
</group>
<group>
<field name="backup_format"/>
<label for="backup_rule_type"/>
<div>
<field name="backup_rule_type" class="oe_inline"/>
Expand Down