add systemd units

This commit is contained in:
erebion 2023-10-10 18:28:50 +02:00
parent 18ec0569c8
commit aafcb1ad50
5 changed files with 18 additions and 4 deletions

View file

@ -77,20 +77,22 @@
- name: "Template systemd units for restic" - name: "Template systemd units for restic"
ansible.builtin.template: ansible.builtin.template:
src: "restic-wasabi.service.j2" src: "restic.service.j2"
dest: "/etc/systemd/system/restic@.service" dest: "/etc/systemd/system/restic@.service"
owner: root owner: root
group: root group: root
mode: 'u+rwx' mode: 'u+rwx'
register: unit
when: "ansible_os_family == 'Debian'" when: "ansible_os_family == 'Debian'"
- name: "Template systemd timers for restic" - name: "Template systemd timers for restic"
ansible.builtin.template: ansible.builtin.template:
src: "restic-wasabi.timer.j2" src: "restic.timer.j2"
dest: "/etc/systemd/system/restic@.timer" dest: "/etc/systemd/system/restic@.timer"
owner: root owner: root
group: root group: root
mode: 'u+rwx' mode: 'u+rwx'
register: unit
when: "ansible_os_family == 'Debian'" when: "ansible_os_family == 'Debian'"
- name: "Reload systemd units" - name: "Reload systemd units"

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source /opt/scripts/restic/restic.env source /opt/scripts/restic/restic.env
source /opt/scripts/restic/restic_db_passwords.env
#We will have to find out whether or not we need to initialize the repo. A non-zero exit code indicates that it has not yet been initialized. #We will have to find out whether or not we need to initialize the repo. A non-zero exit code indicates that it has not yet been initialized.
restic snapshots restic snapshots
if [ "$?" -eq "0" ] if [ "$?" -eq "0" ]
@ -12,9 +14,9 @@ fi
echo "Now dumping databases, this might take a while..." echo "Now dumping databases, this might take a while..."
set -x set -x
docker exec -t pretix_pg-sql.server2 pg_dumpall -c -U prtxdb > /opt/db_dumps/db-dump-pretix_db.sql docker exec -t pretix_pg-sql.server2 pg_dumpall -c -U prtxdb > /opt/db_dumps/db-dump-pretix_db.sql
#docker exec docker-partkeepr-database-1 sh -c "exec mariadb-dump --all-databases -u{{ unhb4_mariadb_containers['partkeepr'].user }} --password=$MARIADB_PASSWORD_PARTKEEPR" > /opt/db_dumps/db-dump-partkeepr_db.sql
source /opt/scripts/restic/restic_db_passwords.env source /opt/scripts/restic/restic_db_passwords.env
docker exec -t engel_sql.server2 sh -c "exec mysqldump --all-databases -u{{ unhb4_mariadb_containers['engelsystem'].user }} --password=$MARIADB_PASSWORD_ENGELSYSTEM" > /opt/db_dumps/db-dump-engelsystem_db.sql docker exec -t engel_sql.server2 sh -c "exec mysqldump --all-databases -uroot --password=$MARIADB_PASSWORD_ENGELSYSTEM" > /opt/db_dumps/db-dump-engelsystem_db.sql
set +x set +x
restic backup --verbose \ restic backup --verbose \

View file

@ -0,0 +1 @@
{{ restic_password_repo[inventory_hostname]["password"] }}

View file

@ -0,0 +1,6 @@
#!/bin/bash
source /opt/scripts/restic/restic.env
restic forget --prune --keep-within 1m --host={{ ansible_hostname }}
echo "done! :)"

View file

@ -0,0 +1,3 @@
#!/bin/bash
export RESTIC_REPOSITORY="{{ restic_repository_location }}{{ inventory_hostname }}"
export RESTIC_PASSWORD_FILE="/opt/scripts/restic/restic-password-repo"