don't remove files during backu period
This commit is contained in:
parent
1fedd2b6c4
commit
364a381554
@ -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…
Reference in New Issue
Block a user