2023-09-03 12:25:37 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# Backup script for Calibre-web in a Kubernetes cluster
|
|
|
|
|
|
|
|
PROGRAM_NAME='backup_calibre-web'
|
|
|
|
printlog () {
|
|
|
|
printf '%s: %s\n' "${PROGRAM_NAME}" "${1}"
|
|
|
|
}
|
2023-06-15 20:56:48 +02:00
|
|
|
|
2023-06-15 23:24:56 +02:00
|
|
|
BACKUP_DEST='/mnt/PRIVATE_DOCS/BACKUPS/calibre-web'
|
|
|
|
DATABASE_FILE='/config/app.db'
|
2023-06-15 22:25:10 +02:00
|
|
|
|
2023-06-15 23:24:56 +02:00
|
|
|
# Create filename for database backup
|
2023-09-03 12:25:37 +02:00
|
|
|
database_backupfile="calibre-web-app_$( date +'%Y%m%d' ).db"
|
2023-06-15 20:56:48 +02:00
|
|
|
|
|
|
|
# Retrieve container name
|
2023-06-15 23:24:56 +02:00
|
|
|
base_container="$( docker ps --format '{{.Names}}' | grep tkioskje-calibre-web_tkioskje-calibre-web )"
|
2023-06-15 20:56:48 +02:00
|
|
|
|
|
|
|
# Abort entire script if any command fails
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Database backup
|
2023-09-03 12:25:37 +02:00
|
|
|
printlog 'Backing up database'
|
2023-06-15 23:24:56 +02:00
|
|
|
docker cp "${base_container}":"${DATABASE_FILE}" "${BACKUP_DEST}/${database_backupfile}"
|
2023-06-15 20:56:48 +02:00
|
|
|
|
2023-06-15 23:24:56 +02:00
|
|
|
# Backup cleanup
|
|
|
|
# Only keep 30 most recent backups
|
2023-09-03 12:25:37 +02:00
|
|
|
printlog 'Cleaning up old database backups'
|
|
|
|
find "${BACKUP_DEST}" -type f -mtime +30 -print -delete
|
|
|
|
|
|
|
|
printlog 'Done'
|