mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-23 05:01:04 +01:00
optimized backups-cleanup
This commit is contained in:
parent
85ffc968df
commit
6a5db94ade
@ -0,0 +1,7 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=delete old backups
|
||||||
|
OnFailure=systemd-email@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/bin/python /usr/local/bin/backups-cleanup.py
|
9
roles/native-backups-cleanup/files/backups-cleanup.timer
Normal file
9
roles/native-backups-cleanup/files/backups-cleanup.timer
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=starts backups-cleanup.service
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=19:00
|
||||||
|
RandomizedDelaySec=1h
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
12
roles/native-backups-cleanup/handlers/main.yml
Normal file
12
roles/native-backups-cleanup/handlers/main.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
- name: "restart backups-cleanup.service"
|
||||||
|
systemd:
|
||||||
|
name: backups-cleanup.service
|
||||||
|
state: restarted
|
||||||
|
enabled: yes
|
||||||
|
daemon_reload: yes
|
||||||
|
- name: "restart backups-cleanup.timer"
|
||||||
|
systemd:
|
||||||
|
name: backups-cleanup.timer
|
||||||
|
state: restarted
|
||||||
|
enabled: yes
|
||||||
|
daemon_reload: yes
|
@ -1,2 +1,3 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- native-python-pip
|
- native-python-pip
|
||||||
|
- native-systemd-email
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
- name: install psutil
|
- name: install psutil
|
||||||
pip:
|
pip:
|
||||||
name: psutil
|
name: psutil
|
||||||
|
|
||||||
|
- name: create backups-cleanup.py
|
||||||
|
template: src=backups-cleanup.py.j2 dest=/usr/local/bin/backups-cleanup.py
|
||||||
|
|
||||||
|
- name: create backups-cleanup.service
|
||||||
|
copy:
|
||||||
|
src: backups-cleanup.service
|
||||||
|
dest: "/etc/systemd/system/backups-cleanup.service"
|
||||||
|
notify: restart backups-cleanup.service
|
||||||
|
|
||||||
|
- name: create backups-cleanup.timer
|
||||||
|
copy:
|
||||||
|
src: backups-cleanup.timer
|
||||||
|
dest: "/etc/systemd/system/backups-cleanup.timer"
|
||||||
|
notify: restart backups-cleanup.timer
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
import psutil
|
import psutil
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
backup_disk_path = "/media/encrypteddrive-sda/"
|
backup_disk_path = "{{backup_disk_path}}"
|
||||||
backups_folder_path = os.path.join(backup_disk_path, "Backups/")
|
backups_folder_path = os.path.join(backup_disk_path, "Backups/")
|
||||||
deleted = True
|
deleted = True
|
||||||
while psutil.disk_usage(backup_disk_path).percent > 50 and deleted:
|
while psutil.disk_usage(backup_disk_path).percent > int({{backup_space_percent}}) and deleted:
|
||||||
deleted = False
|
deleted = False
|
||||||
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):
|
5
site.yml
5
site.yml
@ -39,6 +39,11 @@
|
|||||||
become: true
|
become: true
|
||||||
roles:
|
roles:
|
||||||
- role: native-pull-primary-backups
|
- role: native-pull-primary-backups
|
||||||
|
- name: setup backups cleanup
|
||||||
|
hosts: backups_cleanup
|
||||||
|
become: true
|
||||||
|
roles:
|
||||||
|
- role: native-backups-cleanup
|
||||||
- name: setup homepages
|
- name: setup homepages
|
||||||
hosts: homepage_hosts
|
hosts: homepage_hosts
|
||||||
become: true
|
become: true
|
||||||
|
Loading…
Reference in New Issue
Block a user