Browse Source
Merge pull request #1308 from hbrunn/8.0-auto_backup-improvements
[auto_backup] show chatter; custom tempdir
pull/1469/head
Pedro M. Baeza
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
24 additions and
1 deletions
-
auto_backup/models/db_backup.py
-
auto_backup/view/db_backup_view.xml
|
|
@ -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,6 +160,7 @@ class DbBackup(models.Model): |
|
|
|
shutil.copyfileobj(cached, destiny) |
|
|
|
# Generate new backup |
|
|
|
else: |
|
|
|
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): |
|
|
|
|
|
@ -14,6 +14,7 @@ |
|
|
|
<field name="folder"/> |
|
|
|
<field name="days_to_keep"/> |
|
|
|
<field name="method"/> |
|
|
|
<field name="tempdir" attrs="{'invisible': [('method', '!=', 'local')]}" groups="base.group_no_one" /> |
|
|
|
</group> |
|
|
|
<div attrs="{'invisible': [('method', '!=', 'sftp')]}"> |
|
|
|
<div class="bg-warning text-warning"> |
|
|
@ -44,6 +45,10 @@ |
|
|
|
<li>Set the scheduler to active and fill in how often you want backups generated.</li> |
|
|
|
</ol> |
|
|
|
</div> |
|
|
|
<div class="oe_chatter"> |
|
|
|
<field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/> |
|
|
|
<field name="message_ids" widget="mail_thread"/> |
|
|
|
</div> |
|
|
|
</form> |
|
|
|
</field> |
|
|
|
</record> |
|
|
|