diff --git a/env.yml b/env.yml index c43ae96..32cb752 100644 --- a/env.yml +++ b/env.yml @@ -50,6 +50,7 @@ projects: projects_to_backup: + - etebase - synapse - vaultwarden diff --git a/roles/etebase/tasks/backup.yml b/roles/etebase/tasks/backup.yml new file mode 100644 index 0000000..b65072f --- /dev/null +++ b/roles/etebase/tasks/backup.yml @@ -0,0 +1,30 @@ +- name: + become: true + block: + - name: Backup SQLite database + command: + cmd: | + sqlite3 + "{{ volumes['etebase_datadir'] }}/db.sqlite3" + ".backup {{ volumes['etebase_datadir'] }}/db-backup.sqlite3" + + - name: Create borg backup + command: + cmd: | + borg create + --compression=lzma + "{{ borg_repodir }}::{{ role_name }}-{now:%Y-%m-%d_%H-%M-%S}" + {{ volumes['etebase_datadir'] }}/db-backup.sqlite3 + {{ volumes['etebase_datadir'] }}/media + environment: + BORG_PASSCOMMAND: "cat {{ borg_passphrase_file }}" + + - name: Prune borg repository + command: + cmd: | + borg prune + --glob-archives='{{ role_name }}-*' + {{ borg_prune_options }} + {{ borg_repodir }} + environment: + BORG_PASSCOMMAND: "cat {{ borg_passphrase_file }}" diff --git a/roles/etebase/tasks/main.yml b/roles/etebase/tasks/main.yml index 2199a6b..ed95f38 100644 --- a/roles/etebase/tasks/main.yml +++ b/roles/etebase/tasks/main.yml @@ -1,34 +1,9 @@ -- name: "Create {{ etebase_project_dir }} project directory" - file: - path: "{{ etebase_project_dir }}" - state: directory +- name: Include backup tasks + include_tasks: + file: backup.yml + when: run_backup | default(false) | bool -- name: Template docker-compose.yaml to project directory - template: - src: docker-compose.yaml - dest: "{{ etebase_project_dir }}/docker-compose.yaml" - owner: "{{ ansible_env['USER'] }}" - group: "{{ ansible_env['USER'] }}" - mode: '640' - -- name: Template etebase-server.ini to project directory - template: - src: etebase-server.ini - dest: "{{ etebase_project_dir }}/etebase-server.ini" - owner: "{{ ansible_env['USER'] }}" - group: "{{ ansible_env['USER'] }}" - mode: '644' - -- name: "Create directory {{ volumes['etebase_datadir'] }} with correct permissions" - file: - path: "{{ volumes['etebase_datadir'] }}" - state: directory - owner: "{{ users['etebase'] + uid_shift }}" - group: "{{ users['etebase'] + uid_shift }}" - mode: '770' - become: true - -- name: Pull/Create/Restart project services - community.docker.docker_compose: - project_src: "{{ etebase_project_dir }}" - pull: "{{ docker_pull_images | bool }}" +- name: Include update tasks + include_tasks: + file: update.yml + when: run_update | default(false) | bool diff --git a/roles/etebase/tasks/update.yml b/roles/etebase/tasks/update.yml new file mode 100644 index 0000000..2199a6b --- /dev/null +++ b/roles/etebase/tasks/update.yml @@ -0,0 +1,34 @@ +- name: "Create {{ etebase_project_dir }} project directory" + file: + path: "{{ etebase_project_dir }}" + state: directory + +- name: Template docker-compose.yaml to project directory + template: + src: docker-compose.yaml + dest: "{{ etebase_project_dir }}/docker-compose.yaml" + owner: "{{ ansible_env['USER'] }}" + group: "{{ ansible_env['USER'] }}" + mode: '640' + +- name: Template etebase-server.ini to project directory + template: + src: etebase-server.ini + dest: "{{ etebase_project_dir }}/etebase-server.ini" + owner: "{{ ansible_env['USER'] }}" + group: "{{ ansible_env['USER'] }}" + mode: '644' + +- name: "Create directory {{ volumes['etebase_datadir'] }} with correct permissions" + file: + path: "{{ volumes['etebase_datadir'] }}" + state: directory + owner: "{{ users['etebase'] + uid_shift }}" + group: "{{ users['etebase'] + uid_shift }}" + mode: '770' + become: true + +- name: Pull/Create/Restart project services + community.docker.docker_compose: + project_src: "{{ etebase_project_dir }}" + pull: "{{ docker_pull_images | bool }}"