From e5955aa4248f6c9805d5896485488040fb6dd721 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 10 Mar 2016 12:19:16 +0100 Subject: [PATCH] Make sure you don't backup inside the filestore folder. The filestore is saved in the backup, so if you save the backup in the filestore, you'd end up with a huge backup that includes itself and the universe may collapse. --- auto_backup/models/db_backup.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/auto_backup/models/db_backup.py b/auto_backup/models/db_backup.py index 7131530b9..a312d1347 100644 --- a/auto_backup/models/db_backup.py +++ b/auto_backup/models/db_backup.py @@ -91,10 +91,11 @@ class DbBackup(models.Model): @api.model def _default_folder(self): - """Default to ``backups`` folder inside current database datadir.""" + """Default to ``backups`` folder inside current server datadir.""" return os.path.join( - tools.config.filestore(self.env.cr.dbname), - "backups") + tools.config["data_dir"], + "backups", + self.env.cr.dbname) @api.multi @api.depends("folder", "method", "sftp_host", "sftp_port", "sftp_user") @@ -107,6 +108,18 @@ class DbBackup(models.Model): rec.name = "sftp://%s@%s:%d%s" % ( rec.sftp_user, rec.sftp_host, rec.sftp_port, rec.folder) + @api.constrains("folder", "method") + @api.multi + def _check_folder(self): + """Do not use the filestore or you will backup your backups.""" + for s in self: + if (s.method == "local" and + s.folder.startswith( + tools.config.filestore(self.env.cr.dbname))): + raise exceptions.ValidationError( + _("Do not save backups on your filestore, or you will " + "backup your backups too!")) + @api.multi def action_sftp_test_connection(self): """Check if the SFTP settings are correct."""