mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-22 20:51:07 +01:00
Finished backup-to-swappable draft
This commit is contained in:
parent
6a4dea3582
commit
7eed695623
@ -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_pull_primary_backups: "*-*-* 21:30:00"
|
||||||
on_calendar_renew_lets_encrypt_certificates: "*-*-* 12,00:30:00"
|
on_calendar_renew_lets_encrypt_certificates: "*-*-* 12,00:30:00"
|
||||||
on_calendar_deploy_mailu_certificates: "*-*-* 13,01: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
|
# Space Variables
|
||||||
size_percent_maximum_backup: 75
|
size_percent_maximum_backup: 75
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
hosts: wireguard_server
|
hosts: wireguard_server
|
||||||
become: true
|
become: true
|
||||||
roles:
|
roles:
|
||||||
- independent-application-wireguard
|
- independent_application-wireguard
|
||||||
|
|
||||||
- name: setup wireguard client behind firewall\nat
|
- name: setup wireguard client behind firewall\nat
|
||||||
hosts: wireguard_behind_firewall
|
hosts: wireguard_behind_firewall
|
||||||
@ -290,3 +290,10 @@
|
|||||||
become: true
|
become: true
|
||||||
roles:
|
roles:
|
||||||
- pc_application-docker
|
- pc_application-docker
|
||||||
|
|
||||||
|
|
||||||
|
- name: setup backup to swappable
|
||||||
|
hosts: backup_to_swappable
|
||||||
|
become: true
|
||||||
|
roles:
|
||||||
|
- independent_backup-to-swappable
|
@ -1,2 +1,2 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- independent-application-wireguard
|
- independent_application-wireguard
|
@ -1 +0,0 @@
|
|||||||
ATTRS{idVendor}=="152d", ATTRS{idProduct}=="2329", RUN+="/tmp/test.sh"
|
|
@ -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}}
|
|
@ -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
|
|
@ -1,7 +1,8 @@
|
|||||||
# independent-auto-usb-backup
|
# independent_auto-usb-backup
|
||||||
This tool role allows to make an automatic backup to an usb stick
|
This tool role allows to make an automatic backup to a swappable device.
|
||||||
|
|
||||||
## More information
|
## More information
|
||||||
- https://unix.stackexchange.com/questions/67464/how-to-get-uuid-for-a-usb-drive
|
- 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://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://askubuntu.com/questions/25071/how-to-run-a-script-when-a-specific-flash-drive-is-mounted
|
||||||
|
- https://wiki.archlinux.org/title/udev
|
@ -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
|
12
roles/independent_backup-to-swappable/handlers/main.yml
Normal file
12
roles/independent_backup-to-swappable/handlers/main.yml
Normal 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
|
@ -1,2 +1,3 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- independent_user-administrator
|
- independent_user-administrator
|
||||||
|
- independent_systemd-email
|
27
roles/independent_backup-to-swappable/tasks/main.yml
Normal file
27
roles/independent_backup-to-swappable/tasks/main.yml
Normal 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
|
@ -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"
|
@ -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}}
|
@ -1,8 +1,8 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=starts usb-auto-backup.service
|
Description=starts backup-to-swappable.service
|
||||||
|
|
||||||
[Timer]
|
[Timer]
|
||||||
OnCalendar={{on_calendar_usb_auto_backup}}
|
OnCalendar={{on_calendar_backup_to_swappable}}
|
||||||
RandomizedDelaySec={{randomized_delay_sec}}
|
RandomizedDelaySec={{randomized_delay_sec}}
|
||||||
Persistent=true
|
Persistent=true
|
||||||
|
|
3
roles/independent_backup-to-swappable/vars/main.yml
Normal file
3
roles/independent_backup-to-swappable/vars/main.yml
Normal 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"
|
@ -1,4 +1,4 @@
|
|||||||
# role independent-system-apt-update
|
# role independent_system-apt-update
|
||||||
This role updates the packages
|
This role updates the packages
|
||||||
|
|
||||||
# upgrade
|
# upgrade
|
@ -1,3 +1,3 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- { role: independent-system-pacman, when: ansible_distribution == 'Archlinux' }
|
- { role: independent_system-pacman, when: ansible_distribution == 'Archlinux' }
|
||||||
- { role: independent-system-apt-update, when: ansible_distribution == "Debian" }
|
- { role: independent_system-apt-update, when: ansible_distribution == "Debian" }
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- server_native-docker-reverse-proxy
|
- server_native-docker-reverse-proxy
|
||||||
- server_native-systemd-email
|
- independent_systemd-email
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- server_native-python-pip
|
- server_native-python-pip
|
||||||
- server_native-systemd-email
|
- independent_systemd-email
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- server_native-git
|
- server_native-git
|
||||||
- server_native-systemd-email
|
- independent_systemd-email
|
||||||
- server_native-backups-cleanup
|
- server_native-backups-cleanup
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- server_native-systemd-email
|
- independent_systemd-email
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- server_native-nginx
|
- server_native-nginx
|
||||||
- server_native-systemd-email
|
- independent_systemd-email
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- server_native-systemd-email
|
- independent_systemd-email
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- server_native-systemd-email
|
- independent_systemd-email
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- server_native-git
|
- server_native-git
|
||||||
- server_native-backups-provider
|
- server_native-backups-provider
|
||||||
- server_native-systemd-email
|
- independent_systemd-email
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- server_native-systemd-email
|
- independent_systemd-email
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
- server_native-systemd-email
|
- independent_systemd-email
|
||||||
|
Loading…
Reference in New Issue
Block a user