Compare commits
No commits in common. "cd8a21a63db7cfaf2b62408a47d794532f1bff96" and "e483e678b188bc3bee4fb20e42b88dd10b0d6c06" have entirely different histories.
cd8a21a63d
...
e483e678b1
3 changed files with 70 additions and 80 deletions
33
backups/create_calibre-web_backup.sh
Executable file
33
backups/create_calibre-web_backup.sh
Executable file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Backup script for Calibre-web in a kubernetes cluster
|
||||||
|
|
||||||
|
BACKUP_DEST='/mnt/PRIVATE_DOCS/BACKUPS/calibre-web'
|
||||||
|
DATABASE_FILE='/config/app.db'
|
||||||
|
|
||||||
|
# Create filename for database backup
|
||||||
|
database_backupfile="calibre-web-app_$(date +'%Y%m%d').db"
|
||||||
|
|
||||||
|
# Retrieve container name
|
||||||
|
base_container="$( docker ps --format '{{.Names}}' | grep tkioskje-calibre-web_tkioskje-calibre-web )"
|
||||||
|
|
||||||
|
# Abort entire script if any command fails
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Database backup
|
||||||
|
>&2 echo 'Backing up database'
|
||||||
|
docker cp "${base_container}":"${DATABASE_FILE}" "${BACKUP_DEST}/${database_backupfile}"
|
||||||
|
|
||||||
|
# Backup cleanup
|
||||||
|
# Only keep 30 most recent backups
|
||||||
|
>&2 echo 'Cleaning up old database backups'
|
||||||
|
pushd "${BACKUP_DEST}"
|
||||||
|
excess="$( ls -x | head -n -30 )"
|
||||||
|
if [ -n "${excess}" ]; then
|
||||||
|
>&2 echo "Removing ${excess}"
|
||||||
|
rm "${excess}"
|
||||||
|
else
|
||||||
|
>&2 echo 'Skipping: nothing to remove'
|
||||||
|
fi
|
||||||
|
popd
|
||||||
|
|
||||||
|
>&2 echo 'Done'
|
37
backups/create_gitea_backup.sh
Executable file
37
backups/create_gitea_backup.sh
Executable file
|
@ -0,0 +1,37 @@
|
||||||
|
#!/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
|
||||||
|
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
|
|
@ -1,80 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# Backup Gitea database in a Kubernetes environment
|
|
||||||
# Usage: backup-database [OPTIONS] <destination>
|
|
||||||
|
|
||||||
# `gitea dump` is a mess that we should not touch. We write our own backup scripts instead.
|
|
||||||
#
|
|
||||||
usage() {
|
|
||||||
>&2 printf "Usage: %s <destination>\n" "${0}"
|
|
||||||
>&2 printf "Options:\n"
|
|
||||||
>&2 printf "\t-e \t Specify the environment file to use\n"
|
|
||||||
exit "${1:-1}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get options
|
|
||||||
|
|
||||||
while getopts ":e:" option; do
|
|
||||||
case "${option}" in
|
|
||||||
e)
|
|
||||||
if ! [ -f "${OPTARG}" ]; then
|
|
||||||
>&2 printf "Error: Specified environment file does not exist: '%s'.\n" "${OPTARG}"
|
|
||||||
elif ! [ -r "${OPTARG}" ]; then
|
|
||||||
>&2 printf "Error: Specified environment file is not readable: '%s'.\n" "${OPTARG}"
|
|
||||||
fi
|
|
||||||
env_file="${OPTARG}"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
>&2 printf "Error: Invalid option: '%s'.\n" "${option}"
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
shift $(( OPTIND - 1 ))
|
|
||||||
|
|
||||||
# Check arguments.
|
|
||||||
|
|
||||||
if [ $# -ne 1 ]; then
|
|
||||||
>&2 printf "Error: You need to specify a destination.\n"
|
|
||||||
usage
|
|
||||||
elif ! [ -d "${1}" ]; then
|
|
||||||
>&2 printf "Error: Specified destination does not exist or is not readable : '%s'.\n" "${1}"
|
|
||||||
usage
|
|
||||||
else
|
|
||||||
destination="${1}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Retrieve container names
|
|
||||||
base_container="$( docker ps --format '{{.Names}}' | grep -E 'gitea_gitea-[0-9a-z]{10}-[0-9a-z]{5}' )"
|
|
||||||
database_container="$( docker ps --format '{{.Names}}' | grep 'postgres_gitea-cnpg-main-1' )"
|
|
||||||
|
|
||||||
if ! [[ -n "${base_container}" && -n "${database_container}" ]]; then
|
|
||||||
>&2 printf "Error: Not all containers could be found.\n"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Abort entire script if any command fails
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Enable maintenance mode
|
|
||||||
# Flush queues
|
|
||||||
docker exec "${base_container}" gitea manager flush-queues
|
|
||||||
# TODO Pause queues
|
|
||||||
|
|
||||||
# Database backup
|
|
||||||
|
|
||||||
# Filename for database backup.
|
|
||||||
database_backupfile="gitea-sqlbkp_$( date +'%Y%m%d' ).bak"
|
|
||||||
host_database_backupfile="${destination}/${database_backupfile}"
|
|
||||||
|
|
||||||
# Backup the database
|
|
||||||
>&2 echo 'Backing up database'
|
|
||||||
docker exec --env-file "${env_file:=.env}" "${database_container}" pg_dump 'gitea' -cwv -h 'localhost' -U 'gitea' > "${host_database_backupfile}"
|
|
||||||
|
|
||||||
# Disable maintenance mode
|
|
||||||
# TODO Continue queues
|
|
||||||
|
|
||||||
# Double check
|
|
||||||
# gitea doctor --all --log-file /tmp/doctor.log
|
|
||||||
# TODO
|
|
||||||
|
|
||||||
printf "Done.\n"
|
|
Loading…
Reference in a new issue