Skip to content

Commit

Permalink
Merge pull request #898 from cortex-lab/purge_backups
Browse files Browse the repository at this point in the history
remove backups that are older than one year
  • Loading branch information
mayofaulkner authored Jan 9, 2025
2 parents 9453dbe + ee4f524 commit dea0b8b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/deployment_examples/99_purge_duplicate_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CMD = (f"ssh -i /home/ubuntu/.ssh/sdsc_alyx.pem -q -p 62022 -t {HOST} "
f"'ls -s1 {FLAT_IRON_DIR}/*.sql.gz'")
KEEP_DAYS = 2
KEEP_YEARS = 1

parser = argparse.ArgumentParser(
description='Removes local backup files if they exist on the flatiron remote server')
Expand All @@ -36,14 +37,15 @@
files_aws = {v.replace(str(LOCAL_DIR) + '/', '').replace('/', '_'): int(k) for k, v in files_aws}

# Find all backups locally that are also on flatiron, with (almost) the same file size, older than
# 7 days, and not starting the first of a month.
# 7 days, and not starting the first of a month and are not from the last year.
for fn in sorted(files_aws):
if fn in sorted(files_flatiron):
ds = r.search(fn).group(0)
d = isoparse(ds)
tol = 15 # size diff in blocks <2021-08-23 increased from 12>
if ((datetime.now() - d).days >= KEEP_DAYS and
abs(files_aws[fn] - files_flatiron[fn]) <= tol and d.day != 1):
abs(files_aws[fn] - files_flatiron[fn]) <= tol
and (d.day != 1 or (datetime.now().year - d.year) > KEEP_YEARS)):
sql_file = Path(LOCAL_DIR).joinpath('%s/alyx_full.sql.gz' % ds)
json_file = Path(LOCAL_DIR).joinpath('%s/alyx_full.json.gz' % ds)
if sql_file.exists():
Expand Down

0 comments on commit dea0b8b

Please sign in to comment.