Skip to Content
Edit on GitHub

Backups

Regular backups are essential for protecting your LearnHouse data. The LearnHouse CLI provides built-in backup and restore commands for the PostgreSQL database.

The built-in backup only covers the database and your .env file. Uploaded content (images, videos, documents) stored on the filesystem is not included. See Filesystem Content below for recommendations.

Creating a Backup

Create a backup with a single command:

learnhouse backup

This creates a timestamped archive containing:

  • database.sql — a pg_dump of the LearnHouse PostgreSQL database
  • .env — a copy of your instance’s environment file (if present)

Backups are written to <installDir>/backups/learnhouse-backup-<timestamp>.tar.gz. The CLI prints the absolute path when the backup completes.

learnhouse backup only works when PostgreSQL runs in a local Docker container managed by the CLI. If you use an external managed database, use that provider’s native backup tools instead.

Restoring from a Backup

To restore from a backup file:

learnhouse restore <installDir>/backups/learnhouse-backup-<timestamp>.tar.gz

The restore command replays database.sql into the running database container. It does not stop or restart services — restart them yourself if needed.

Restoring a backup overwrites the database. Make sure you are restoring to the correct instance.

Automating Backups

It is recommended to set up automated backups using a cron job. For example, to create a daily backup at 2:00 AM:

# Edit your crontab
crontab -e
 
# Add this line for daily backups at 2 AM
0 2 * * * /usr/local/bin/learnhouse backup

Backup Retention

Backup files accumulate over time and can consume significant disk space. Implement a retention policy to remove old backups. For example, keep the last 7 daily backups:

find <installDir>/backups -name "learnhouse-backup-*.tar.gz" -mtime +7 -delete

Filesystem Content

When LEARNHOUSE_CONTENT_DELIVERY_TYPE=filesystem, uploaded files live on the host (or in a Docker volume) and are not captured by learnhouse backup. You are responsible for backing up this directory separately — for example with rsync, a volume snapshot, or a scheduled tar job.

When using s3api storage, rely on your S3 provider’s versioning, lifecycle, or cross-region replication features to protect uploaded content.