未验证 提交 26e14cff 编写于 作者: I Ivan Blinkov 提交者: GitHub

Introduce backup.md (only "en" for now) (#3812)

* CLICKHOUSE-4063: less manual html @ index.md

* CLICKHOUSE-4063: recommend markdown="1" in README.md

* CLICKHOUSE-4003: manually purge custom.css for now

* CLICKHOUSE-4064: expand <details> before any print (including to pdf)

* CLICKHOUSE-3927: rearrange interfaces/formats.md a bit

* CLICKHOUSE-3306: add few http headers

* Remove copy-paste introduced in #3392

* Hopefully better chinese fonts #3392

* get rid of tabs @ custom.css

* Apply comments and patch from #3384

* Add jdbc.md to ToC and some translation, though it still looks badly incomplete

* minor punctuation

* Add some backlinks to official website from mirrors that just blindly take markdown sources

* Do not make fonts extra light

* find . -name '*.md' -type f | xargs -I{} perl -pi -e 's//g' {}

* find . -name '*.md' -type f | xargs -I{} perl -pi -e 's/ sql/g' {}

* Remove outdated stuff from roadmap.md

* Not so light font on front page too

* Refactor Chinese formats.md to match recent changes in other languages

* Update some links on front page

* Remove some outdated comment

* Add twitter link to front page

* More front page links tuning

* Add Amsterdam meetup link

* Smaller font to avoid second line

* Add Amsterdam link to README.md

* Proper docs nav translation

* Back to 300 font-weight except Chinese

* fix docs build

* Update Amsterdam link

* remove symlinks

* more zh punctuation

* apply lost comment by @zhang2014

* Apply comments by @zhang2014 from #3417

* Remove Beijing link

* rm incorrect symlink

* restore content of docs/zh/operations/table_engines/index.md

* CLICKHOUSE-3751: stem terms while searching docs

* CLICKHOUSE-3751: use English stemmer in non-English docs too

* CLICKHOUSE-4135 fix

* Remove past meetup link

* Add blog link to top nav

* Add ContentSquare article link

* Add form link to front page + refactor some texts

* couple markup fixes

* minor

* Introduce basic ODBC driver page in docs

* More verbose 3rd party libs disclaimer

* Put third-party stuff into a separate folder

* Separate third-party stuff in ToC too

* Update links

* Move stuff that is not really (only) a client library into a separate page

* Add clickhouse-hdfs-loader link

* Some introduction for "interfaces" section

* Rewrite tcp.md

* http_interface.md -> http.md

* fix link

* Remove unconvenient error for now

* try to guess anchor instead of failing

* remove symlink

* Remove outdated info from introduction

* remove ru roadmap.md

* replace ru roadmap.md with symlink

* Update roadmap.md

* lost file

* Title case in toc_en.yml

* Sync "Functions" ToC section with en

* Remove reference to pretty old ClickHouse release from docs

* couple lost symlinks in fa

* Close quote in proper place

* Rewrite en/getting_started/index.md

* Sync en<>ru getting_started/index.md

* minor changes

* Some gui.md refactoring

* Translate DataGrip section to ru

* Translate DataGrip section to zh

* Translate DataGrip section to fa

* Translate DBeaver section to fa

* Translate DBeaver section to zh

* Split third-party GUI to open-source and commercial

* Mention some RDBMS integrations + ad-hoc translation fixes

* Add rel="external nofollow" to outgoing links from docs

* Lost blank lines

* Fix class name

* More rel="external nofollow"

* Apply suggestions by @sundy-li

* Mobile version of front page improvements

* test

* test 2

* test 3

* Update LICENSE

* minor docs fix

* Highlight current article as suggested by @sundy-li

* fix link destination

* Introduce backup.md (only "en" for now)

* Mention INSERT+SELECT in backup.md

* Some improvements for replication.md

* Add backup.md to toc

* Mention clickhouse-backup tool
上级 7af621f6
......@@ -8,6 +8,9 @@
- [ProxySQL](https://github.com/sysown/proxysql/wiki/ClickHouse-Support)
- [PostgreSQL](https://www.postgresql.org)
- [infi.clickhouse_fdw](https://github.com/Infinidat/infi.clickhouse_fdw) (uses [infi.clickhouse_orm](https://github.com/Infinidat/infi.clickhouse_orm))
- Object store
- S3
- [clickhouse-backup](https://github.com/AlexAkulov/clickhouse-backup)
- Python
- [SQLAlchemy](https://www.sqlalchemy.org)
- [sqlalchemy-clickhouse](https://github.com/cloudflare/sqlalchemy-clickhouse) (uses [infi.clickhouse_orm](https://github.com/Infinidat/infi.clickhouse_orm))
......
# Data Backup
While [replication](../table_engines/replication.md#table_engines-replication) provides protection from hardware failures, it does not protect against human errors: accidentally deleting data, deleting the wrong table or on the wrong cluster, software bugs leading to incorrect data processing or data corruption. In many cases commands like these will affect all replicas. ClickHouse has built-in safeguards to prevent some of mistakes, for example by default [you can't just drop tables with MergeTree-like engine containing more than 50Gb of data](https://github.com/yandex/ClickHouse/blob/v18.14.18-stable/dbms/programs/server/config.xml#L322-L330), but they don't cover all possible cases and can be circumvented.
So in order to effectively mitigate possible human errors, you should carefully prepare your backup and restore strategy **in advance**.
Each company has different resources available and different business requirements so there's no universal solution for ClickHouse backups and restores that will fit any situation. What works for gigabyte of data likely won't work for tens of petabytes. There are different possible approaches with their own pros and cons, which will be discussed below. Often it makes to employ few of those instead of just one to compensate their trade-offs.
!!! note "Note"
Keep in mind that if you backed something up and never tried to restore it, chances are that restore will not work properly when you'll need it (or at least will take longer than business can tolerate). So whatever backup approach you'll choose, make sure to automate restore process too and practice it on spare ClickHouse cluster regularly.
## Duplicating Source Data Somewhere Else
Often data that is ingested into ClickHouse is delivered through some sort of persistent queue, for example [Apache Kafka](https://kafka.apache.org). In this case it is possible to set up additional set of subscribers that will read same data stream as is written to ClickHouse and store it in some cold storage. Most companies already have some default recommended cold storage, it could be an object store or a distributed filesystem, for example [HDFS](https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-hdfs/HdfsDesign.html).
## Filesystem Snapshots
Some local filesystems provide functionality to create snapshots, for example [ZFS](https://en.wikipedia.org/wiki/ZFS), but they might be not best choice for serving live queries. Possible solution is to create additional replicas with this kind of filesystems and exclude them from distributed tables that are used for SELECT queries. Snapshots on such replicas will be out of reach of any queries modifying data. As a bonus these replicas might have different hardware configuration with much more disks attached per server, which will be cost-effective.
## clickhouse-copier
[clickhouse-copier](utils/clickhouse-copier.md) is a versatile tool initially created to re-shard petabytes-sized tables, but it can be used for backup and restore purposes as well because it just reliably copies data between ClickHouse tables and clusters.
For smaller volumes of data simple `INSERT INTO ... SELECT ...` to remote tables might work as well.
## Manipulations with Parts
ClickHouse allows to create a local copy of table partitions using `ALTER TABLE ... FREZE PARTITION ...` query. It's implemented using hardlinks to `/var/lib/clickhouse/shadow/` folder, so for old data it usually does not consume extra disk space. As created file copies are no longer touched by ClickHouse server, you can just leave them there: it's still be a simple backup that doesn't require any additional external system, but will be prone to hardware issues since. It's better to remotely copy them somewhere and then probably remove the local copies. Distributed filesystems and object stores are still a good options for this, but normal file servers attached with large enough capacity might work as well (in this case the transfer will happen via network filesystem or maybe [rsync](https://en.wikipedia.org/wiki/Rsync)).
More details on queries related to partition manipulations can be found in [respective section of ALTER documentation](../query_language/alter.md#query_language-manipulation-with-partitions-and-parts).
There's a third-party tool to automate this approach: [clickhouse-backup](https://github.com/AlexAkulov/clickhouse-backup).
[Original article](https://clickhouse.yandex/docs/en/operations/access_rights/) <!--hide-->
\ No newline at end of file
......@@ -93,7 +93,7 @@ ORDER BY (CounterID, EventDate, intHash32(UserID))
SAMPLE BY intHash32(UserID)
```
Example in deprecated syntax:
<details><summary>Example in deprecated syntax</summary>
```sql
CREATE TABLE table_name
......@@ -104,6 +104,8 @@ CREATE TABLE table_name
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/hits', '{replica}', EventDate, intHash32(UserID), (CounterID, EventDate, intHash32(UserID), EventTime), 8192)
```
</details>
As the example shows, these parameters can contain substitutions in curly brackets. The substituted values are taken from the 'macros' section of the configuration file. Example:
```xml
......@@ -180,7 +182,7 @@ There is no restriction on network bandwidth during recovery. Keep this in mind
We use the term `MergeTree` to refer to all table engines in the ` MergeTree family`, the same as for `ReplicatedMergeTree`.
If you had a `MergeTree` table that was manually replicated, you can convert it to a replicatable table. You might need to do this if you have already collected a large amount of data in a `MergeTree` table and now you want to enable replication.
If you had a `MergeTree` table that was manually replicated, you can convert it to a replicated table. You might need to do this if you have already collected a large amount of data in a `MergeTree` table and now you want to enable replication.
If the data differs on various replicas, first sync it, or delete this data on all the replicas except one.
......
......@@ -85,6 +85,8 @@ The command is lightweight in a sense that it only changes metadata. To keep the
rows are ordered by the sorting key expression you cannot add expressions containing existing columns
to the sorting key (only columns added by the `ADD COLUMN` command in the same `ALTER` query).
<a name="query_language-manipulation-with-partitions-and-parts"></a>
### Manipulations With Partitions and Parts
It only works for tables in the [`MergeTree`](../operations/table_engines/mergetree.md) family (including
......@@ -206,15 +208,6 @@ To restore from a backup:
In this way, data from the backup will be added to the table.
Restoring from a backup doesn't require stopping the server.
### Backups and Replication
Replication provides protection from device failures. If all data disappeared on one of your replicas, follow the instructions in the "Restoration after failure" section to restore it.
For protection from device failures, you must use replication. For more information about replication, see the section "Data replication".
Backups protect against human error (accidentally deleting data, deleting the wrong data or in the wrong cluster, or corrupting data).
For high-volume databases, it can be difficult to copy backups to remote servers. In such cases, to protect from human error, you can keep a backup on the same server (it will reside in `/var/lib/clickhouse/shadow/`).
``` sql
ALTER TABLE [db.]table FETCH PARTITION 'name' FROM 'path-in-zookeeper'
```
......
......@@ -10,6 +10,9 @@
- [ProxySQL](https://github.com/sysown/proxysql/wiki/ClickHouse-Support)
- [PostgreSQL](https://www.postgresql.org)
- [infi.clickhouse_fdw](https://github.com/Infinidat/infi.clickhouse_fdw) (استفاده می کند [infi.clickhouse_orm](https://github.com/Infinidat/infi.clickhouse_orm))
- فروشگاه شی
- S3
- [clickhouse-backup](https://github.com/AlexAkulov/clickhouse-backup)
- Python
- [SQLAlchemy](https://www.sqlalchemy.org)
- [sqlalchemy-clickhouse](https://github.com/cloudflare/sqlalchemy-clickhouse) (استفاده می کند [infi.clickhouse_orm](https://github.com/Infinidat/infi.clickhouse_orm))
......
../../en/operations/backup.md
\ No newline at end of file
......@@ -8,6 +8,9 @@
- [ProxySQL](https://github.com/sysown/proxysql/wiki/ClickHouse-Support)
- [PostgreSQL](https://www.postgresql.org)
- [infi.clickhouse_fdw](https://github.com/Infinidat/infi.clickhouse_fdw) (использует [infi.clickhouse_orm](https://github.com/Infinidat/infi.clickhouse_orm))
- Хранилища объектов
- S3
- [clickhouse-backup](https://github.com/AlexAkulov/clickhouse-backup)
- Python
- [SQLAlchemy](https://www.sqlalchemy.org)
- [sqlalchemy-clickhouse](https://github.com/cloudflare/sqlalchemy-clickhouse) (использует [infi.clickhouse_orm](https://github.com/Infinidat/infi.clickhouse_orm))
......
../../en/operations/backup.md
\ No newline at end of file
......@@ -78,10 +78,31 @@
Пример:
```sql
CREATE TABLE table_name
(
EventDate DateTime,
CounterID UInt32,
UserID UInt32
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/hits', '{replica}')
PARTITION BY toYYYYMM(EventDate)
ORDER BY (CounterID, EventDate, intHash32(UserID))
SAMPLE BY intHash32(UserID)
```
ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/hits', '{replica}', EventDate, intHash32(UserID), (CounterID, EventDate, intHash32(UserID), EventTime), 8192)
<details><summary>Пример в устаревшем синтаксисе</summary>
```sql
CREATE TABLE table_name
(
EventDate DateTime,
CounterID UInt32,
UserID UInt32
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/hits', '{replica}', EventDate, intHash32(UserID), (CounterID, EventDate, intHash32(UserID), EventTime), 8192)
```
</details>
Как видно в примере, эти параметры могут содержать подстановки в фигурных скобках. Подставляемые значения достаются из конфигурационного файла, из секции macros. Пример:
```xml
......
......@@ -82,6 +82,8 @@ MODIFY ORDER BY new_expression
сортировки, разрешено добавлять в ключ только новые столбцы (т.е. столбцы, добавляемые командой `ADD COLUMN`
в том же запросе `ALTER`), у которых нет выражения по умолчанию.
<a name="query_language-manipulation-with-partitions-and-parts"></a>
### Манипуляции с партициями и кусками
Работает только для таблиц семейства [`MergeTree`](../operations/table_engines/mergetree.md) (в том числе [реплицированных](../operations/table_engines/replication.md)). Существуют следующие виды
......@@ -203,15 +205,6 @@ ALTER TABLE [db.]table FREEZE PARTITION 'name'
Таким образом, данные из бэкапа будут добавлены в таблицу.
Восстановление из бэкапа, так же, не требует остановки сервера.
### Бэкапы и репликация
Репликация защищает от аппаратных сбоев. В случае, если на одной из реплик у вас исчезли все данные, то восстановление делается по инструкции в разделе "Восстановление после сбоя".
Для защиты от аппаратных сбоев, обязательно используйте репликацию. Подробнее про репликацию написано в разделе "Репликация данных".
Бэкапы защищают от человеческих ошибок (случайно удалили данные, удалили не те данные или не на том кластере, испортили данные).
Для баз данных большого объёма, бывает затруднительно копировать бэкапы на удалённые серверы. В этих случаях, для защиты от человеческой ошибки, можно держать бэкап на том же сервере (он будет лежать в `/var/lib/clickhouse/shadow/`).
``` sql
ALTER TABLE [db.]table FETCH PARTITION 'name' FROM 'path-in-zookeeper'
```
......
......@@ -151,6 +151,7 @@ nav:
- 'Kafka': 'operations/table_engines/kafka.md'
- 'MySQL': 'operations/table_engines/mysql.md'
- 'Access Rights': 'operations/access_rights.md'
- 'Data Backup': 'operations/backup.md'
- 'Configuration Files': 'operations/configuration_files.md'
- 'Quotas': 'operations/quotas.md'
- 'System Tables': 'operations/system_tables.md'
......
......@@ -150,6 +150,7 @@ nav:
- 'Kafka': 'operations/table_engines/kafka.md'
- 'MySQL': 'operations/table_engines/mysql.md'
- 'Access rights': 'operations/access_rights.md'
- 'Data Backup': 'operations/backup.md'
- 'Configuration files': 'operations/configuration_files.md'
- 'Quotas': 'operations/quotas.md'
- 'System tables': 'operations/system_tables.md'
......
......@@ -151,6 +151,7 @@ nav:
- 'Kafka': 'operations/table_engines/kafka.md'
- 'MySQL': 'operations/table_engines/mysql.md'
- 'Права доступа': 'operations/access_rights.md'
- 'Резервное копирование': 'operations/backup.md'
- 'Конфигурационные файлы': 'operations/configuration_files.md'
- 'Квоты': 'operations/quotas.md'
- 'Системные таблицы': 'operations/system_tables.md'
......
......@@ -151,6 +151,7 @@ nav:
- 'Kafka': 'operations/table_engines/kafka.md'
- 'MySQL': 'operations/table_engines/mysql.md'
- 'Access rights': 'operations/access_rights.md'
- 'Data backup': 'operations/backup.md'
- 'Configuration files': 'operations/configuration_files.md'
- 'Quotas': 'operations/quotas.md'
- 'System tables': 'operations/system_tables.md'
......
../../en/operations/backup.md
\ No newline at end of file
......@@ -8,6 +8,9 @@
- [ProxySQL](https://github.com/sysown/proxysql/wiki/ClickHouse-Support)
- [PostgreSQL](https://www.postgresql.org)
- [infi.clickhouse_fdw](https://github.com/Infinidat/infi.clickhouse_fdw) (使用 [infi.clickhouse_orm](https://github.com/Infinidat/infi.clickhouse_orm))
- 对象存储
- S3
- [clickhouse-backup](https://github.com/AlexAkulov/clickhouse-backup)
- Python
- [SQLAlchemy](https://www.sqlalchemy.org)
- [sqlalchemy-clickhouse](https://github.com/cloudflare/sqlalchemy-clickhouse) (使用 [infi.clickhouse_orm](https://github.com/Infinidat/infi.clickhouse_orm))
......
../../en/operations/backup.md
\ No newline at end of file
......@@ -983,4 +983,4 @@ SELECT uniq(UserID) FROM local_table WHERE CounterID = 101500 AND UserID GLOBAL
在所有的其他情况下,我们不建议使用星号,因为它是列式数据库的缺点而不是优点。
[来源文章](https://clickhouse.yandex/docs/en/query_language/select/) <!--hide-->
[来源文章](https://clickhouse.yandex/docs/zh/query_language/select/) <!--hide-->
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册