Data Backup and Recovery for InfluxDB2

Data Backup and Recovery in InfluxDB2

This operation is for InfluxDB version v2.7.0. The methods and commands differ from versions 1.x and 2.0, so please verify the version before proceeding.

1. Install the influx CLI

Official Website: Install the influx CLI

# Download the installation package, choose one of the following commands based on your CPU
# amd64
wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.3-linux-amd64.tar.gz
# arm
wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.3-linux-arm64.tar.gz

# Extract the installation package, choose one of the following commands based on your CPU
# amd64
tar xvzf path/to/influxdb2-client-2.7.3-linux-amd64.tar.gz
# arm
tar xvzf path/to/influxdb2-client-2.7.3-linux-arm64.tar.gz

# Place the unpacked influx executable in the system directory, choose one of the following commands based on your CPU
# amd64
sudo cp influxdb2-client-2.7.3-linux-amd64/influx /usr/local/bin/
# arm
sudo cp influxdb2-client-2.7.3-linux-arm64/influx /usr/local/bin/

Actual operation results

baroot@hcss-ecs-a9d1:/usr/local/src/influx_back# wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.3-linux-amd64.tar.gz
--2023-10-12 09:38:32--  https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.3-linux-amd64.tar.gz
Resolving dl.influxdata.com (dl.influxdata.com)... 18.244.214.54, 18.244.214.38, 18.244.214.89, ...
Connecting to dl.influxdata.com (dl.influxdata.com)|18.244.214.54|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11454321 (11M) [application/x-tar]
Saving to: ‘influxdb2-client-2.7.3-linux-amd64.tar.gz’

influxdb2-client-2.7.3-linux-amd64.tar.gz                          100%[================================================================================================================================================================>]  10.92M  2.39MB/s    in 4.6s    

2023-10-12 09:38:37 (2.39 MB/s) - ‘influxdb2-client-2.7.3-linux-amd64.tar.gz’ saved [11454321/11454321]
root@hcss-ecs-a9d1:/usr/local/src/influx_back# ls
influxdb2-client-2.7.3-linux-amd64.tar.gz
# Extract the file based on the actual file storage path
root@hcss-ecs-a9d1:/usr/local/src/influx_back# tar xvzf influxdb2-client-2.7.3-linux-amd64.tar.gz 
./
./LICENSE
./README.md
./influx
root@hcss-ecs-a9d1:/usr/local/src/influx_back# ls
influx  influxdb2-client-2.7.3-linux-amd64.tar.gz  LICENSE  README.md
root@hcss-ecs-a9d1:/usr/local/src/influx_back# cd influx
bash: cd: influx: Not a directory
root@hcss-ecs-a9d1:/usr/local/src/influx_back# ll
total 35856
drwx------ 2 root root     4096 Apr 28 22:25 ./
drwxr-xr-x 3 root root     4096 Oct 11 16:28 ../
-rwxr-xr-x 1 root root 25240165 Apr 28 22:25 influx*
-rw-r--r-- 1 root root 11454321 Apr 28 22:27 influxdb2-client-2.7.3-linux-amd64.tar.gz
-rw-r--r-- 1 root root     1067 Apr 28 22:25 LICENSE
-rw-r--r-- 1 root root     2196 Apr 28 22:25 README.md
root@hcss-ecs-a9d1:/usr/local/src/influx_back# sudo cp influx /usr/local/bin
# Note here, if adding the executable file to the system still prompts that it cannot be executed, add it to the system's executable file directory as prompted
root@hcss-ecs-a9d1:/usr/local/src/influx_back# influx
bash: /usr/bin/influx: No such file or directory
root@hcss-ecs-a9d1:/usr/local/src/influx_back# sudo cp influx /usr/bin

2. Backup the Database

Official Website: Backup Data in InfluxDB | InfluxDB OSS v2 Documentation (influxdata.com)

Backup command:

# influx backup [backup path] -t [database token]
influx backup /usr/local/src/influx_backup -t Y9bgC1gdlPZsCjE_o7N9bXZRBl2VAXy8pr0CRXiz7wCSZ1y70Crv27AIU3kAee402Y_VlSctWEvN_e1xeR3hw==

Actual operation results

# Need to add token, otherwise a 401 error will occur. The token is generated when creating an account
root@hcss-ecs-a9d1:/usr/local/src/influx_backup# influx backup /usr/local/src/influx_backup
2023/10/12 10:02:55 INFO: Downloading metadata snapshot
Error: failed to backup metadata: failed to download metadata snapshot: 401 Unauthorized: unauthorized access
root@hcss-ecs-a9d1:/usr/local/src/influx_backup# influx backup /usr/local/src/influx_backup -t Y9bgC1gdlPZsCjE_o7N9bXZRBl2VAXy8pr0CRXiz7wCSZ1y70Crv27AIU3kAee402Y_VlSctWEvN_e1xeR3hw==
2023/10/12 10:03:50 INFO: Downloading metadata snapshot
2023/10/12 10:03:50 INFO: Backing up TSM for shard 1
2023/10/12 10:04:17 INFO: Backing up TSM for shard 2
2023/10/12 10:05:19 INFO: Backing up TSM for shard 3
root@hcss-ecs-a9d1:/usr/local/src/influx_backup# ls
20231012T020350Z.1.tar.gz  20231012T020350Z.2.tar.gz  20231012T020350Z.3.tar.gz  20231012T020350Z.bolt.gz  20231012T020350Z.manifest  20231012T020350Z.sqlite.gz

3. Data Recovery

Official Website: Restore Data in InfluxDB | InfluxDB OSS v2 Documentation (influxdata.com)

influx restore /usr/local/src/influx_backup/
root@VM-4-13-ubuntu:/usr/local/src/influx# influx restore /usr/local/src/influx_backup/
# Because the system port was changed, an error occurs when connecting, so the influx configuration needs to be changed
Error: API compatibility check failed: Get "http://localhost:8086/health": dial tcp 127.0.0.1:8086: connect: connection refused
root@VM-4-13-ubuntu:/usr/local/src/influx# influx config create \
>   -n config-name \
>   -u http://localhost:8090 \
>   -p account:password \
>   -o organization
Active  Name            URL                     Org
        config-name     http://localhost:8090   whut
# After changing the configuration, re-execute the recovery. Some data may still not be queried
root@VM-4-13-ubuntu:/usr/local/src/influx# influx restore /usr/local/src/influx_backup/
2023/10/12 11:12:15 INFO: Restoring bucket "9abe804d24024bba" as "zncb"
2023/10/12 11:12:15 INFO: Restoring TSM snapshot for shard 1
2023/10/12 11:12:19 INFO: Restoring TSM snapshot for shard 2
2023/10/12 11:12:29 INFO: Restoring TSM snapshot for shard 3
# Use the command to perform a global recovery again
root@VM-4-13-ubuntu:/usr/local/src/influx# influx restore /usr/local/src/influx_backup/ --full
2023/10/12 11:16:36 INFO: Restoring KV snapshot
2023/10/12 11:16:40 WARN: Restoring KV snapshot overwrote the operator token, ensure following commands use the correct token
2023/10/12 11:16:40 INFO: Restoring SQL snapshot
2023/10/12 11:16:40 INFO: Restoring TSM snapshot for shard 1
2023/10/12 11:16:44 INFO: Restoring TSM snapshot for shard 2
2023/10/12 11:16:54 INFO: Restoring TSM snapshot for shard 3

By Tim

Leave a Reply

Your email address will not be published. Required fields are marked *