

# Create zip file (for both file and folder options)īackup_file_name = f'backup-.zip' While len(oldest_to_newest_backup_by_name) >= MAX_BACKUP_AMOUNT: # >= because we will have another soonīackup_to_delete = oldest_to_newest_backup_by_name.pop(0) Oldest_to_newest_backup_by_name = list(sorted(existing_backups, key=lambda f: f.name))

# Enforce max backups and delete oldest if there will be too many after the new backup If x.is_file() and x.suffix = '.zip' and x.name.startswith('backup-') # Get the amount of past backup zips in the backup directory already # Validate the backup directory exists and create if requiredīackup_directory_path.mkdir(parents=True, exist_ok=True) Object_to_backup_path = Path(OBJECT_TO_BACKUP)īackup_directory_path = Path(BACKUP_DIRECTORY)Īssert object_to_backup_path.exists() # Validate the object we are about to backup exists before we continue MAX_BACKUP_AMOUNT = 5 # The maximum amount of backups to have in BACKUP_DIRECTORY OBJECT_TO_BACKUP = '/home/etre/test/' # The file or directory to backupīACKUP_DIRECTORY = '/home/etre/test-backup/' # The location to store the backups in I use this script to make zipped backup of important folder but because after 5th backup files is moves to Recycle Bin and show to everyone I am looking for setpassword opinion to protect deleted zips or even better delete old zips but permanently (not move in Recycle Bin).
