#!/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. PROGRAM_NAME='backup_gitea' printlog () { printf '%s: %s\n' "${PROGRAM_NAME}" "${1}" } 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 printlog 'Flushing queues' docker exec "${base_container}" gitea manager flush-queues # Pause queues # TODO # Backup the database printlog '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 printlog 'Backing up files' tar czvf "${BACKUP_DEST}/gitea-data_$( date +'%Y%m%d' ).tar.gz" -C "/mnt/APPS/hugit" # Disable maintenance mode # TODO # Double check # gitea doctor --all --log-file /tmp/doctor.log # TODO printlog 'Done'