Add crude DB backups

This commit is contained in:
2026-09-15 21:18:49 +03:00
parent b9b855928c
commit f53608fbb4
3 changed files with 45 additions and 0 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
ansible-navigator.log
collections/
backups/

View File

@@ -71,6 +71,47 @@
- name: Install database quadlet
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
ansible.builtin.include_tasks: redis.yml

View File

@@ -7,3 +7,6 @@ mastodon_local_dirs:
- "~/mastodon/redis"
- "~/mastodon/elasticsearch"
- "~/mastodon/system"
- "~/backups"
mastodon_local_backup_dir: "{{ playbook_dir }}/backups"