mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-12-22 18:35:03 +01:00
Renamed to backup and cleanup roles
This commit is contained in:
parent
0d4eb75afe
commit
c70f0b2580
@ -30,11 +30,11 @@ This software allows to setup the docker following applications:
|
||||
#### Native Applications
|
||||
|
||||
This software shipts the following tools which are natively setup on the server:
|
||||
- [Backups Cleanup](./roles/backups-cleanup-timer/README.md) - Cleans up old backups
|
||||
- [Backups Cleanup](./roles/cleanup-backups-timer/README.md) - Cleans up old backups
|
||||
- [Btrfs Health Check](./roles/health-btrfs/README.md) - Checks the health of Btrfs file systems
|
||||
- [Docker Health Check](./roles/health-docker/) - Checks the health of docker containers
|
||||
- [Docker Reverse Proxy](./roles/docker-reverse-proxy/README.md) - Docker Reverse Proxy Solution
|
||||
- [Docker Volume Backup](./roles/backup-docker/) - Backup Solution for Docker Volumes
|
||||
- [Docker Volume Backup](./roles/backup-docker-to-local/) - Backup Solution for Docker Volumes
|
||||
- [Pull Primary Backups](./roles/backups-consumer/README.md) - Pulls the backups from another server and stores them
|
||||
- [Wireguard](./roles/wireguard/README.md) - Integrates the server in an wireguard vpn
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
- system-security
|
||||
- journalctl
|
||||
- health-disc-space
|
||||
- free-disc-space
|
||||
- cleanup-disc-space
|
||||
- health-btrfs
|
||||
|
||||
# Wireguard Rollen
|
||||
@ -321,4 +321,4 @@
|
||||
hosts: backup_to_usb
|
||||
become: true
|
||||
roles:
|
||||
- backup-to-usb
|
||||
- backup-data-to-usb
|
@ -1,4 +1,4 @@
|
||||
# backup-to-usb
|
||||
# backup-data-to-usb
|
||||
|
||||
This Ansible role automates the process of performing backups to a swappable USB device.
|
||||
|
@ -21,7 +21,7 @@ def main():
|
||||
machine_id = subprocess.run(["sha256sum", "/etc/machine-id"], capture_output=True, text=True).stdout.strip()[:64]
|
||||
print(f"machine id: {machine_id}")
|
||||
|
||||
versions_path = os.path.join(backup_to_usb_destination_path, f"{machine_id}/backup-to-usb/")
|
||||
versions_path = os.path.join(backup_to_usb_destination_path, f"{machine_id}/backup-data-to-usb/")
|
||||
print(f"versions path: {versions_path}")
|
||||
|
||||
if not os.path.isdir(versions_path):
|
6
roles/backup-data-to-usb/handlers/main.yml
Normal file
6
roles/backup-data-to-usb/handlers/main.yml
Normal file
@ -0,0 +1,6 @@
|
||||
- name: "reload backup-data-to-usb.service"
|
||||
systemd:
|
||||
name: backup-data-to-usb.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
3
roles/backup-data-to-usb/meta/main.yml
Normal file
3
roles/backup-data-to-usb/meta/main.yml
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
dependencies:
|
||||
- role: cleanup-backups-service
|
@ -1,6 +1,6 @@
|
||||
- name: Copy backup script to the scripts directory
|
||||
copy:
|
||||
src: backup-to-usb.python
|
||||
src: backup-data-to-usb.python
|
||||
dest: "{{ backup_to_usb_script_path }}"
|
||||
owner: root
|
||||
group: root
|
||||
@ -8,9 +8,9 @@
|
||||
|
||||
- name: Copy systemd service to systemd directory
|
||||
template:
|
||||
src: backup-to-usb.service.j2
|
||||
dest: /etc/systemd/system/backup-to-usb.service
|
||||
src: backup-data-to-usb.service.j2
|
||||
dest: /etc/systemd/system/backup-data-to-usb.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
notify: reload backup-to-usb.service
|
||||
notify: reload backup-data-to-usb.service
|
@ -1,4 +1,4 @@
|
||||
backup_to_usb_script_path: "/usr/local/sbin/backup-to-usb.python"
|
||||
backup_to_usb_script_path: "/usr/local/sbin/backup-data-to-usb.python"
|
||||
backup_to_usb_destination: "{{backup_to_usb_mount}}{{backup_to_usb_destination_subdirectory}}"
|
||||
backups_folder_path: "{{backup_to_usb_destination}}"
|
||||
systemctl_mount_service_name: "{{ backup_to_usb_mount | trim('/') | replace('/', '-') }}.mount"
|
@ -1,3 +0,0 @@
|
||||
# Docker Volume Backup Cleanup
|
||||
This script cleans up failed docker backups.
|
||||
It uses https://github.com/kevinveenbirkenbach/backup-docker-cleanup as base.
|
@ -1,5 +0,0 @@
|
||||
- name: "reload backup-docker-cleanup.service daemon"
|
||||
systemd:
|
||||
name: backup-docker-cleanup.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -1,18 +0,0 @@
|
||||
- name: pull backup-docker-cleanup.git
|
||||
git:
|
||||
repo: "https://github.com/kevinveenbirkenbach/backup-docker-cleanup.git"
|
||||
dest: "{{docker_volume_backup_cleanup_folder}}"
|
||||
update: yes
|
||||
register: git_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: Warn if repo is not reachable
|
||||
debug:
|
||||
msg: "Warning: Repository is not reachable."
|
||||
when: git_result.failed
|
||||
|
||||
- name: configure backup-docker-cleanup.service
|
||||
template:
|
||||
src: backup-docker-cleanup.service.j2
|
||||
dest: /etc/systemd/system/backup-docker-cleanup.service
|
||||
notify: reload backup-docker-cleanup.service daemon
|
12
roles/backup-docker-to-local/handlers/main.yml
Normal file
12
roles/backup-docker-to-local/handlers/main.yml
Normal file
@ -0,0 +1,12 @@
|
||||
- name: "reload backup-docker-to-local.service"
|
||||
systemd:
|
||||
name: backup-docker-to-local.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
|
||||
- name: "restart backup-docker-to-local.timer"
|
||||
systemd:
|
||||
name: backup-docker-to-local.timer
|
||||
state: started
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -2,4 +2,4 @@ dependencies:
|
||||
- git
|
||||
- backups-provider
|
||||
- systemd_notifier
|
||||
- backup-docker-cleanup
|
||||
- cleanup-failed-docker-backups
|
@ -5,9 +5,9 @@
|
||||
- python-pandas
|
||||
state: present
|
||||
|
||||
- name: pull backup-docker.git
|
||||
- name: pull backup-docker-to-local.git
|
||||
git:
|
||||
repo: "https://github.com/kevinveenbirkenbach/backup-docker.git"
|
||||
repo: "https://github.com/kevinveenbirkenbach/backup-docker-to-local.git"
|
||||
dest: "{{docker_volume_backup_folder}}"
|
||||
update: yes
|
||||
register: git_result
|
||||
@ -18,15 +18,15 @@
|
||||
msg: "Warning: Repository is not reachable."
|
||||
when: git_result.failed
|
||||
|
||||
- name: configure backup-docker.service
|
||||
- name: configure backup-docker-to-local.service
|
||||
template:
|
||||
src: backup-docker.service.j2
|
||||
dest: /etc/systemd/system/backup-docker.service
|
||||
notify: reload backup-docker.service
|
||||
src: backup-docker-to-local.service.j2
|
||||
dest: /etc/systemd/system/backup-docker-to-local.service
|
||||
notify: reload backup-docker-to-local.service
|
||||
|
||||
- name: configure backup-docker.timer.tpl
|
||||
template: src=backup-docker.timer.j2 dest=/etc/systemd/system/backup-docker.timer
|
||||
notify: restart backup-docker.timer
|
||||
- name: configure backup-docker-to-local.timer.tpl
|
||||
template: src=backup-docker-to-local.timer.j2 dest=/etc/systemd/system/backup-docker-to-local.timer
|
||||
notify: restart backup-docker-to-local.timer
|
||||
|
||||
- name: create {{docker_volume_backup_folder}}databases.csv
|
||||
copy:
|
@ -1,7 +1,7 @@
|
||||
[Unit]
|
||||
Description=docker volume backup
|
||||
OnFailure=systemd-notifier@%n.service backup-docker-cleanup.service
|
||||
OnFailure=systemd-notifier@%n.service cleanup-failed-docker-backups.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/python {{docker_volume_backup_folder}}backup-docker.py
|
||||
ExecStart=/usr/bin/python {{docker_volume_backup_folder}}backup-docker-to-local.py
|
@ -1 +1 @@
|
||||
docker_volume_backup_folder: "{{path_administrator_scripts}}backup-docker/"
|
||||
docker_volume_backup_folder: "{{path_administrator_scripts}}backup-docker-to-local/"
|
@ -1,12 +0,0 @@
|
||||
- name: "reload backup-docker.service"
|
||||
systemd:
|
||||
name: backup-docker.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
|
||||
- name: "restart backup-docker.timer"
|
||||
systemd:
|
||||
name: backup-docker.timer
|
||||
state: started
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -1,6 +0,0 @@
|
||||
- name: "reload backup-to-usb.service"
|
||||
systemd:
|
||||
name: backup-to-usb.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
dependencies:
|
||||
- role: backups-cleanup-service
|
@ -1,2 +0,0 @@
|
||||
dependencies:
|
||||
- backups-cleanup-service
|
@ -1,5 +1,5 @@
|
||||
dependencies:
|
||||
- git
|
||||
- systemd_notifier
|
||||
- backups-cleanup-timer
|
||||
- backup-docker-cleanup
|
||||
- cleanup-backups-timer
|
||||
- cleanup-failed-docker-backups
|
||||
|
@ -1,6 +1,6 @@
|
||||
[Unit]
|
||||
Description=pull remote backups
|
||||
OnFailure=systemd-notifier@%n.service backup-docker-cleanup.service
|
||||
OnFailure=systemd-notifier@%n.service cleanup-failed-docker-backups.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
|
@ -12,8 +12,8 @@ hashed_machine_id="$($get_hashed_machine_id | head -c 64)"
|
||||
get_backup_types="find /Backups/$hashed_machine_id/ -maxdepth 1 -type d -execdir basename {} ;";
|
||||
|
||||
|
||||
# @todo This configuration is not scalable yet. If other backup services then backup-docker are integrated, this logic needs to be optimized
|
||||
get_version_directories="ls -d /Backups/$hashed_machine_id/backup-docker/*"
|
||||
# @todo This configuration is not scalable yet. If other backup services then backup-docker-to-local are integrated, this logic needs to be optimized
|
||||
get_version_directories="ls -d /Backups/$hashed_machine_id/backup-docker-to-local/*"
|
||||
last_version_directory="$($get_version_directories | tail -1)"
|
||||
rsync_command="sudo rsync --server --sender -blogDtpre.iLsfxCIvu . $last_version_directory/"
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
dependencies:
|
||||
- backups-provider-user
|
||||
- backups-cleanup-timer
|
||||
- cleanup-backups-timer
|
||||
|
@ -1,4 +1,4 @@
|
||||
# role backups-cleanup-timer
|
||||
# role cleanup-backups-timer
|
||||
|
||||
Cleans up old backups
|
||||
|
@ -1,3 +1,3 @@
|
||||
# role backups-cleanup-timer
|
||||
# role cleanup-backups-timer
|
||||
|
||||
Timer for cleaning up old backups
|
2
roles/cleanup-backups-timer/meta/main.yml
Normal file
2
roles/cleanup-backups-timer/meta/main.yml
Normal file
@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- cleanup-backups-service
|
@ -1,4 +1,4 @@
|
||||
# free-disc-space
|
||||
# cleanup-disc-space
|
||||
Frees disc space
|
||||
## More information
|
||||
- https://askubuntu.com/questions/380238/how-to-clean-tmp
|
12
roles/cleanup-disc-space/handlers/main.yml
Normal file
12
roles/cleanup-disc-space/handlers/main.yml
Normal file
@ -0,0 +1,12 @@
|
||||
- name: "reload cleanup-disc-space.service"
|
||||
systemd:
|
||||
name: cleanup-disc-space.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
- name: "restart cleanup-disc-space.timer"
|
||||
systemd:
|
||||
name: cleanup-disc-space.timer
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
22
roles/cleanup-disc-space/tasks/main.yml
Normal file
22
roles/cleanup-disc-space/tasks/main.yml
Normal file
@ -0,0 +1,22 @@
|
||||
- name: "create {{free_disc_space_folder}}"
|
||||
file:
|
||||
path: "{{free_disc_space_folder}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create cleanup-disc-space.sh
|
||||
template:
|
||||
src: cleanup-disc-space.sh.j2
|
||||
dest: "{{free_disc_space_folder}}cleanup-disc-space.sh"
|
||||
|
||||
- name: create cleanup-disc-space.service
|
||||
template:
|
||||
src: cleanup-disc-space.service.j2
|
||||
dest: /etc/systemd/system/cleanup-disc-space.service
|
||||
notify: reload cleanup-disc-space.service
|
||||
|
||||
- name: create cleanup-disc-space.timer
|
||||
template:
|
||||
src: cleanup-disc-space.timer.j2
|
||||
dest: /etc/systemd/system/cleanup-disc-space.timer
|
||||
notify: restart cleanup-disc-space.timer
|
@ -4,4 +4,4 @@ OnFailure=systemd-notifier@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash {{free_disc_space_folder}}free-disc-space.sh {{size_percent_free_disc_space}}
|
||||
ExecStart=/bin/bash {{free_disc_space_folder}}cleanup-disc-space.sh {{size_percent_free_disc_space}}
|
@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description=starts free-disc-space.service
|
||||
Description=starts cleanup-disc-space.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{on_calendar_free_disc_space}}
|
1
roles/cleanup-disc-space/vars/main.yml
Normal file
1
roles/cleanup-disc-space/vars/main.yml
Normal file
@ -0,0 +1 @@
|
||||
free_disc_space_folder: "{{path_administrator_scripts}}cleanup-disc-space/"
|
3
roles/cleanup-failed-docker-backups/README.md
Normal file
3
roles/cleanup-failed-docker-backups/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Docker Volume Backup Cleanup
|
||||
This script cleans up failed docker backups.
|
||||
It uses https://github.com/kevinveenbirkenbach/cleanup-failed-docker-backups as base.
|
5
roles/cleanup-failed-docker-backups/handlers/main.yml
Normal file
5
roles/cleanup-failed-docker-backups/handlers/main.yml
Normal file
@ -0,0 +1,5 @@
|
||||
- name: "reload cleanup-failed-docker-backups.service daemon"
|
||||
systemd:
|
||||
name: cleanup-failed-docker-backups.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
18
roles/cleanup-failed-docker-backups/tasks/main.yml
Normal file
18
roles/cleanup-failed-docker-backups/tasks/main.yml
Normal file
@ -0,0 +1,18 @@
|
||||
- name: pull cleanup-failed-docker-backups.git
|
||||
git:
|
||||
repo: "https://github.com/kevinveenbirkenbach/cleanup-failed-docker-backups.git"
|
||||
dest: "{{docker_volume_backup_cleanup_folder}}"
|
||||
update: yes
|
||||
register: git_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: Warn if repo is not reachable
|
||||
debug:
|
||||
msg: "Warning: Repository is not reachable."
|
||||
when: git_result.failed
|
||||
|
||||
- name: configure cleanup-failed-docker-backups.service
|
||||
template:
|
||||
src: cleanup-failed-docker-backups.service.j2
|
||||
dest: /etc/systemd/system/cleanup-failed-docker-backups.service
|
||||
notify: reload cleanup-failed-docker-backups.service daemon
|
@ -1 +1 @@
|
||||
docker_volume_backup_cleanup_folder: "{{path_administrator_scripts}}backup-docker-cleanup/"
|
||||
docker_volume_backup_cleanup_folder: "{{path_administrator_scripts}}cleanup-failed-docker-backups/"
|
@ -81,7 +81,7 @@ docker-compose build &&
|
||||
docker-compose -p akaunting up -d --force-recreate
|
||||
|
||||
# recover all volumes
|
||||
cd {{path_administrator_scripts}}backup-docker &&
|
||||
cd {{path_administrator_scripts}}backup-docker-to-local &&
|
||||
bash docker-volume-recover.sh akaunting_akaunting-modules ${machine_id:0:64} "$backup_version" &&
|
||||
bash docker-volume-recover.sh akaunting_akaunting-data ${machine_id:0:64} "$backup_version" &&
|
||||
bash docker-volume-recover.sh akaunting_akaunting-db ${machine_id:0:64} "$backup_version" akaunting-db "$akaunting_db_password" akaunting
|
||||
|
@ -30,7 +30,7 @@ waiting_time=600
|
||||
blocker_running=True
|
||||
while blocker_running:
|
||||
try:
|
||||
bash("systemctl is-active --quiet backup-docker.service")
|
||||
bash("systemctl is-active --quiet backup-docker-to-local.service")
|
||||
bash("systemctl is-active --quiet update-docker.service")
|
||||
print("backup is running.")
|
||||
print("trying again in " + str(waiting_time) + " seconds.")
|
||||
|
@ -59,8 +59,8 @@ and disable the not functioning apps.
|
||||
```bash
|
||||
cd {{path_docker_compose_files}}nextcloud &&
|
||||
docker-compose down &&
|
||||
docker-compose exec -i database mysql -u nextcloud -pPASSWORT nextcloud < "/Backups/$(sha256sum /etc/machine-id | head -c 64)/backup-docker/latest/nextcloud_database/sql/backup.sql" &&
|
||||
cd {{path_administrator_scripts}}backup-docker &&
|
||||
docker-compose exec -i database mysql -u nextcloud -pPASSWORT nextcloud < "/Backups/$(sha256sum /etc/machine-id | head -c 64)/backup-docker-to-local/latest/nextcloud_database/sql/backup.sql" &&
|
||||
cd {{path_administrator_scripts}}backup-docker-to-local &&
|
||||
bash ./docker-volume-recover.sh "nextcloud_data" "$(sha256sum /etc/machine-id | head -c 64)"
|
||||
```
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
dependencies:
|
||||
- backup-docker
|
||||
- backup-docker-to-local
|
||||
- user-administrator
|
||||
- health-docker
|
||||
- docker-compose-restart-unhealthy
|
||||
|
@ -1,12 +0,0 @@
|
||||
- name: "reload free-disc-space.service"
|
||||
systemd:
|
||||
name: free-disc-space.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
- name: "restart free-disc-space.timer"
|
||||
systemd:
|
||||
name: free-disc-space.timer
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -1,22 +0,0 @@
|
||||
- name: "create {{free_disc_space_folder}}"
|
||||
file:
|
||||
path: "{{free_disc_space_folder}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create free-disc-space.sh
|
||||
template:
|
||||
src: free-disc-space.sh.j2
|
||||
dest: "{{free_disc_space_folder}}free-disc-space.sh"
|
||||
|
||||
- name: create free-disc-space.service
|
||||
template:
|
||||
src: free-disc-space.service.j2
|
||||
dest: /etc/systemd/system/free-disc-space.service
|
||||
notify: reload free-disc-space.service
|
||||
|
||||
- name: create free-disc-space.timer
|
||||
template:
|
||||
src: free-disc-space.timer.j2
|
||||
dest: /etc/systemd/system/free-disc-space.timer
|
||||
notify: restart free-disc-space.timer
|
@ -1 +0,0 @@
|
||||
free_disc_space_folder: "{{path_administrator_scripts}}free-disc-space/"
|
Loading…
Reference in New Issue
Block a user