Site administration
Restore an analytics backup
The analytics server lost its data, and you need the events back. Restore the database from one of the nightly backups in R2.
1 min read
You need:
- The R2 token of Back up the analytics database on the server. The restore reads R2 with this token, so do those steps first.
- To be signed in to the server as root. See Sign in to the server.
Important
On a new server, restore before you start cloudflared (step 6 of the setup). After that step, the queue puts new rows in the table.
1. Find the day that you want
The bucket gitflare-analytics has one folder for each day under backups/.
2. Make sure that the tables are empty
ClickHouse does not restore into a table that has rows. This command must print 0:
clickhouse-client --password "$(cat /root/.clickhouse-admin)" --query "SELECT (SELECT count() FROM analytics.events) + (SELECT count() FROM analytics.rank_actions)"
3. Restore the backup of that day
clickhouse-client --password "$(cat /root/.clickhouse-admin)" --query "RESTORE DATABASE analytics FROM S3('https://<account id>.r2.cloudflarestorage.com/gitflare-analytics/backups/<day>/')"
Done
Count the rows again, with the command of step 2. The count is now the number of events in the backup.