Finished backup-to-swappable draft

This commit is contained in:
Kevin Veen-Birkenbach 2023-04-26 22:12:40 +02:00
parent f78a759d7a
commit 8327323a45
40 changed files with 115 additions and 37 deletions

View File

@ -16,7 +16,7 @@ on_calendar_docker_compose_restart_unhealthy: "*-*-* 09,10,11,12,13,14,15,16,17,
on_calendar_pull_primary_backups: "*-*-* 21:30:00"
on_calendar_renew_lets_encrypt_certificates: "*-*-* 12,00:30:00"
on_calendar_deploy_mailu_certificates: "*-*-* 13,01:30:00"
on_calendar_usb_auto_backup: "*-*-* 09,12,15,18,21,24,03,06:30:00"
on_calendar_backup_to_swappable: "*-*-* 09,12,15,18,21,24,03,06:30:00"
# Space Variables
size_percent_maximum_backup: 75

View File

@ -20,7 +20,7 @@
hosts: wireguard_server
become: true
roles:
- independent-application-wireguard
- independent_application-wireguard
- name: setup wireguard client behind firewall\nat
hosts: wireguard_behind_firewall
@ -290,3 +290,10 @@
become: true
roles:
- pc_application-docker
- name: setup backup to swappable
hosts: backup_to_swappable
become: true
roles:
- independent_backup-to-swappable

View File

@ -1,2 +1,2 @@
dependencies:
- independent-application-wireguard
- independent_application-wireguard

View File

@ -1 +0,0 @@
ATTRS{idVendor}=="152d", ATTRS{idProduct}=="2329", RUN+="/tmp/test.sh"

View File

@ -1,7 +0,0 @@
[Unit]
Description=delete old backups
OnFailure=systemd-email@%n.service
[Service]
Type=oneshot
ExecStart=/usr/bin/python {{docker_backups_cleanup}}backups-cleanup.py --backups-folder-path {{backups_folder_path}} --maximum-backup-size-percent {{size_percent_maximum_backup}}

View File

@ -1,8 +0,0 @@
#! /bin/sh
env >>/tmp/test.log
file "/sys${DEVPATH}" >>/tmp/test.log
if [ "${ACTION}" = add -a -d "/sys${DEVPATH}" ]; then
echo "add ${DEVPATH}" >>/tmp/test.log
fi

View File

@ -1,7 +1,8 @@
# independent-auto-usb-backup
This tool role allows to make an automatic backup to an usb stick
# independent_auto-usb-backup
This tool role allows to make an automatic backup to a swappable device.
## More information
- https://unix.stackexchange.com/questions/67464/how-to-get-uuid-for-a-usb-drive
- https://unix.stackexchange.com/questions/65891/how-to-execute-a-shellscript-when-i-plug-in-a-usb-device
- https://askubuntu.com/questions/25071/how-to-run-a-script-when-a-specific-flash-drive-is-mounted
- https://wiki.archlinux.org/title/udev

View File

@ -0,0 +1,35 @@
#! /bin/sh
backup_to_swappable_destination_path="$1" &&
echo "backup to swappable destination path: $backup_to_swappable_destination_path" &&
source_path="$2" &&
echo "source path: $source_path" || exit 1
if [ ! -d "$backup_to_swappable_destination_path" ]; then
echo "Directory $backup_to_swappable_destination_path does not exist" &&
exit 1
fi
machine_id="$(sha256sum /etc/machine-id | head -c 64 )" &&
echo "machine id: $machine_id" &&
versions_path="$backup_to_swappable_destination_path$machine_id/backup-to-swappable/" &&
echo "versions path: $versions_path" || exit 1
if [ ! -d "$versions_path" ]; then
echo "Creating $versions_path..." &&
mkdir -vp $versions_path || exit 1
fi
previous_version_path="$(ls -d $versions_path* | tail -1)" &&
echo "previous versions path: $previous_version_path" &&
current_version_path="$versions_path$(date '+%Y%m%d%H%M%S')" &&
echo "current versions path: $current_version_path" &&
echo "creating backup destination folder..." &&
mkdir -vp "$current_version_path" &&
echo "Starting syncronization..."
rsync -abP --delete --delete-excluded --link-dest="$previous_version_path" "$source_path" "$current_version_path" &&
echo "Syncronization finished." || exit 1

View File

