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:
- The PostgreSQL database (users, meeting types, created bookings, calendar records).
- The application data volume
/app/data(uploaded profile photos and backgrounds inuploads/, the bookers' private attachments inprivate_uploads/and possibly the.envfile). - Configuration keys and the
.envfile (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:
- Install Docker and Docker Compose on the new server.
- Upload the backed-up
.envfile and the contents of the data volume/app/data(e.g.docker compose cp ./data/. app:/app/data). - Start the database container:
docker compose up -d db - 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 - Start the main LockMyCal container:
docker compose up -d app - Check the logs with
docker compose logs -f appand verify access through a web browser.