Backup and Data Recovery (Backup & Restore)

Regular backups protect your instance against hardware failures, disk errors or accidental deletion. A proper LockMyCal backup strategy consists of three components:

  1. The PostgreSQL database (users, meeting types, created bookings, calendar records).
  2. The application data volume /app/data (uploaded profile photos and backgrounds in uploads/, the bookers' private attachments in private_uploads/ and possibly the .env file).
  3. Configuration keys and the .env file (SECRET_KEY_BASE, DATA_ENCRYPTION_KEY).

1. Backing up the PostgreSQL database

A manual dump using pg_dump

If the database runs in the Docker container lockmycal-db:

docker exec -t lockmycal-db pg_dump -U lockmycal -d lockmycal_prod -F c -b -v -f /tmp/lockmycal_backup.dump
docker cp lockmycal-db:/tmp/lockmycal_backup.dump ./lockmycal_backup_$(date +%Y%m%d_%H%M%S).dump

An automatic daily Cron script

Create the script /opt/lockmycal/backup.sh:

#!/bin/bash
BACKUP_DIR="/opt/lockmycal/backups"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
mkdir -p "$BACKUP_DIR"

# DB backup
docker exec -t lockmycal-db pg_dump -U lockmycal -d lockmycal_prod -F c | gzip > "$BACKUP_DIR/db_$TIMESTAMP.sql.gz"

# Backup of the application data volume (uploads, private_uploads, possibly .env) and the configuration
docker compose cp app:/app/data "$BACKUP_DIR/data_$TIMESTAMP"
tar -czf "$BACKUP_DIR/files_$TIMESTAMP.tar.gz" -C "$BACKUP_DIR" "data_$TIMESTAMP" -C /opt/lockmycal .env
rm -rf "$BACKUP_DIR/data_$TIMESTAMP"

# Delete backups older than 14 days
find "$BACKUP_DIR" -type f -mtime +14 -delete

Add to crontab -e:

0 3 * * * /opt/lockmycal/backup.sh > /dev/null 2>&1

2. Critical backup of the encryption keys (.env)

Caution

LockMyCal encrypts OAuth tokens and sensitive data using the DATA_ENCRYPTION_KEY key. If you lose this key, you won't be able to decrypt the calendar connections even after restoring the database from a backup! Keep the .env file safely backed up in a separate place.


3. Recovery procedure (Disaster Recovery)

When restoring data to a new server, proceed as follows:

  1. Install Docker and Docker Compose on the new server.
  2. Upload the backed-up .env file and the contents of the data volume /app/data (e.g. docker compose cp ./data/. app:/app/data).
  3. Start the database container:
    docker compose up -d db
  4. Restore the database from the dump:
    docker cp lockmycal_backup.dump lockmycal-db:/tmp/restore.dump
    docker exec -i lockmycal-db pg_restore -U lockmycal -d lockmycal_prod -v -c /tmp/restore.dump
  5. Start the main LockMyCal container:
    docker compose up -d app
  6. Check the logs with docker compose logs -f app and verify access through a web browser.