2023-06-15 20:56:48 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# Backup script for Calibre-web in a kubernetes cluster
|
|
|
|
|
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
|
|
|
|
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-06-15 23:24:56 +02:00
|
|
|
>&2 echo 'Backing up database'
|
|
|
|
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
|
|
|
|
>&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'
|