Browse Source

don't remove files during backu period

master
Romain H 7 months ago
committed by root
parent
commit
364a381554
  1. 23
      cleaning/remove_expired_files.py

23
cleaning/remove_expired_files.py

@ -2,10 +2,15 @@ import logging
import argparse
import os
import re
import datetime
import redis
BACKUP_START_TIME = datetime.time(1, 30, 0)
BACKUP_END_TIME = datetime.time(3, 30, 0)
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", action="store_true",
@ -57,6 +62,11 @@ def locate_file_with_id(args, file_id):
return None
def delete_files(args, file_ids):
for file_id in file_ids:
delete_file(args, file_id)
def delete_file(args, file_id):
logging.info('File with id %s will be deleted', file_id)
@ -76,8 +86,17 @@ def delete_file(args, file_id):
os.remove(file_path)
def is_in_backup_period():
now = datetime.datetime.now().time()
if BACKUP_START_TIME <= BACKUP_END_TIME:
return BACKUP_START_TIME <= now <= BACKUP_END_TIME
else:
return BACKUP_START_TIME <= now or now <= BACKUP_END_TIME
def main():
args = parse_args()
file_ids_to_delete = []
configure_logging(args)
redis_client, pubsub = create_redis_client(args)
@ -97,7 +116,9 @@ def main():
logging.debug('Event of type %s ignored', channel)
continue
delete_file(args, data)
file_ids_to_delete.append(data)
if not is_in_backup_period():
delete_files(args, file_ids_to_delete)
if __name__ == "__main__":

Loading…
Cancel
Save