mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-10-31 02:10:05 +00:00 
			
		
		
		
	Cleaned up
This commit is contained in:
		| @@ -1,44 +1,20 @@ | ||||
| # @see https://stackoverflow.com/questions/48929553/get-hard-disk-size-in-python | ||||
| # import shutil | ||||
| import psutil | ||||
| import shutil | ||||
| import os | ||||
| import time | ||||
| backup_disk_path = "/media/encrypteddrive-sda/" | ||||
| backups_folder_path = os.path.join(backup_disk_path, "Backups/") | ||||
|  | ||||
|  | ||||
| # 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: | ||||
| while psutil.disk_usage(backup_disk_path).percent > 50: | ||||
|     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): | ||||
|         primary_directory = os.path.join(backups_folder_path, primary_directory) | ||||
|         for application_directory in os.listdir(primary_directory): | ||||
|             time.sleep(5) | ||||
|             application_directory = os.path.join(primary_directory, application_directory) | ||||
|             diffs_directory = os.path.join(application_directory, "diffs/") | ||||
|             diffs = os.listdir(diffs_directory) | ||||
|             diffs.sort(reverse=False) | ||||
|             delete_diff = diffs_directory + diffs[0] | ||||
|             print("Deleting %s and free %s space..." % (delete_diff)) | ||||
|             #shutil.rmtree(delete_diff) | ||||
|             #disk_statistics.update_disc_usage() | ||||
|             print("Deleting %s..." % (delete_diff)) | ||||
|             shutil.rmtree(delete_diff) | ||||
| print("Cleaning up finished: %d %% of disk %s are used." % (psutil.disk_usage(backup_disk_path).percent,backup_disk_path)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user