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 Neon object storage.
2 min read
You need:
- The key of the server from Back up the analytics database, step 1. The restore reads the backups with this key, so do that step first.
- To be signed in to the server as root. See Sign in to the server.
neonctl, signed in to the TanStack organization on Neon, on your computer, for step 1.
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 backups of the Neon project source-backups has one folder for each night that it keeps, 8 or 9 of them, named by the UTC day. On your computer, list them:
neonctl buckets object list backups --project-id wandering-moon-95155232 --branch main
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://br-steep-term-bcsp8mb3.storage.c-16.us-east-1.aws.neon.tech/backups/<day>/')"
Note
A backup from before the server moved to Neon is in the R2 bucket gitflare-analytics for 8 days after the move. Its URL is https://<account id>.r2.cloudflarestorage.com/gitflare-analytics/backups/<day>/, and the R2 key of the server stays for those 8 days. See Move the backups of a server from R2.
Done
Count the rows again, with the command of step 2. The count is now the number of events in the backup.