From 4f094f7859cab6ee72792b96313c1c7d4407685d Mon Sep 17 00:00:00 2001 From: zoof Date: Sun, 22 Dec 2024 07:57:59 -0500 Subject: [PATCH] Change hour of daily tasks to run at 1am and only run full backups on weekends (#2424) * Change hour of daily tasks to run at 1am * Change to only do full backup on weekends --- management/backup.py | 17 +++++++++++------ setup/management.sh | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/management/backup.py b/management/backup.py index aae6c00b..238cb2ed 100755 --- a/management/backup.py +++ b/management/backup.py @@ -9,6 +9,7 @@ import os, os.path, re, datetime, sys import dateutil.parser, dateutil.relativedelta, dateutil.tz +from datetime import date import rtyaml from exclusiveprocess import Lock @@ -157,6 +158,8 @@ def should_force_full(config, env): # since the last full backup is greater than half the size # of that full backup. inc_size = 0 + # Check if day of week is a weekend day + weekend = date.today().weekday()>=5 for bak in backup_status(env)["backups"]: if not bak["full"]: # Scan through the incremental backups cumulating @@ -165,12 +168,14 @@ def should_force_full(config, env): else: # ...until we reach the most recent full backup. # Return if we should to a full backup, which is based - # on the size of the increments relative to the full - # backup, as well as the age of the full backup. - if inc_size > .5*bak["size"]: - return True - if dateutil.parser.parse(bak["date"]) + datetime.timedelta(days=config["min_age_in_days"]*10+1) < datetime.datetime.now(dateutil.tz.tzlocal()): - return True + # on whether it is a weekend day, the size of the + # increments relative to the full backup, as well as + # the age of the full backup. + if weekend: + if inc_size > .5*bak["size"]: + return True + if dateutil.parser.parse(bak["date"]) + datetime.timedelta(days=config["min_age_in_days"]*10+1) < datetime.datetime.now(dateutil.tz.tzlocal()): + return True return False else: # If we got here there are no (full) backups, so make one. diff --git a/setup/management.sh b/setup/management.sh index fb359cd3..d8032312 100755 --- a/setup/management.sh +++ b/setup/management.sh @@ -116,7 +116,7 @@ minute=$((RANDOM % 60)) # avoid overloading mailinabox.email cat > /etc/cron.d/mailinabox-nightly << EOF; # Mail-in-a-Box --- Do not edit / will be overwritten on update. # Run nightly tasks: backup, status checks. -$minute 3 * * * root (cd $PWD && management/daily_tasks.sh) +$minute 1 * * * root (cd $PWD && management/daily_tasks.sh) EOF # Start the management server.