Cleaned up

This commit is contained in:
Kevin Veen-Birkenbach 2021-06-19 11:45:12 +02:00
parent a3c2c02bf0
commit 2691d5d3fc
2 changed files with 6 additions and 30 deletions

View File

@ -1,44 +1,20 @@
# @see https://stackoverflow.com/questions/48929553/get-hard-disk-size-in-python # @see https://stackoverflow.com/questions/48929553/get-hard-disk-size-in-python
# import shutil
import psutil import psutil
import shutil
import os import os
import time
backup_disk_path = "/media/encrypteddrive-sda/" backup_disk_path = "/media/encrypteddrive-sda/"
backups_folder_path = os.path.join(backup_disk_path, "Backups/") backups_folder_path = os.path.join(backup_disk_path, "Backups/")
while psutil.disk_usage(backup_disk_path).percent > 50:
# Helper class for statistics
# class Disk_Statistics(object):
# def __init__(self):
# self.total = 0
# self.used = 0
# self.free = 0
# self.update_disc_usage()
#
# def update_disc_usage(self):
# old_used = self.used
# old_free = self.free
# self.total, self.used, self.free = shutil.disk_usage(backup_disk_path)
# if [(old_used == self.used) or (old_free == self.free)]:
# raise Exception("The values didn't change. \n Used: %d/%d \n Free: %d/%d" % (old_used,self.used, old_free,self.free))
#
# def get_used_space_percent(self):
# return (self.used/self.total)*100
#
#
# disk_statistics = Disk_Statistics()
while psutil.disk_usage(backup_disk_path).percent > 52:
print("%d %% of disk %s are used. Freeing space..." % (psutil.disk_usage(backup_disk_path).percent,backup_disk_path)) print("%d %% of disk %s are used. Freeing space..." % (psutil.disk_usage(backup_disk_path).percent,backup_disk_path))
for primary_directory in os.listdir(backups_folder_path): for primary_directory in os.listdir(backups_folder_path):
primary_directory = os.path.join(backups_folder_path, primary_directory) primary_directory = os.path.join(backups_folder_path, primary_directory)
for application_directory in os.listdir(primary_directory): for application_directory in os.listdir(primary_directory):
time.sleep(5)
application_directory = os.path.join(primary_directory, application_directory) application_directory = os.path.join(primary_directory, application_directory)
diffs_directory = os.path.join(application_directory, "diffs/") diffs_directory = os.path.join(application_directory, "diffs/")
diffs = os.listdir(diffs_directory) diffs = os.listdir(diffs_directory)
diffs.sort(reverse=False) diffs.sort(reverse=False)
delete_diff = diffs_directory + diffs[0] delete_diff = diffs_directory + diffs[0]
print("Deleting %s and free %s space..." % (delete_diff)) print("Deleting %s..." % (delete_diff))
#shutil.rmtree(delete_diff) shutil.rmtree(delete_diff)
#disk_statistics.update_disc_usage() print("Cleaning up finished: %d %% of disk %s are used." % (psutil.disk_usage(backup_disk_path).percent,backup_disk_path))

View File

@ -6,7 +6,7 @@
- system-security - system-security
- system-update - system-update
- native-journalctl - native-journalctl
- native-hostname #- native-hostname
- name: setup standard wireguard hosts - name: setup standard wireguard hosts
hosts: wireguard_hosts hosts: wireguard_hosts
become: true become: true