--- - name: Back up hosts: all gather_facts: false become: true vars_files: - vars/secrets.yaml tasks: # ---------------------------------------------------------------------------------------------------- - name: Get current date shell: date +%Y-%m-%d run_once: true register: current_date # ---------------------------------------------------------------------------------------------------- - name: Stop Privatebin command: docker stop privatebin when: inventory_hostname == 'oracle1' - name: Set permissions of privatebin directory file: path: "/home/{{ ansible_user }}/Docker/privatebin/data" state: directory owner: 1000 group: 1000 mode: 0755 recurse: yes when: inventory_hostname == 'oracle1' - name: Compress privatebin directory shell: "zip -r --password {{ backup_zip_password }} privatebin_{{ current_date.stdout }}.zip data" args: chdir: "/home/{{ ansible_user }}/Docker/privatebin/" when: inventory_hostname == 'oracle1' - name: Set permissions of privatebin directory file: path: "/home/{{ ansible_user }}/Docker/privatebin/data" state: directory owner: 65534 group: 82 mode: 0700 recurse: yes when: inventory_hostname == 'oracle1' - name: Start Privatebin command: docker start privatebin when: inventory_hostname == 'oracle1' - name: Copy privatebin.zip copy: src: "{{ oracle1_nfs_docker_dir_on_control_host }}/privatebin/privatebin_{{ current_date.stdout }}.zip" dest: "{{ backup_path_on_control_host }}/" owner: 0 group: 0 mode: 0644 when: inventory_hostname == 'oracle1' delegate_to: "{{ control_host }}" - name: Remove privatebin.zip on remote server file: path: "/home/{{ ansible_user }}/Docker/privatebin/privatebin_{{ current_date.stdout }}.zip" state: absent when: inventory_hostname == 'oracle1' # To Restore: # cd ./Docker/privatebin # sudo unzip privatebin_2023-11-11.zip # sudo chown -R 65534:82 /home/{{ ansible_user }}/Docker/privatebin/data # ---------------------------------------------------------------------------------------------------- - name: Backup Etherpaddb command: "docker exec -e PGPASSWORD={{ etherpad_db_pass }} etherpaddb sh -c 'PGPASSWORD={{ etherpad_db_pass }} pg_dump -Ft -U etherpad etherpad > /backups/etherpaddb_{{ current_date.stdout }}.tar'" when: inventory_hostname == 'oracle3' - name: Prune Etherpaddb on remote server command: find /home/{{ ansible_user }}/Docker/etherpad/backups -type f -mtime +2 -delete when: inventory_hostname == 'oracle3' - name: Copy Etherpaddb backups copy: src: "{{ oracle3_nfs_docker_dir_on_control_host }}/etherpad/backups/" dest: "{{ backup_path_on_control_host }}/" owner: 0 group: 0 mode: 0644 when: inventory_hostname == 'oracle3' delegate_to: "{{ control_host }}" # ---------------------------------------------------------------------------------------------------- - name: Stop gitea command: docker stop gitea when: inventory_hostname == 'oracle3' - name: Stop gitea-db command: docker stop gitea-db when: inventory_hostname == 'oracle3' - name: Compress gitea directory archive: path: "/home/{{ ansible_user }}/Docker/gitea/data/" dest: "/home/{{ ansible_user }}/Docker/gitea/gitea_{{ current_date.stdout }}.tar" format: tar when: inventory_hostname == 'oracle3' - name: Copy gitea.tar copy: src: "{{ oracle3_nfs_docker_dir_on_control_host }}/gitea/gitea_{{ current_date.stdout }}.tar" dest: "{{ backup_path_on_control_host }}/gitea_{{ current_date.stdout }}.tar" owner: 0 group: 0 mode: 0644 when: inventory_hostname == 'oracle3' delegate_to: "{{ control_host }}" - name: Remove gitea.tar on remote server file: path: "/home/{{ ansible_user }}/Docker/gitea/gitea_{{ current_date.stdout }}.tar" state: absent when: inventory_hostname == 'oracle3' - name: Start gitea command: docker start gitea when: inventory_hostname == 'oracle3' - name: Start gitea-db command: docker start gitea-db when: inventory_hostname == 'oracle3' # ---------------------------------------------------------------------------------------------------- # - name: Stop ntfy # command: docker stop ntfy # when: inventory_hostname == 'oracle3' # - name: Compress ntfy directory # archive: # path: "/home/{{ ansible_user }}/Docker/ntfy/" # dest: "/home/{{ ansible_user }}/Docker/ntfy.tar" # format: tar # become: true # when: inventory_hostname == 'oracle3' # - name: Copy ntfy.tar # copy: # src: "{{ oracle3_nfs_docker_dir_on_control_host }}/ntfy.tar" # dest: "{{ backup_path_on_control_host }}/ntfy.tar" # owner: 1000 # group: 1000 # mode: 0755 # when: inventory_hostname == 'oracle3' # delegate_to: "{{ control_host }}" # - name: Remove ntfy.tar # file: # path: "/home/{{ ansible_user }}/Docker/ntfy.tar" # state: absent # when: inventory_hostname == 'oracle3' # - name: Start ntfy # command: docker start ntfy # when: inventory_hostname == 'oracle3' # ---------------------------------------------------------------------------------------------------- - name: Remove old weekly files from send command: find /home/{{ ansible_user }}/Docker/send/uploads/ -name 7-\* -mmin +10130 -exec rm {} \; when: inventory_hostname == 'oracle1' - name: Remove old daily files from send command: find /home/{{ ansible_user }}/Docker/send/uploads/ -name 1-\* -mmin +1500 -exec rm {} \; when: inventory_hostname == 'oracle1' # - name: Compress send directory # archive: # path: "/home/{{ ansible_user }}/Docker/send" # dest: "/home/{{ ansible_user }}/Docker/send.tar" # format: tar # delegate_to: oracle1 # tags: never # when: inventory_hostname == 'oracle1' # - name: Copy send.tar # copy: # src: "{{ oracle1_nfs_docker_dir_on_control_host }}/send.tar" # dest: "{{ backup_path_on_control_host }}/send.tar" # owner: 1000 # group: 1000 # mode: 0755 # tags: never # when: inventory_hostname == 'oracle1' # delegate_to: "{{ control_host }}" # - name: Remove send.tar # file: # path: "/home/{{ ansible_user }}/Docker/send.tar" # state: absent # tags: never # when: inventory_hostname == 'oracle1' # ---------------------------------------------------------------------------------------------------- - name: Prune outdated backups command: find "{{ backup_path_on_control_host }}/" -type f -mtime +90 -delete run_once: true delegate_to: "{{ control_host }}"