30 lines
838 B
Bash
Executable file
30 lines
838 B
Bash
Executable file
#!/bin/sh
|
|
# Backup script for Calibre-web in a Kubernetes cluster
|
|
|
|
PROGRAM_NAME='backup_calibre-web'
|
|
printlog () {
|
|
printf '%s: %s\n' "${PROGRAM_NAME}" "${1}"
|
|
}
|
|
|
|
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
|
|
printlog 'Backing up database'
|
|
docker cp "${base_container}":"${DATABASE_FILE}" "${BACKUP_DEST}/${database_backupfile}"
|
|
|
|
# Backup cleanup
|
|
# Only keep 30 most recent backups
|
|
printlog 'Cleaning up old database backups'
|
|
find "${BACKUP_DEST}" -type f -mtime +30 -print -delete
|
|
|
|
printlog 'Done'
|