Hugo/backups/create_gitea_backup.sh

38 lines
1.2 KiB
Bash
Raw Normal View History

2023-07-01 23:29:19 +02:00
#!/bin/bash
# Backup script for Gitea in a Kubernetes cluster
# `gitea dump` is a mess that we should not touch. We write our own backup scripts instead.
BACKUP_DEST='/mnt/PRIVATE_DOCS/BACKUPS/gitea'
PASSFILE='./gitea_pass.txt'
# Retrieve container names
base_container="$( docker ps --format '{{.Names}}' | grep 'hugit-gitea_hugit-gitea' )"
database_container="$( docker ps --format '{{.Names}}' | grep 'hugit-postgresql_hugit-postgresql' )"
# Abort entire script if any command fails
set -e
# Enable maintenance mode
# Flush queues
docker exec "${base_container}" gitea manager flush-queues
# Pause queues
# TODO
# Backup the database
>&2 echo 'Backing up database'
database_backupfile="gitea-sqlbkp_$( date +'%Y%m%d' ).bak"
internal_database_backupfile="/tmp/${database_backupfile}"
docker exec --env-file "${PASSFILE}" "${database_container}" pg_dump 'gitea' -cwv -h 'localhost' -U 'gitea' -f "${internal_database_backupfile}"
docker cp "${database_container}":"${internal_database_backupfile}" "${BACKUP_DEST}"
# Backup files
2023-07-02 21:52:26 +02:00
tar czvf "${BACKUP_DEST}/gitea-data_$(date +'%Y%m%d').tar.gz" -C "/mnt/APPS/hugit"
2023-07-01 23:29:19 +02:00
# Disable maintenance mode
# TODO
# Double check
# gitea doctor --all --log-file /tmp/doctor.log
# TODO