mirror of
https://github.com/plausible/hosting.git
synced 2024-10-02 11:58:58 -05:00
4.1 KiB
4.1 KiB
Guide to backing up and restoring plausible_events_db
. Based on "Backup and Restore" from ClickHouse.
Note: following this guide you'd need to stop some containers and it would make your plausible instance temporarily unavailable.
Plan
- dump contents of the Plausible tables (events, sessions, imported_*) to files in a mounted volume
- load dumps from the mounted volume into
plausible_events_db
Backup
- Add backup config to allow reading backup files in the ClickHouse container
$ touch clickhouse/backups.xml
<clickhouse>
<storage_configuration>
<disks>
<backups>
<type>local</type>
<path>/backups/</path>
</backups>
</disks>
</storage_configuration>
<backups>
<allowed_disk>backups</allowed_disk>
<allowed_path>/backups/</allowed_path>
</backups>
</clickhouse>
- Add backups volume to
plausible_events_db
in yourdocker-compose.yml
plausible_events_db:
image: clickhouse/clickhouse-server:22.6
volumes:
- event-data:/var/lib/clickhouse
- ./clickhouse/:/etc/clickhouse-server/config.d/
+ - ./clickhouse-backups:/backups
- Stop relevant containers to avoid writing to old
plausible_events_db
> docker compose stop plausible plausible_events_db
[+] Running 2/2
⠿ Container hosting-plausible-1 Stopped 6.5s
⠿ Container hosting-plausible_events_db-1 Stopped 0.2s
- Restart
plausible_events_db
container to attach volume
> docker compose up plausible_events_db -d
[+] Running 1/1
⠿ Container hosting-plausible_events_db-1 Started 0.3s
- Dump old
plausible_events_db
contents to backup files
> docker compose exec plausible_events_db sh -c "clickhouse-client --query 'BACKUP TABLE plausible_events_db.events TO Disk('backups', 'events.zip')'"
> docker compose exec plausible_events_db sh -c "clickhouse-client --query 'BACKUP TABLE plausible_events_db.sessions TO Disk('backups', 'sessions.zip')'"
> docker compose exec plausible_events_db sh -c "clickhouse-client --query 'BACKUP TABLE plausible_events_db.imported_visitors TO Disk('backups', 'imported_visitors.zip')'"
# etc.
TODO: script
- (Optional) verify backup went OK
> ls backups
events.zip sessions.zip imported_visitors.zip ...
- Move the backups somewhere, like a different host
Restore
- Ensure relevant containers are stopped
> docker compose stop plausible plausible_events_db
[+] Running 2/2
⠿ Container hosting-plausible-1 Stopped 0.0s
⠿ Container hosting-plausible_events_db-1 Stopped 0.2s
-
Ensure backup config from step 1 and backups mount from step 2 are still present.
-
Load data into from backups. TODO: User + permissions
> docker compose exec plausible_events_db sh -c "clickhouse-client --query 'RESTORE TABLE plausible_events_db.events FROM Disk('backups', 'events.zip')'"
> docker compose exec plausible_events_db sh -c "clickhouse-client --query 'RESTORE TABLE plausible_events_db.sessions FROM Disk('backups', 'sessions.zip')'"
> docker compose exec plausible_events_db sh -c "clickhouse-client --query 'RESTORE TABLE plausible_events_db.imported_visitors FROM Disk('backups', 'imported_visitors.zip')'"
# etc.
- Start all other containers
> docker compose up -d
[+] Running 4/4
⠿ Container hosting-plausible_events_db-1 Running 0.0s
⠿ Container hosting-mail-1 Running 0.0s
⠿ Container hosting-plausible_db-1 Started 0.5s
⠿ Container hosting-plausible-1 Started 0.5s
- (Optional) Remove backups from
docker-compose.yml
and your filesystem
plausible_events_db:
image: clickhouse/clickhouse-server:22.6
volumes:
- event-data:/var/lib/clickhouse
- ./clickhouse/:/etc/clickhouse-server/config.d/
- - ./clickhouse-backups:/backups
> rm -rf ./clickhouse-backups