diff --git a/Makefile b/Makefile index dda70b6..f592908 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,6 @@ qnap-services: snunmu: ansible-playbook playbooks/setup-homelab.yml --limit snunmu - homelab: ansible-playbook playbooks/setup-homelab.yml @@ -50,6 +49,9 @@ backup-snunmu: deps backup-qnap: deps ansible-playbook playbooks/backup-docker-volumes.yml --limit qnap +backup-qnap-dirs: deps + ansible-playbook playbooks/backup-directories.yml --limit qnap + restore: deps ansible-playbook playbooks/] -e volume_name="$(volume_name)" --limit "$(host)" diff --git a/host_vars/qnap.yml b/host_vars/qnap.yml index 53cf6af..50e7182 100644 --- a/host_vars/qnap.yml +++ b/host_vars/qnap.yml @@ -10,6 +10,12 @@ mounts: - /mnt/data/device2 options: allow_other,use_ino +# these directories will be backed up to s3. +backup_directories: + - path: /mnt/mergerfs/photoprism/originals + s3_name: photos + - path: /mnt/mergerfs/documents/media/documents/originals + s3_name: paperless-docs cron_hour: "5" docker_backup_host_backup_directory: "/mnt/mergerfs/backups" diff --git a/host_vars/snunmu.yml b/host_vars/snunmu.yml index 7a42042..e096d37 100644 --- a/host_vars/snunmu.yml +++ b/host_vars/snunmu.yml @@ -14,6 +14,7 @@ services: ansible_pull_path: /usr/local/bin/ansible-pull +backup_directories: [] cron_hour: "4" # docker options diff --git a/playbooks/backup-directories.yml b/playbooks/backup-directories.yml new file mode 100644 index 0000000..71048e5 --- /dev/null +++ b/playbooks/backup-directories.yml @@ -0,0 +1,16 @@ +--- +- name: Backup Directories. + hosts: servers + become: true + + pre_tasks: + - name: Include vault variables. + ansible.builtin.include_vars: '../{{ vault_file }}' + tags: [always] + + tasks: + - ansible.builtin.include_role: + name: backup_directory + with_items: "{{ backup_directories }}" + loop_control: + loop_var: backup diff --git a/playbooks/setup-homelab.yml b/playbooks/setup-homelab.yml index ad5f66c..fc938c5 100644 --- a/playbooks/setup-homelab.yml +++ b/playbooks/setup-homelab.yml @@ -10,7 +10,6 @@ roles: - role: setup_users - - name: Configure mergerfs pools. hosts: mergerfs become: true @@ -25,62 +24,6 @@ - role: geerlingguy.samba tags: [samba] -- name: Configure samba shares. - hosts: samba - become: true - roles: - - role: setup_samba - tags: [samba] - -- name: Samba Clients - hosts: sambaclients - become: true - tags: [samba] - pre_tasks: - - name: Include vault variables. - ansible.builtin.include_vars: '../{{ vault_file }}' - tags: [always] - tasks: - - name: Install CIFS and other required packages for mounting with apt - ansible.builtin.apt: - name: "{{ item }}" - state: present - with_items: - - smbclient - - cifs-utils - - - name: Check mountpoint exists. - ansible.builtin.file: - path: "/mnt/mergerfs" - state: directory - mode: '0777' - owner: root - group: root - - - name: Check mountpoint exists. - ansible.builtin.file: - path: "/mnt/ssd0/downloads" - state: directory - mode: '0777' - owner: root - group: root - - - name: Mount shares. - mount: - state: "mounted" - fstype: "cifs" - path: /mnt/mergerfs - src: '//192.168.178.42/mergerfs' - opts: 'username=cianhatton,password={{ cianhatton_password }},dir_mode=0777,file_mode=0777,umask=0000' - - - name: Mount shares. - mount: - state: "mounted" - fstype: "cifs" - path: /mnt/ssd0/downloads - src: '//192.168.178.42/downloads' - opts: 'username=cianhatton,password={{ cianhatton_password }},dir_mode=0777,file_mode=0777,umask=0000' - - name: Install Docker on Docker hosts. hosts: docker become: true @@ -89,7 +32,7 @@ - geerlingguy.docker -- name: Install Portainer on Portainer host. +- name: Install Portainer on Portainer hosts. hosts: portainer become: true pre_tasks: diff --git a/roles/backup_directory/meta/main.yml b/roles/backup_directory/meta/main.yml new file mode 100644 index 0000000..c95a36e --- /dev/null +++ b/roles/backup_directory/meta/main.yml @@ -0,0 +1,13 @@ +--- +galaxy_info: + author: Cian Hatton + namespace: chatton + description: Backup directories + license: MIT + min_ansible_version: "2.1" + galaxy_tags: [] + platforms: + - name: Debian + versions: + - all +dependencies: [] diff --git a/roles/backup_directory/tasks/main.yml b/roles/backup_directory/tasks/main.yml new file mode 100644 index 0000000..38167f6 --- /dev/null +++ b/roles/backup_directory/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- name: Determine backup timestamp. + ansible.builtin.set_fact: backup_time="{{ ansible_date_time.iso8601 }}" + +- name: Compress Directory + community.general.archive: + path: "{{ backup.path }}" + dest: /tmp/backup.tar.gz + +- name: Upload backups to S3 + amazon.aws.aws_s3: + s3_url: "{{ docker_backup_aws_s3_url }}" + bucket: "{{ docker_backup_aws_s3_bucket }}" + object: "{{ backup.s3_name }}-{{ backup_time }}.tar.gz" + src: /tmp/backup.tar.gz + aws_access_key: "{{ docker_backup_aws_s3_aws_access_key }}" + aws_secret_key: "{{ docker_backup_aws_s3_aws_secret_key }}" + region: "{{ docker_backup_aws_s3_region }}" + mode: put + permission: "{{ docker_backup_aws_s3_permissions }}"