1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-11-22 02:17:26 +00:00

backup: automatically take a full backup when the sum of the increments get very large

This commit is contained in:
Joshua Tauberer 2014-08-11 11:38:32 +00:00
parent b6713d9a17
commit f66914d634

View File

@ -10,7 +10,7 @@
# 4) The backup directory is compressed into a single file using tar. # 4) The backup directory is compressed into a single file using tar.
# 5) That file is encrypted with a long password stored in backup/secret_key.txt. # 5) That file is encrypted with a long password stored in backup/secret_key.txt.
import sys, os, os.path, shutil import sys, os, os.path, shutil, glob
from utils import exclusive_process, load_environment, shell from utils import exclusive_process, load_environment, shell
@ -31,6 +31,15 @@ os.makedirs(backup_dir, exist_ok=True)
# will fail. # will fail.
if len(os.listdir(backup_duplicity_dir)) == 0: if len(os.listdir(backup_duplicity_dir)) == 0:
full_backup = True full_backup = True
else:
# When the size of incremental backups exceeds the size of existing
# full backups, take a new full backup. We want to avoid full backups
# because they are costly to synchronize off-site.
full_sz = sum(os.path.getsize(f) for f in glob.glob(backup_duplicity_dir + '/*-full.*'))
inc_sz = sum(os.path.getsize(f) for f in glob.glob(backup_duplicity_dir + '/*-inc.*'))
# (n.b. not counting size of new-signatures files because they are relatively small)
if inc_sz > full_sz * 1.5:
full_backup = True
# Stop services. # Stop services.
shell('check_call', ["/usr/sbin/service", "dovecot", "stop"]) shell('check_call', ["/usr/sbin/service", "dovecot", "stop"])