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.
|
|
|
|
|
2023-09-03 12:25:37 +02:00
|
|
|
PROGRAM_NAME='backup_gitea'
|
|
|
|
printlog () {
|
|
|
|
printf '%s: %s\n' "${PROGRAM_NAME}" "${1}"
|
|
|
|
}
|
|
|
|
|
2023-07-01 23:29:19 +02:00
|
|
|
BACKUP_DEST='/mnt/PRIVATE_DOCS/BACKUPS/gitea'
|
|
|
|
PASSFILE='./gitea_pass.txt'
|
|
|
|
|
|
|
|
# Retrieve container names
|
2023-09-03 12:25:37 +02:00
|
|
|
base_container="$( docker ps --format '{{.Names}}' | grep hugit-gitea_hugit-gitea )"
|
|
|
|
database_container="$( docker ps --format '{{.Names}}' | grep hugit-postgresql_hugit-postgresql )"
|
2023-07-01 23:29:19 +02:00
|
|
|
|
|
|
|
# Abort entire script if any command fails
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Enable maintenance mode
|
2023-09-03 12:25:37 +02:00
|
|
|
printlog 'Flushing queues'
|
2023-07-01 23:29:19 +02:00
|
|
|
docker exec "${base_container}" gitea manager flush-queues
|
|
|
|
# Pause queues
|
|
|
|
# TODO
|
|
|
|
|
|
|
|
# Backup the database
|
2023-09-03 12:25:37 +02:00
|
|
|
printlog 'Backing up database'
|
2023-07-01 23:29:19 +02:00
|
|
|
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-09-03 12:25:37 +02:00
|
|
|
printlog 'Backing up files'
|
|
|
|
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
|
2023-09-03 12:25:37 +02:00
|
|
|
|
|
|
|
printlog 'Done'
|