#!/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'