mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-22 12:41:05 +01:00
In between commit developing backups-cleanup
This commit is contained in:
parent
ea88aa0309
commit
a3c2c02bf0
44
roles/native-backups-cleanup/files/backups-cleanup.py
Normal file
44
roles/native-backups-cleanup/files/backups-cleanup.py
Normal file
@ -0,0 +1,44 @@
|
||||
# @see https://stackoverflow.com/questions/48929553/get-hard-disk-size-in-python
|
||||
# import shutil
|
||||
import psutil
|
||||
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:
|
||||
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()
|
2
roles/native-backups-cleanup/meta/main.yml
Normal file
2
roles/native-backups-cleanup/meta/main.yml
Normal file
@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- native-python-pip
|
3
roles/native-backups-cleanup/readme.md
Normal file
3
roles/native-backups-cleanup/readme.md
Normal file
@ -0,0 +1,3 @@
|
||||
# role native-backups-cleanup
|
||||
|
||||
Cleans up old backups
|
3
roles/native-backups-cleanup/tasks/main.yml
Normal file
3
roles/native-backups-cleanup/tasks/main.yml
Normal file
@ -0,0 +1,3 @@
|
||||
- name: install psutil
|
||||
pip:
|
||||
name: psutil
|
5
roles/native-python-pip/tasks/main.yml
Normal file
5
roles/native-python-pip/tasks/main.yml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: python pip install
|
||||
pacman:
|
||||
name: python-pip
|
||||
state: present
|
Loading…
Reference in New Issue
Block a user