Skip to content

Commit 19062f9

Browse files
authored
Merge pull request #4769 from Blargian/restore_replica_kb
Knowledge base: add KB article and allow vertical stepper to work in Knowledge Base
2 parents a176f9e + 20351fe commit 19062f9

File tree

7 files changed

+126
-4
lines changed

7 files changed

+126
-4
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
date: 2025-11-19
3+
title: How to restore a replica after storage failure
4+
tags: ['Deployments and Scaling']
5+
keywords: ['restore', 'replica', 'storage failure', 'atomic database']
6+
description: 'This article explains how to recover data when using replicated tables in atomic databases in ClickHouse and disks/storage on one of the replica is lost/currupted.'
7+
---
8+
9+
{frontMatter.description}
10+
{/* truncate */}
11+
12+
<br/>
13+
<br/>
14+
15+
<VerticalStepper headerLevel="h2">
16+
17+
:::note
18+
This guide assumes that the `<path>` parameter in your config.xml file is set to:
19+
20+
```text
21+
<path>/var/lib/clickhouse/</path>
22+
```
23+
24+
If you have configured a different data path, replace all instances of `/var/lib/clickhouse` in the below commands with the actual value of your `<path>` setting.
25+
:::
26+
27+
## Copy access configuration from the healthy replica {#copy-access-config}
28+
29+
Copy the contents of the `access` folder which contains local users from the healthy replica:
30+
31+
```text
32+
/var/lib/clickhouse/access
33+
```
34+
35+
## Back up the metadata folder from the healthy replica
36+
37+
1. Navigate to the ClickHouse data directory:
38+
39+
```text
40+
cd /var/lib/clickhouse
41+
```
42+
43+
2. Create a backup of the metadata folder (including symbolic links): The metadata directory contains DDLs for databases and tables.
44+
The database directory has symlinks to `/var/lib/clickhouse/store/..` which contains all the table DDLs.
45+
46+
```bash
47+
{ find metadata -type f; find metadata -type l; find metadata -type l | xargs readlink -f; } | tar -cPf backup.tar --files-from=-
48+
```
49+
50+
:::note
51+
This command ensures that both the **metadata files**, and the symlink architecture are preserved in the backup.
52+
:::
53+
54+
## Restore the metadata on the faulty replica {#restore-the-metadata-on-the-faulty-replica}
55+
56+
1. Copy the generated `backup.tar` file to the faulty replica.
57+
2. Extract it to the ClickHouse data directory:
58+
59+
```text
60+
cd /var/lib/clickhouse/
61+
tar -xvPf backup.tar
62+
```
63+
64+
## Create the force restore flag {#create-force-restore-flag}
65+
66+
To trigger automatic data synchronization from other replicas, create the following flag:
67+
68+
```text
69+
sudo -u clickhouse touch /var/lib/clickhouse/flags/force_restore_data
70+
```
71+
72+
## Restart the faulty replica {#restart-faulty-replica}
73+
74+
1. Restart the ClickHouse server on the faulty node.
75+
2. Check the server logs, you should observe parts being downloaded from the healthy replicas:
76+
77+
```bash
78+
2025.11.02 00:00:04.047097 [ 682 ] {} <Debug> analytics.events_local (...) (Fetcher): Downloading files 23
79+
2025.11.02 00:00:04.055542 [ 682 ] {} <Debug> analytics.events_local (...) (Fetcher): Download of part 202511_0_0_0 onto disk disk2 finished.
80+
2025.11.02 00:00:04.101888 [ 687 ] {} <Debug> warehouse.customers_local (...) (Fetcher): Downloading part 2025_0_0_1 onto disk default.
81+
2025.11.02 00:00:04.102005 [ 687 ] {} <Debug> warehouse.customers_local (...) (Fetcher): Downloading files 11
82+
2025.11.02 00:00:04.102210 [ 690 ] {} <Debug> warehouse.customers_local (...) (Fetcher): Downloading part 2022_0_0_1 onto disk disk1.
83+
2025.11.02 00:00:04.102247 [ 688 ] {} <Debug> warehouse.customers_local (...) (Fetcher): Downloading part 2021_0_0_1 onto disk disk2.
84+
2025.11.02 00:00:04.102331 [ 690 ] {} <Debug> warehouse.customers_local (...) (Fetcher): Downloading files 11
85+
```
86+
87+
</VerticalStepper>

plugins/remark-custom-blocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const plugin = (options) => {
3838
visit(tree, 'mdxJsxFlowElement', (node, index, parent) => {
3939
// Look specifically for the <VerticalStepper> tag used in the markdown file
4040
if (node.name === 'VerticalStepper') {
41-
try {
41+
try{
4242
// --- 1. Parse <VerticalStepper> Attributes ---
4343
const jsxAttributes = node.attributes || [];
4444
let type = "numbered"; // Default type

scripts/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/bash
22

3+
# Set locale to prevent perl warnings in child processes
4+
export LC_ALL=C
5+
export LANG=C
6+
37
function parse_args() {
48
locale="" # Default: No locale specified
59
out_dir="" # Default: No custom output directory

scripts/sed_links.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/bash
22

3+
# Set locale to prevent perl warnings
4+
export LC_ALL=C
5+
export LANG=C
6+
37
# Sometimes we need to change links which are reporting as broken
48
# but they are from the ClickHouse/ClickHouse repo. In this case
59
# it's useful to sed the link so that the build can pass and then

src/components/CodeViewer/CodeInterpreter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Button, Icon, RadioGroup, Tooltip } from '@clickhouse/click-ui/bundled'
22
import { createClient as createWebClient } from '@clickhouse/client-web'
3-
import { parse } from 'json5'
3+
import JSON5 from 'json5'
44
import { useEffect, useState } from 'react'
55
import short from 'short-uuid'
66
import CodeResults, { DefaultView } from './CodeResults'
@@ -90,7 +90,7 @@ function CodeInterpreter({
9090
params.forEach((param) => {
9191
if (param.type && /^(Array|Map|Tuple|Nested)/.test(param.type)) {
9292
try {
93-
query_params[param.name] = parse(param.value)
93+
query_params[param.name] = JSON5.parse(param.value)
9494
} catch (e) {
9595
// just send and let clickhouse error
9696
query_params[param.name] = param.value

src/theme/BlogLayout/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import BlogLayout from '@theme-original/BlogLayout';
3+
import {ClickUIProvider} from '@clickhouse/click-ui/bundled';
4+
import {useColorMode} from "@docusaurus/theme-common";
5+
6+
function BlogContentWithProvider({children}) {
7+
const { colorMode } = useColorMode();
8+
return (
9+
<ClickUIProvider theme={colorMode}>
10+
{children}
11+
</ClickUIProvider>
12+
);
13+
}
14+
15+
export default function BlogLayoutWrapper(props) {
16+
const {children, ...otherProps} = props;
17+
18+
return (
19+
<BlogLayout {...otherProps}>
20+
<BlogContentWithProvider>
21+
{children}
22+
</BlogContentWithProvider>
23+
</BlogLayout>
24+
);
25+
}

src/theme/MDXComponents.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const enhancedComponents = {
2020
// Map to the components expected from the remark plugin
2121
Stepper: VStepper,
2222
Step: VStepper.Step,
23+
// Also map VerticalStepper directly for cases where remark plugin doesn't transform it
24+
VerticalStepper: VStepper,
2325
};
2426

25-
export default enhancedComponents;
27+
export default enhancedComponents;

0 commit comments

Comments
 (0)