@ -0,0 +1,12 @@
- name: "reload backup-to-swappable.service"
systemd:
name: backup-to-swappable.service
state: reloaded
enabled: yes
daemon_reload: yes
- name: "restart backup-to-swappable.timer"
systemd:
name: backup-to-swappable.timer
state: restarted
enabled: yes
daemon_reload: yes

View File

@ -1,2 +1,3 @@
dependencies:
- independent_user-administrator
- independent_systemd-email

View File

@ -0,0 +1,27 @@
- name: "create {{backup_to_swappable_folder}}"
file:
path: "{{backup_to_swappable_folder}}"
state: directory
mode: 0755
- name: create backup-to-swappable.rule
template:
src: backup-to-swappable.rule.j2
dest: "/etc/udev/rules.d/backup-to-swappable.rule"
- name: create backup-to-swappable.sh
copy:
src: backup-to-swappable.sh
dest: "{{backup_to_swappable_folder}}backup-to-swappable.sh"
- name: create backup-to-swappable.service
template:
src: backup-to-swappable.service.j2
dest: /etc/systemd/system/backup-to-swappable.service
notify: reload backup-to-swappable.service
- name: create backup-to-swappable.timer
template:
src: backup-to-swappable.timer.j2
dest: /etc/systemd/system/backup-to-swappable.timer
notify: restart backup-to-swappable.timer

View File

@ -0,0 +1 @@
ACTION=="add", KERNEL=="sd[a-z]", ENV{ID_SERIAL_SHORT}=="{{backup_to_swappable_serial_short}}", RUN+="systemctl start backup-to-swappable.service"

View File

@ -0,0 +1,7 @@
[Unit]
Description=backing up data
OnFailure=systemd-email@%n.service
[Service]
Type=oneshot
ExecStart=/usr/bin/bash {{backup_to_swappable_script_path}}

View File

@ -1,8 +1,8 @@
[Unit]
Description=starts usb-auto-backup.service
Description=starts backup-to-swappable.service
[Timer]
OnCalendar={{on_calendar_usb_auto_backup}}
OnCalendar={{on_calendar_backup_to_swappable}}
RandomizedDelaySec={{randomized_delay_sec}}
Persistent=true

View File

@ -0,0 +1,3 @@
backup_to_swappable_folder: "{{path_administrator_scripts}}backup-to-swappable/"
backup_to_swappable_destination_path: "{{backup_to_swappable_destination_path}}backup-to-swappable/"
backup_to_swappable_script_path: "{{backup_to_swappable_folder}}backup-to-swappable.sh"

View File

@ -1,4 +1,4 @@
# role independent-system-apt-update
# role independent_system-apt-update
This role updates the packages
# upgrade

View File

@ -1,3 +1,3 @@
dependencies:
- { role: independent-system-pacman, when: ansible_distribution == 'Archlinux' }
- { role: independent-system-apt-update, when: ansible_distribution == "Debian" }
- { role: independent_system-pacman, when: ansible_distribution == 'Archlinux' }
- { role: independent_system-apt-update, when: ansible_distribution == "Debian" }

View File

@ -1,3 +1,3 @@
dependencies:
- server_native-docker-reverse-proxy
- server_native-systemd-email
- independent_systemd-email

View File

@ -1,3 +1,3 @@
dependencies:
- server_native-python-pip
- server_native-systemd-email
- independent_systemd-email

View File

@ -1,4 +1,4 @@
dependencies:
- server_native-git
- server_native-systemd-email
- independent_systemd-email
- server_native-backups-cleanup

View File

@ -1,2 +1,2 @@
dependencies:
- server_native-systemd-email
- independent_systemd-email

View File

@ -1,3 +1,3 @@
dependencies:
- server_native-nginx
- server_native-systemd-email
- independent_systemd-email

View File

@ -1,2 +1,2 @@
dependencies:
- server_native-systemd-email
- independent_systemd-email

View File

@ -1,2 +1,2 @@
dependencies:
- server_native-systemd-email
- independent_systemd-email

View File

@ -1,4 +1,4 @@
dependencies:
- server_native-git
- server_native-backups-provider
- server_native-systemd-email
- independent_systemd-email

View File

@ -1,2 +1,2 @@
dependencies:
- server_native-systemd-email
- independent_systemd-email

View File

@ -1,2 +1,2 @@
dependencies:
- server_native-systemd-email
- independent_systemd-email