Restore

Last updated:

|Edit this page

A backup is worthless if the restoration process hasn’t been tested. If you backed something up and never tried to restore it, chances are that restore will not work properly when you actually need it or it will take longer than business can tolerate. Perform regular test restores to ensure your data will be there when you need it!

Automated using clickhouse-backup

The tool provides an automatic restore operation that you can invoke by running: clickhouse-backup restore <BACKUP NAME>.

For more information please look at the official documentation.

Manual

In this specific example, we will restore the table events.

  1. Optional: create the table you would like to restore (if it doesn’t exist yet) from its backed up metadata file

    Terminal
    cat events.sql | clickhouse-client --database posthog
  2. Copy the backup data from the data/posthog/events/ directory inside the backup you want to restore to the /var/lib/clickhouse/data/posthog/events/detached/ directory

    Terminal
    cp -r $SOURCE_BACKUP_LOCATION/data/posthog/events/* /var/lib/clickhouse/data/posthog/events/detached/
  3. Add the data to the table from the detached directory. It is possible to add data for an entire partition or for a separate part (take a look here for more info)

    Terminal
    clickhouse-client --database posthog --query "ALTER TABLE events ATTACH PARTITION 202111"
  4. Your data should be now available

    Terminal
    clickhouse-client --database posthog --query "SELECT COUNT(1) from events"

Questions?

Was this page useful?

Next article

Scaling ClickHouse Vertically

How to scale ClickHouse vertically Currently the easiest way to scale up a ClickHouse environment hosted by our helm chart config is to set the affinity for which node ClickHouse is deployed to and scale that node up in terms of the resources it has available to it. This is very easy to do in practice. Let's get down to the nuts and bolts of how to get this done! Create a node instance or group with more CPU and memory in your K8s cluster with a label of clickhouse:true set on it (this will…

Read next article