mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Finished backup-to-swappable draft
This commit is contained in:
8
roles/independent_backup-to-swappable/README.md
Normal file
8
roles/independent_backup-to-swappable/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# 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
|
@@ -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
|
3
roles/independent_backup-to-swappable/meta/main.yml
Normal file
3
roles/independent_backup-to-swappable/meta/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
dependencies:
|
||||
- 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}}
|
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=starts backup-to-swappable.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{on_calendar_backup_to_swappable}}
|
||||
RandomizedDelaySec={{randomized_delay_sec}}
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
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"
|
Reference in New Issue
Block a user