|
| 1 | +<!-- |
| 2 | +
|
| 3 | + Licensed to the Apache Software Foundation (ASF) under one |
| 4 | + or more contributor license agreements. See the NOTICE file |
| 5 | + distributed with this work for additional information |
| 6 | + regarding copyright ownership. The ASF licenses this file |
| 7 | + to you under the Apache License, Version 2.0 (the |
| 8 | + "License"); you may not use this file except in compliance |
| 9 | + with the License. You may obtain a copy of the License at |
| 10 | + |
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + |
| 13 | + Unless required by applicable law or agreed to in writing, |
| 14 | + software distributed under the License is distributed on an |
| 15 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | + KIND, either express or implied. See the License for the |
| 17 | + specific language governing permissions and limitations |
| 18 | + under the License. |
| 19 | +
|
| 20 | +--> |
| 21 | + |
| 22 | +# Backup Tool |
| 23 | + |
| 24 | +## 1. Overview |
| 25 | + |
| 26 | +The IoTDB Full Backup Tool is designed to create a full backup of a single IoTDB node’s data via hard links to a specified local directory. The backup can then be directly started and joined to the original cluster. The tool offers two modes: **Quick Mirror Mode** and **Manual Backup Path Mode**. |
| 27 | + |
| 28 | +> **Notes**: |
| 29 | +> |
| 30 | +> * **Stop the IoTDB service before starting the backup**. |
| 31 | +> * The script runs in the background by default, and logs are saved to log files during execution. |
| 32 | +
|
| 33 | + |
| 34 | +## 2. Backup Modes |
| 35 | + |
| 36 | +### 2.1 Mode 1: Quick Mirror Mode |
| 37 | + |
| 38 | +#### Usage |
| 39 | + |
| 40 | +```bash |
| 41 | +backup.sh/backup.bat -quick -node xxx |
| 42 | +# Optional values for xxx are shown in the following examples |
| 43 | + |
| 44 | +backup.sh/backup.bat -quick -node |
| 45 | +# Back up all nodes to the default path |
| 46 | + |
| 47 | +backup.sh/backup.bat -quick -node all |
| 48 | +# Back up all nodes to the default path |
| 49 | + |
| 50 | +backup.sh/backup.bat -quick -node confignode |
| 51 | +# Back up only the ConfigNode to the default path |
| 52 | + |
| 53 | +backup.sh/backup.bat -quick -node datanode |
| 54 | +# Back up only the DataNode to the default path |
| 55 | +``` |
| 56 | + |
| 57 | +#### Parameter Descriptions |
| 58 | + |
| 59 | +| **Parameter** | **Description** | **Required** | |
| 60 | +| ----------------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---------------------- | |
| 61 | +| `-quick` | Enables Quick Mirror Mode. | No | |
| 62 | +| `-node` | Specifies the node type to back up. Options: `all`, `datanode`, or `confignode`. Default: `all`. <br>`all`: Back up both DataNode and ConfigNode. <br>`datanode`: Back up only the DataNode. <br>`confignode`: Back up only the ConfigNode. | No | |
| 63 | + |
| 64 | +**Process Details**: |
| 65 | + |
| 66 | +1. Check if the `_backup` folder already exists in the current IoTDB directory or paths specified in the configuration file. If it exists, the tool exits with the error: `The backup folder already exists`. |
| 67 | +> When the backup folder already exists, you can try the following solutions: |
| 68 | +> * Delete the existing _backup folder and retry the backup. |
| 69 | +> * Modify the backup path to avoid conflicts. |
| 70 | +
|
| 71 | +2. Create hard links from the original `dn_data_dirs` paths to the corresponding `_backup` paths. |
| 72 | + * Example: If `dn_data_dirs=/data/iotdb/data/datanode/data`, the backup data will be stored in `/data/iotdb/data/datanode/data_backup`. |
| 73 | +3. Copy other files from the IoTDB directory (e.g., `/data/iotdb`) to the `_backup` path (e.g., `/data/iotdb_backup`). |
| 74 | + |
| 75 | + |
| 76 | +### 2.2 Mode 2: Manual Backup Path Mode |
| 77 | + |
| 78 | +#### Usage |
| 79 | + |
| 80 | +```bash |
| 81 | +backup.sh -node xxx -targetdir xxx -targetdatadir xxx -targetwaldir xxx |
| 82 | +``` |
| 83 | + |
| 84 | +#### Parameter Descriptions |
| 85 | + |
| 86 | +| **Parameter** | **Description** | **Required** | |
| 87 | +| ----------------------- | -------------------------------------------------------------------------------------------- | ---------------------- | |
| 88 | +| `-node` | Node type to back up (`all`, `datanode`, or `confignode`). Default: `all`. | No | |
| 89 | +| `-targetdir` | Target directory for backing up the IoTDB folder. | **Yes** | |
| 90 | +| `-targetdatadir` | Target path for `dn_data_dirs` files. Default: `targetdir/data/datanode/data`. | No | |
| 91 | +| `-targetwaldir` | Target path for `dn_wal_dirs` files. Default: `targetdir/data/datanode/wal`. | No | |
| 92 | + |
| 93 | +**Process Details**: |
| 94 | + |
| 95 | +1. The `-targetdir` parameter is mandatory. If missing, the tool exits with the error: `-targetdir cannot be empty. The backup folder must be specified`. |
| 96 | +2. Validate consistency between configuration paths (`dn_data_dirs`, `dn_wal_dirs`) and parameters (`-targetdatadir`, `-targetwaldir`): |
| 97 | + |
| 98 | + * If `-targetdatadir` or `-targetwaldir` is a single path, it is considered consistent. |
| 99 | + * If the number of source paths (from configuration) does not match the target paths, the tool exits with the error: `-targetdatadir parameter exception: the number of original paths does not match the specified paths`. |
| 100 | +3. Check if `-targetdatadir` paths are on the same disk as the original paths: |
| 101 | + |
| 102 | + * **Same disk**: Attempt to create hard links. If hard links fail, copy files instead. |
| 103 | + * **Different disk**: Copy files directly. |
| 104 | +4. Path Matching Rules |
| 105 | + |
| 106 | +* **Many-to-One**: Multiple source paths can be backed up to a single target path. |
| 107 | +* **One-to-One**: A single source path can be backed up to a single target path. |
| 108 | +* **Many-to-Many**: Multiple source paths can be backed up to multiple target paths, but the pattern must match. |
| 109 | + |
| 110 | +#### Examples |
| 111 | + |
| 112 | +| **Configuration Paths** | **`-targetdatadir` Paths** | **Result** | |
| 113 | +| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | |
| 114 | +| `/data/iotdb/data/datanode/data` | `/data/iotdb_backup/data/datanode/data` |**Consistent** | |
| 115 | +| `/data/iotdb/data/datanode/data` | `/data/iotdb_backup/data/datanode/data1,/data/iotdb_backup/data/datanode/data2` | **Inconsistent** | |
| 116 | +| `/data/iotdb/data/datanode/data1,/data/iotdb/data/datanode/data2` | `/data/iotdb_backup/data/datanode/data` | **Consistent** | |
| 117 | +| `/data/iotdb/data/datanode/data1,/data/iotdb/data/datanode/data2` | `/data/iotdb_backup/data/datanode/data3,/data/iotdb_backup/data/datanode/data4` | **Consistent** | |
| 118 | +| `/data/iotdb/data/datanode/data1,/data/iotdb/data/datanode/data2;/data/iotdb/data/datanode/data3` | `/data/iotdb_backup/data/datanode/data` | **Consistent** | |
| 119 | +| `/data/iotdb/data/datanode/data1,/data/iotdb/data/datanode/data2;/data/iotdb/data/datanode/data3` | `/data/iotdb_backup/data/datanode/data1;/data/iotdb_backup/data/datanode/data1` | **Consistent** | |
| 120 | +| `/data/iotdb/data/datanode/data1,/data/iotdb/data/datanode/data2;/data/iotdb/data/datanode/data3` | `/data/iotdb_backup/data/datanode/data1,/data/iotdb_backup/data/datanode/data3;/data/iotdb_backup/data/datanode/data` | **Consistent** | |
| 121 | +| `/data/iotdb/data/datanode/data1,/data/iotdb/data/datanode/data2;/data/iotdb/data/datanode/data3` | `/data/iotdb_backup/data/datanode/data1,/data/iotdb_backup/data/datanode/data3;/data/iotdb_backup/data/datanode/data1,/data/iotdb_backup/data/datanode/data4` | **Inconsistent** | |
| 122 | + |
| 123 | +#### Path Matching Rules Summary |
| 124 | + |
| 125 | +* **Paths separated by `;` only**: |
| 126 | + * `-targetdatadir` can be a single path (no `;` or `,`). |
| 127 | + * `-targetdatadir` can also use `;` to split paths, but the count must match the source paths. |
| 128 | +* **Paths separated by `,` only**: |
| 129 | + * `-targetdatadir` can be a single path (no `;` or `,`). |
| 130 | + * `-targetdatadir` can also use `,` to split paths, but the count must match the source paths. |
| 131 | +* **Paths with both `;` and `,`**: |
| 132 | + * `-targetdatadir` can be a single path (no `;` or `,`). |
| 133 | + * Split paths first by `;`, then by `,`. The number of paths at each level must match. |
| 134 | + |
| 135 | +> **Note**: The `dn_wal_dirs` parameter (for WAL paths) follows the same rules as `dn_data_dirs`. |
0 commit comments