mirror of
https://github.com/learnhouse/docs.git
synced 2026-11-29 01:10:27 +01:00
69 lines
2.5 KiB
Plaintext
69 lines
2.5 KiB
Plaintext
import { Callout } from 'nextra/components'
|
|
|
|
# Backups
|
|
|
|
Regular backups are essential for protecting your LearnHouse data. The LearnHouse CLI provides built-in backup and restore commands for the PostgreSQL database.
|
|
|
|
<Callout type="warning">
|
|
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](#filesystem-content) below for recommendations.
|
|
</Callout>
|
|
|
|
## Creating a Backup
|
|
|
|
Create a backup with a single command:
|
|
|
|
```bash
|
|
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.
|
|
|
|
<Callout type="info">
|
|
`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.
|
|
</Callout>
|
|
|
|
## Restoring from a Backup
|
|
|
|
To restore from a backup file:
|
|
|
|
```bash
|
|
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.
|
|
|
|
<Callout type="warning">
|
|
Restoring a backup overwrites the database. Make sure you are restoring to the correct instance.
|
|
</Callout>
|
|
|
|
## 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:
|
|
|
|
```bash
|
|
# 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:
|
|
|
|
```bash
|
|
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.
|