|
|
@ -6,6 +6,7 @@ |
|
|
|
|
|
|
|
import os |
|
|
|
import shutil |
|
|
|
import tempfile |
|
|
|
import traceback |
|
|
|
from contextlib import contextmanager |
|
|
|
from datetime import datetime, timedelta |
|
|
@ -54,6 +55,11 @@ class DbBackup(models.Model): |
|
|
|
default="local", |
|
|
|
help="Choose the storage method for this backup.", |
|
|
|
) |
|
|
|
tempdir = fields.Char( |
|
|
|
string="Temporary directory", |
|
|
|
help="Backups first go to a temporary directory. In case you need to " |
|
|
|
"put them somewhere else, fill in the directory here", |
|
|
|
) |
|
|
|
sftp_host = fields.Char( |
|
|
|
string='SFTP Server', |
|
|
|
oldname="sftpip", |
|
|
@ -154,7 +160,8 @@ class DbBackup(models.Model): |
|
|
|
shutil.copyfileobj(cached, destiny) |
|
|
|
# Generate new backup |
|
|
|
else: |
|
|
|
db.dump_db(self.env.cr.dbname, destiny) |
|
|
|
with rec.custom_tempdir(): |
|
|
|
db.dump_db(self.env.cr.dbname, destiny) |
|
|
|
backup = backup or destiny.name |
|
|
|
successful |= rec |
|
|
|
|
|
|
@ -191,6 +198,17 @@ class DbBackup(models.Model): |
|
|
|
"""Run all scheduled backups.""" |
|
|
|
return self.search([]).action_backup() |
|
|
|
|
|
|
|
@api.multi |
|
|
|
@contextmanager |
|
|
|
def custom_tempdir(self): |
|
|
|
old_tempdir = tempfile.tempdir |
|
|
|
if self.tempdir: |
|
|
|
tempfile.tempdir = self.tempdir |
|
|
|
try: |
|
|
|
yield |
|
|
|
finally: |
|
|
|
tempfile.tempdir = old_tempdir |
|
|
|
|
|
|
|
@api.multi |
|
|
|
@contextmanager |
|
|
|
def backup_log(self): |
|
|
|