Renamed backup roles

This commit is contained in:
2025-07-14 19:04:30 +02:00
parent 4acf2137e8
commit f02ca50f88
42 changed files with 66 additions and 66 deletions

View File

@@ -0,0 +1,30 @@
# Docker 🐳
## Description
This Ansible role installs and manages Docker on Arch Linux systems. It ensures that Docker and Docker Compose are available, configured, and ready to run containerized workloads, while enabling seamless integration with system roles and administrative tasks.
Checkout the [administration reference](./Administration.md) for volume cleanup, container resets, and Docker network recovery.
## Overview
Tailored for Arch Linux, this role handles the installation of Docker and Docker Compose using the systems package manager. It sets up a secure environment for managing Compose instances and ensures the Docker service is properly enabled and restarted. In addition, the role flags its state so that dependent roles can execute conditionally.
## Purpose
The purpose of this role is to automate the provisioning of Docker environments in a consistent and maintainable way. It reduces manual setup steps and enables clean integration with other infrastructure roles, making it ideal for production or homelab deployments.
## Features
- **Installs Docker & Docker Compose:** Uses `pacman` to install necessary packages.
- **Service Management:** Automatically enables and restarts the Docker service.
- **Secure Directory Creation:** Creates a secure location for Docker Compose instance files.
- **Run-once Setup Logic:** Ensures idempotent execution by controlling task flow with internal flags.
- **System Role Integration:** Sets internal state (`docker_enabled`) for use by other CyMaIS roles.
## Credits 📝
Developed and maintained by **Kevin Veen-Birkenbach**.
Learn more at [www.veen.world](https://www.veen.world)
Part of the [CyMaIS Project](https://github.com/kevinveenbirkenbach/cymais)
License: [CyMaIS NonCommercial License (CNCL)](https://s.veen.world/cncl)

View File

@@ -0,0 +1,63 @@
#!/usr/bin/env python3
import sys
import subprocess
import shutil
import os
import glob
import datetime
def main():
source_path = sys.argv[1]
print(f"source path: {source_path}")
backup_to_usb_destination_path = sys.argv[2]
print(f"backup to usb destination path: {backup_to_usb_destination_path}")
if not os.path.isdir(backup_to_usb_destination_path):
print(f"Directory {backup_to_usb_destination_path} does not exist")
sys.exit(1)
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}/svc-bkp-loc-2-usb/")
print(f"versions path: {versions_path}")
if not os.path.isdir(versions_path):
print(f"Creating {versions_path}...")
os.makedirs(versions_path, exist_ok=True)
previous_version_path = max(glob.glob(f"{versions_path}*"), key=os.path.getmtime, default=None)
print(f"previous versions path: {previous_version_path}")
current_version_path = os.path.join(versions_path, datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
print(f"current versions path: {current_version_path}")
print("Creating backup destination folder...")
os.makedirs(current_version_path, exist_ok=True)
print("Starting synchronization...")
try:
rsync_command = [
"rsync", "-abP", "--delete", "--delete-excluded"
]
if previous_version_path is not None:
rsync_command.append("--link-dest=" + previous_version_path)
rsync_command.extend([source_path, current_version_path])
rsync_output = subprocess.check_output(rsync_command, stderr=subprocess.STDOUT, text=True)
print(rsync_output)
print("Synchronization finished")
sys.exit(0)
except subprocess.CalledProcessError as e:
print(e.output)
if "rsync warning: some files vanished before they could be transferred" in e.output:
print("Synchronization finished with rsync warning")
sys.exit(0)
else:
print("Synchronization failed")
sys.exit(1)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,5 @@
- name: "reload svc-bkp-loc-2-usb.cymais.service"
systemd:
name: svc-bkp-loc-2-usb.cymais.service
state: reloaded
daemon_reload: yes

View File

@@ -0,0 +1,27 @@
---
galaxy_info:
author: "Kevin Veen-Birkenbach"
description: "Automated backups to a swappable USB device."
license: "CyMaIS NonCommercial License (CNCL)"
license_url: "https://s.veen.world/cncl"
company: |
Kevin Veen-Birkenbach
Consulting & Coaching Solutions
https://www.veen.world
min_ansible_version: "2.9"
platforms:
- name: Archlinux
versions:
- rolling
galaxy_tags:
- backup
- usb
- systemd
- automation
- archlinux
repository: https://s.veen.world/cymais
issue_tracker_url: https://s.veen.world/cymaisissues
documentation: https://s.veen.world/cymais
dependencies:
- sys-cln-bkps-service
- sys-lock

View File

@@ -0,0 +1,16 @@
- name: Copy backup script to the scripts directory
copy:
src: svc-bkp-loc-2-usb.python
dest: "{{ backup_to_usb_script_path }}"
owner: root
group: root
mode: '0755'
- name: Copy systemd service to systemd directory
template:
src: svc-bkp-loc-2-usb.service.j2
dest: /etc/systemd/system/svc-bkp-loc-2-usb.cymais.service
owner: root
group: root
mode: '0644'
notify: reload svc-bkp-loc-2-usb.cymais.service

View File

@@ -0,0 +1,12 @@
[Unit]
Description=Backup to USB when mounted to {{ backup_to_usb_mount }}
Wants={{systemctl_mount_service_name}}
OnFailure=sys-alm-compose.cymais@%n.service
[Service]
Type=oneshot
ExecStart=/bin/python {{ backup_to_usb_script_path }} {{backup_to_usb_source}} {{backup_to_usb_destination}}
ExecStartPost=/bin/systemctl start sys-cln-backups.cymais.service
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,6 @@
backup_to_usb_script_path: /usr/local/sbin/svc-bkp-loc-2-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'
application_id: svc-bkp-loc-2-usb