From b34e455c82944be998eebb391a8e8aedc494de11 Mon Sep 17 00:00:00 2001 From: Christian Steinle Date: Thu, 15 May 2025 08:16:44 +0200 Subject: [PATCH] Update backup to nas and remove mattermost variables. --- nas.yaml | 124 ++++++++++++++++--------------------------- vars/mattermost.yaml | 22 -------- 2 files changed, 46 insertions(+), 100 deletions(-) delete mode 100644 vars/mattermost.yaml diff --git a/nas.yaml b/nas.yaml index adaa9e7..137a1e6 100644 --- a/nas.yaml +++ b/nas.yaml @@ -1,91 +1,59 @@ --- -# This playbook creates a backup of odroid and writes it to the nas. -- name: Backup odroid to nas. +# This playbook creates a backup of minisforum and writes it to odroid. +- name: Backup minisforum to odroid hosts: all + vars: + directories: + - docker + - media + - nextcloud + - sftp + - strato-production gather_facts: false tasks: - - name: Backup odroid - block: - - include_vars: vars/mattermost.yaml + - name: Wakeup odroid + community.general.wakeonlan: + mac: '00:1E:06:45:4C:45' + broadcast: 192.168.178.255 + delegate_to: localhost - - name: Wakeup the nas - community.general.wakeonlan: - mac: '54:04:a6:f1:9b:80' + - name: Wait odroid is responding + ansible.builtin.wait_for_connection: - - name: Wait nas is responding - wait_for_connection: - timeout: 120 - delay: 5 - sleep: 5 + - name: Gathering facts + ansible.builtin.setup: - - name: Gathering facts - setup: + - name: Mount minisforum storage + ansible.posix.mount: + src: 192.168.178.46:/ + path: /media/nas + state: mounted + fstype: nfs + become: true - - name: Check mount point exists - file: - path: /media/nas - state: directory + - name: Check backup directory exists + ansible.builtin.file: + path: /media/backup/minisforum + state: directory + mode: '0755' - - name: Mount nas volume - ansible.posix.mount: - src: 192.168.178.55:/export/data - path: /media/nas - state: mounted - fstype: nfs - become: yes + - name: Check file path for storage directories exists + ansible.builtin.file: + path: /media/backup/minisforum/{{ item }} + state: directory + mode: '0755' + loop: "{{ directories }}" - - name: Backup docker data to nas - shell: rsync -a --delete /media/backup/docker/ /media/nas/Odroid/docker - become: yes + - name: Backup minisforum directories + ansible.builtin.shell: rsync -a --delete /media/nas/{{ item }}/ /media/backup/minisforum/{{ item }}/ + loop: "{{ directories }}" - - name: Backup hetzner data to nas - shell: rsync -a --delete /media/backup/hetzner/ /media/nas/Odroid/hetzner - become: yes + - name: Unmount the volume + ansible.posix.mount: + path: /media/nas + state: unmounted + become: true - - name: Backup nextcloud data to nas - shell: rsync -a --delete /media/backup/nextcloud/ /media/nas/Odroid/nextcloud - become: yes - - - name: Backup media to nas - shell: rsync -a --delete /media/backup/media/ /media/nas/Odroid/media - become: yes - - - name: Umount nas volume - ansible.posix.mount: - path: /media/nas - state: unmounted - become: yes - - - name: Inform Mattermost about success - uri: - url: "{{ mattermost_url }}" - method: POST - body_format: json - body: - channel_id: "{{ channel_id }}" - message: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}: Playbook ran successful ({{ ansible_play_name }})" - headers: - Content-Type: application/json - Authorization: "Bearer {{ semaphore_token }}" - status_code: [200, 201] - - rescue: - - name: Umount nas volume - ansible.posix.mount: - path: /media/nas - state: unmounted - become: yes - - - name: Inform Mattermost about error - uri: - url: "{{ mattermost_url }}" - method: POST - body_format: json - body: - channel_id: "{{ channel_id }}" - message: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}: Playbook ran with error ({{ ansible_play_name }})" - headers: - Content-Type: application/json - Authorization: "Bearer {{ error_token }}" - status_code: [200, 201] + - name: Shutdown nas + ansible.builtin.shell: sudo shutdown -h 1 diff --git a/vars/mattermost.yaml b/vars/mattermost.yaml deleted file mode 100644 index d569c70..0000000 --- a/vars/mattermost.yaml +++ /dev/null @@ -1,22 +0,0 @@ -mattermost_url: https://cs-mm.ddnss.de/api/v4/posts -channel_id: !vault | - $ANSIBLE_VAULT;1.1;AES256 - 39653833613461333664643534613839663837373932333262346338653366363734643361383931 - 3632326236393064616566653336333830356135376530320a353135616533303632663432383663 - 62643264356135363064353666353736666330393035643139333833306463646365356563313862 - 3662363932666164650a393834376463366537323066393262663730383337636636633439653437 - 32313635326439373234313565633035306166323935363336326231316533386538 -semaphore_token: !vault | - $ANSIBLE_VAULT;1.1;AES256 - 63313433633333393362306534636131666536313365353439343764623132616537663838353238 - 3536376438343865376539336235366138303762663732370a303532306533613838383037633138 - 39383139656231373237333434653932663361393063313962383831356134653866313539373235 - 3564373132346262640a316463333735393534346436313838336439373839643535646262366339 - 34663863383264393638316434333764643263623536386262643431613630333539 -error_token: !vault | - $ANSIBLE_VAULT;1.1;AES256 - 37376437373233373664323163346661663336656636316365343732383130626339363032393035 - 3831633664373835663933333533303031626135303139380a396439393762316430333035373233 - 64623137643433353537306436333665313864373634353032346366613037336437343239643661 - 3665646265326435650a373561663637366266613933376636313830313937306362653864376439 - 66313761646362323634343139316235353639643830366130653238306232353631