Add crude DB backups
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
ansible-navigator.log
|
ansible-navigator.log
|
||||||
collections/
|
collections/
|
||||||
|
backups/
|
||||||
|
|||||||
@@ -71,6 +71,47 @@
|
|||||||
- name: Install database quadlet
|
- name: Install database quadlet
|
||||||
ansible.builtin.include_tasks: db.yml
|
ansible.builtin.include_tasks: db.yml
|
||||||
|
|
||||||
|
- name: Schedule postgres database backup
|
||||||
|
ansible.builtin.cron:
|
||||||
|
name: "Backup mastodon postgres database"
|
||||||
|
minute: "0"
|
||||||
|
hour: "3"
|
||||||
|
job: >-
|
||||||
|
podman exec database pg_dump -U {{ mastodon_database.username }} mastodon
|
||||||
|
| gzip > ~/backups/mastodon-$(date +\%Y\%m\%d\%H\%M\%S).sql.gz &&
|
||||||
|
find ~/backups/ -type f -mtime 7 -delete
|
||||||
|
|
||||||
|
- name: Find backup files
|
||||||
|
ansible.builtin.find:
|
||||||
|
paths: "~/backups"
|
||||||
|
patterns: "mastodon-*.sql.gz"
|
||||||
|
register: mastodon_backup_files
|
||||||
|
tags:
|
||||||
|
- backup
|
||||||
|
|
||||||
|
- name: Identify latest backup file
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
mastodon_latest_backup: "{{ (mastodon_backup_files.files | sort(attribute='mtime') | last).path }}"
|
||||||
|
tags:
|
||||||
|
- backup
|
||||||
|
|
||||||
|
- name: Ensure local backup directory exists
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ mastodon_local_backup_dir }}"
|
||||||
|
state: directory
|
||||||
|
delegate_to: localhost
|
||||||
|
become: false
|
||||||
|
tags:
|
||||||
|
- backup
|
||||||
|
|
||||||
|
- name: Download latest backup file to local machine
|
||||||
|
ansible.builtin.fetch:
|
||||||
|
src: "{{ mastodon_latest_backup }}"
|
||||||
|
dest: "{{ mastodon_local_backup_dir }}/{{ mastodon_latest_backup | basename }}"
|
||||||
|
flat: true
|
||||||
|
tags:
|
||||||
|
- backup
|
||||||
|
|
||||||
- name: Install redis quadlet
|
- name: Install redis quadlet
|
||||||
ansible.builtin.include_tasks: redis.yml
|
ansible.builtin.include_tasks: redis.yml
|
||||||
|
|
||||||
|
|||||||
@@ -7,3 +7,6 @@ mastodon_local_dirs:
|
|||||||
- "~/mastodon/redis"
|
- "~/mastodon/redis"
|
||||||
- "~/mastodon/elasticsearch"
|
- "~/mastodon/elasticsearch"
|
||||||
- "~/mastodon/system"
|
- "~/mastodon/system"
|
||||||
|
- "~/backups"
|
||||||
|
|
||||||
|
mastodon_local_backup_dir: "{{ playbook_dir }}/backups"
|
||||||
|
|||||||
Reference in New Issue
Block a user