Skip to content

Commit d2cd9b8

Browse files
Lorchrliuhui
Lorchr
authored and
liuhui
committed
update
1 parent 8875f44 commit d2cd9b8

6 files changed

+638
-3
lines changed

docs/zh-cn/devenv/Docker-InfluxDB.md

+125
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,128 @@ show field keys from cpu
104104
5. 双击打开`influx.exe`文件, 输入 `SHOW DATABASES`,如果报错说明身份认证功能已打开
105105
6. 创建admin管理员用户`CREATE USER influxdb WITH PASSWORD 'influxdb' WITH ALL PRIVILEGES`
106106
7. 验证账户是否创建成功,输入`auth`后按回车,根据提示输入用户名和密码。登录后输入`SHOW DATABASES`,如有输出数据库名称即为安装成功
107+
108+
## 3. 备份和还原
109+
为了防止因为操作错误或机器故障导致数据丢失,InfluxDB企业版提供了两个工具集:备份和还原
110+
备份工具集;导出和导入数据工具集。这两个工具集都可以用于数据备份和还原,但侧重点又有所不
111+
同。
112+
- 备份和还原备份工具集:适用于大多数场景,是通用型工具。
113+
- 导出和导入数据工具集:针对海量数据集(100G以上)场景补充设计的备份工具。
114+
115+
上述两个工具集可用于以下场景:
116+
- 在意外故障导致数据损坏后进行灾难恢复。
117+
- 将数据迁移到新环境或新服务器。
118+
- 将集群还原到一致性状态。
119+
120+
备份和还原备份工具集支持以数据库、保留策略、分片3个维度选定要操作的数据,进行备份或
121+
还原备份操作,一般推荐使用备份和还原备份工具集。
122+
123+
> 注意:对于大型数据集(100G以上),推荐使用导出和导入数据工具集。
124+
Influx 企业级版本备份恢复官方文档:[Back up and restore | InfluxDB Enterprise 1.10
125+
Documentation](https://docs.influxdata.com/enterprise_influxdb/v1.10/administration/backup-and-restore/)
126+
127+
### 1. 备份
128+
备份是指创建存放在META节点上的元数据和DATA节点上的分片数据的副本,并将该副本存储在
129+
指定目录中。除了指定的数据副本,一个完整的备份还包括一个JSON格式的备份描述文件,描述具
130+
体的备份内容。所有备份文件的文件名包含一个UTC时间戳,表示创建备份的时间。
131+
132+
- META节点的元数据备份:20221108T034621Z.meta
133+
- DATA节点的分片数据备份:20221108T034621Z.<shard_id>.tar.gz
134+
- 备份描述文件:20221108T034621Z.manifest
135+
136+
备份可以是完整备份或增量备份,默认情况下,生成的备份是增量备份。增量备份会创建自上次
137+
增量备份以来已更改的元数据和分片数据的副本。如果当前目录下不存在增量备份,系统将自动做完
138+
整备份。
139+
140+
> 注意:因为还原完整备份的命令与还原增量备份的命令不同,为防止还原备份时出错,建议将完
141+
整备份和增量备份放置在不同的目录中。
142+
143+
参考官方文档连接:[Back up and restore data in InfluxDB v1.8 | InfluxDB OSS 1.8 Documentation](https://docs.influxdata.com/influxdb/v1.8/administration/backup_and_restore/#time-based-backups)
144+
145+
备份命令基本语法:
146+
147+
```shell
148+
influxd backup
149+
[ -database <db_name> ] # 指定需要备份的数据库名称,可选,若没有指定,将备份所有数据
150+
151+
[ -portable ] # 表示在线备份,必选
152+
[ -host <host:port> ] # influxdb服务所在的机器,默认为 127.0.0.1:8088
153+
[ -retention <rp_name> ] | [ -shard <shard_ID> -retention <rp_name> ] # 备份的保留策略,注意shard是挂在rp下的;我们需要备份的就是shard中的数据
154+
[ -start <timestamp> [ -end <timestamp> ] | -since <timestamp> ] # 备份指定时间段的数据
155+
<path-to-backup> # 备份文件的输出地址
156+
# 补充
157+
-host: fluxdb绑定地址(仅当从远程fluxdb主机创建备份时需要)
158+
-database/db:数据库名称(如果不指定数据库名称,则备份所有数据库)
159+
-rp:保留策略名称(如果不指定保留策略,则备份所有保留策略)
160+
-shard:分片ID(如果不指定分片ID,则备份所有分片)。需要保留策略。)
161+
-start:起始时间(如果不指定起始时间,则备份所有时间的数据。)
162+
-end/stop:停止时间(如果不指定停止时间,则备份到当前时间)。
163+
```
164+
165+
1. 备份所有的数据库
166+
[influxdb](https://so.csdn.net/so/search?q=influxdb&spm=1001.2101.3001.7020) 中的所有的数据库都备份到 /path/to/backup-directory 目录下:
167+
> influxd backup -portable /path/to/backup-directory
168+
2. 从远程InfluxDB实例备份所有数据
169+
> influxd backup -portable -host 203.0.113.0:8088 /path/to/backup-directory
170+
3. 备份指定数据库
171+
假设此时 influxdb 中有数据库 monitor,将数据库monitor中的所有数据完整备份到指定目录中:
172+
> influxd backup -portable -db monitor /path/to/backup-directory
173+
4. 备份特定的时间范围
174+
备份2022-01-01到2022-02-01内的数据:
175+
> influxd backup -portable -start 2022-01-01T00:00:00Z -stop 2022-02-01T00:00:00Z /path/to/backup-directory
176+
5. 备份指定时间到现在的数据
177+
> influxd backup -portable -start 2022-01-01T00:00:00Z /path/to/backup-directory
178+
6. 备份特定的保留策略
179+
> influxd backup -portable -db example-db -rp example-retention-policy /path/to/backupdirectory
180+
7. 备份特定的shard
181+
> influxd backup -portable -rp example-retention-policy -shard 123 /path/to/backup-directory
182+
183+
如何查看shard id 参考官方文档:[InfluxQuery Language (InfluxQL) reference | InfluxDB OSS 1.8
184+
Documentation](https://docs.influxdata.com/influxdb/v1.8/query_language/spec/#show-shards)
185+
186+
### 2. 恢复
187+
恢复命令基本语法:
188+
189+
```shell
190+
influxd restore [ -db <db_name> ] # 待恢复的数据库(备份中的数据库名)
191+
-portable | -online
192+
[ -host <host:port> ] # influxdb 的服务器
193+
[ -newdb <newdb_name> ] # 恢复到influxdb中的数据库名
194+
[ -rp <rp_name> ] # 备份中的保留策略
195+
[ -newrp <newrp_name> ] # 恢复的保留策略
196+
[ -shard <shard_ID> ]
197+
<path-to-backup-files>
198+
# 补充说明
199+
-host: fluxdb绑定地址(仅在将备份恢复到远程fluxdb主机时需要)
200+
-db:数据库名称(如果不指定数据库名称,则恢复所有数据库)
201+
-newdb:新的数据库名称(当恢复一个已经存在的数据库时需要)
202+
-rp:保留策略名称(如果不指定保留策略,则恢复所有保留策略)
203+
-newrp:新的保留策略名称(在恢复已经存在的保留策略时需要)
204+
-shard:分片ID(如果不指定分片ID,则备份所有分片)。需要保留策略。)
205+
```
206+
207+
1. 恢复所有数据库
208+
> influxd restore -portable /path/to/backup-directory
209+
2. 将所有数据恢复到远程InfluxDB实例
210+
> influxd restore -portable -host 203.0.113.0:8088 /path/to/backup-directory
211+
3. 恢复一个特定的数据库
212+
> influxd restore -portable -db example-db /path/to/backup-directory
213+
4. 从已经存在的数据库中恢复数据
214+
如果想将备份恢复到一个已经存在的database中时,并不是那么简单的,这里采用的一个策略是
215+
先备份到一个临时的db中,然后将临时DB中的数据写入已存在的db中。
216+
```shell
217+
#1. 将备份恢复到临时数据库example-tmp-db中
218+
influxd restore -portable -db example-db -newdb example-tmp-db /path/to/backup-direct
219+
ory
220+
#2. 登录连接influx客户端,从临时数据库查询数据,并将其写回现有数据库test中
221+
SELECT * INTO "test".autogen.:MEASUREMENT FROM "example-tmp-db".autogen./.*/ GROUP BY
222+
*
223+
#3. 删除临时数据库example-tmp-db
224+
DROP DATABASE "example-tmp-db"
225+
```
226+
5. 恢复指定的保留策略
227+
> influxd backup -portable -db example-db -rp example-retention-policy /path/to/backupdirectory
228+
6. 从已经存在的保留策略中恢复数据
229+
> influxd restore -portable -db example-db -rp example-rp -newrp example-new-rp /path/to/backup-directory
230+
7. 恢复指定的分片
231+
> influxd backup -portable -db example-db -rp example-rp -shard 123 /path/to/backup-directory

docs/zh-cn/devenv/Docker-Pgsql.md

+63-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,66 @@ docker container restart postgres
1616
```
1717

1818
- Account
19-
- postgres/postgres
19+
- postgres/postgres
20+
21+
## 2. Pgsql备份还原
22+
### 一、Windows下备份和恢复
23+
24+
1. 备份命令
25+
```shell
26+
pg_dump -h 164.82.233.54 -U postgres test > D:\postgres.bak
27+
28+
1. pg_dump 是备份数据库指令;
29+
2. 164.82.233.54 是数据库的 ip 地址;
30+
3. postgres 是数据库的用户名;
31+
4. test 是数据库名;
32+
5. > 意思是导出到指定目录;
33+
```
34+
35+
2. 恢复命令
36+
```shell
37+
psql -h localhost -U postgres -d test < D:\postgres.bak
38+
39+
1. psql 是恢复数据库指令;
40+
2. localhost 是要恢复的数据库的 ip 地址;
41+
3. postgres 是数据库的用户名;
42+
4. test 是数据库名;
43+
5. < 意思是导出到指定目录;
44+
```
45+
46+
### 二、Linux 下备份和恢复
47+
48+
1. 备份
49+
```shell
50+
/opt/PostgreSQL/9.5/bin/pg_dump -h 164.82.233.54 -U postgres databasename > databasename.bak
51+
```
52+
53+
2. 恢复
54+
```shell
55+
/opt/PostgreSQL/9.5/bin/psql -h localhost -U postgres -d databasename < databasename.bak
56+
```
57+
58+
### SQL方式备份和恢复
59+
60+
> 这里我们用到的工具是 `pg_dump``pg_dumpall`
61+
> 这种方式可以在数据库正在使用的时候进行完整一致的备份,并不阻塞其它用户对数据库的访问。
62+
> 它会产生一个脚本文件,里面包含备份开始时,已创建的各种数据库对象的 SQL 语句和每个表中的数据。
63+
> 可以使用数据库提供的工具 `pg_dumpall``pg_dump` 来进行备份。
64+
> `pg_dump` 只备份数据库集群中的某个数据库的数据,它不会导出角色和表空间相关的信息,因为这些信息是整个数据库集群共用的,不属于某个单独的数据库。
65+
> `pg_dumpall`,对集簇中的每个数据库调用 pg_dump 来完成该工作,还会还转储对所有数据库公用的全局对象( pg_dump 不保存这些对象)。
66+
> 目前这包括适数据库用户和组、表空间以及适合所有数据库的访问权限等属性。
67+
68+
例如,在我的计算机上,可使用如下命令对名为 dbname 的数据库进行备份:
69+
```shell
70+
pg_dump –h 127.0.0.1 -p 5432 -U postgres -c -C –f dbname.sql dbname
71+
```
72+
73+
使用如下命令可对全部 pg 数据库进行备份:
74+
```shell
75+
pg_dumpall –h 127.0.0.1 –p 5432 -U postgres –c -C –f db_bak.sql
76+
```
77+
78+
恢复方式很简单。执行恢复命令即可:
79+
```shell
80+
psql –h 127.0.0.1 -p 5432 -U postgres –f db_bak.sql
81+
```

docs/zh-cn/devenv/Maven-Mvnd.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
# 查看版本
8787
mvn -v
8888
89-
# 打包安装到本地
90-
mvn clean package
89+
# 打包
90+
mvn clean -U -Dmaven.test.skip=true package
9191
9292
# 打包安装到本地
9393
mvn clean package -T 1C -Dmaven.test.skip=true -Dmaven.compile.fork=true
@@ -130,6 +130,10 @@
130130
# 查看版本
131131
mvnd -v
132132
133+
# 打包
134+
mvnd clean -U -Dmaven.test.skip=true package # 并行
135+
mvnd clean -U -Dmaven.test.skip=true package -T1 # 串行
136+
133137
# 打包安装到本地
134138
mvnd clean install -Dquickly
135139
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
## 使用`outflux` 导入`influxdb`的数据到`timescaledb`
2+
`influxdb` 以及 `timescaledb` 都是不错的时序数据库,`timescaledb` 团队提供了直接从 `influxdb` 导入
3+
4+
## 1. 环境准备
5+
`docker-compose` 文件
6+
```yaml
7+
version: "3"
8+
services:
9+
timescaledb:
10+
image: timescale/timescaledb-postgis:latest-pg10
11+
ports:
12+
- "5432:5432"
13+
environment:
14+
- "POSTGRES_PASSWORD=dalong"
15+
influxdb:
16+
image: influxdb
17+
ports:
18+
- "8086:8086"
19+
```
20+
21+
## 2. Influxdb 数据导入
22+
下载测试数据
23+
注意需要在容器中操作 `docker-compose exec influxdb sh`
24+
25+
```shell
26+
wget https://timescaledata.blob.core.windows.net/datasets/outflux_taxi.txt
27+
```
28+
29+
导入
30+
31+
```shell
32+
influx -import -path=./outflux_taxi.txt -database=outflux_tutorial
33+
```
34+
35+
## 3. Schema 迁移
36+
37+
```shell
38+
./outflux schema-transfer outflux_tutorial taxi --input-server=http://localhost:8086 --output-conn="dbname=postgres user=postgres password=dalong"
39+
```
40+
41+
效果
42+
43+
```shell
44+
2019/04/12 11:03:55 Selected input database: outflux_tutorial
45+
2019/04/12 11:03:55 Overriding PG environment variables for connection with: dbname=postgres user=postgres password=dalong
46+
2019/04/12 11:03:55 pipe_taxi starting execution
47+
2019/04/12 11:03:55 Discovering influx schema for measurement: taxi
48+
2019/04/12 11:03:55 Discovered: DataSet { Name: taxi, Columns: [Column { Name: time, DataType: IDRFTimestamp} Column { Name: location_id, DataType: IDRFString} Column { Name: rating, DataType: IDRFString} Column { Name: vendor, DataType: IDRFString} Column { Name: fare, DataType: IDRFDouble}Column { Name: mta_tax, DataType: IDRFDouble} Column { Name: tip, DataType: IDRFDouble} Column { Name: tolls, DataType: IDRFDouble}], Time Column: time }
49+
2019/04/12 11:03:55 Selected Schema Strategy: CreateIfMissing
50+
2019/04/12 11:03:55 existing hypertable 'taxi' is partitioned properly
51+
2019/04/12 11:03:55 No data transfer will occur
52+
2019/04/12 11:03:55 Schema Transfer complete in: 0.079 seconds
53+
```
54+
55+
## 4. 数据迁移
56+
57+
```shell
58+
./outflux migrate outflux_tutorial taxi --input-server=http://localhost:8086 --output-conn="dbname=postgres user=postgres password=dalong" --schema-strategy=DropAndCreate
59+
```
60+
61+
效果
62+
63+
```shell
64+
2019/04/12 11:04:33 All pipelines scheduled
65+
2019/04/12 11:04:33 Overriding PG environment variables for connection with: dbname=postgres user=postgres password=dalong
66+
2019/04/12 11:04:33 pipe_taxi starting execution
67+
2019/04/12 11:04:33 Discovering influx schema for measurement: taxi
68+
2019/04/12 11:04:33 Discovered: DataSet { Name: taxi, Columns: [Column { Name: time, DataType: IDRFTimestamp} Column { Name: location_id, DataType: IDRFString} Column { Name: rating, DataType: IDRFString} Column { Name: vendor, DataType: IDRFString} Column { Name: fare, DataType: IDRFDouble}Column { Name: mta_tax, DataType: IDRFDouble} Column { Name: tip, DataType: IDRFDouble} Column { Name: tolls, DataType: IDRFDouble}], Time Column: time }
69+
2019/04/12 11:04:33 Selected Schema Strategy: DropAndCreate
70+
2019/04/12 11:04:33 Table taxi exists, dropping it
71+
2019/04/12 11:04:33 Executing: DROP TABLE taxi
72+
2019/04/12 11:04:33 Table taxi ready to be created
73+
2019/04/12 11:04:33 Creating table with:
74+
CREATE TABLE "taxi"("time" TIMESTAMP, "location_id" TEXT, "rating" TEXT, "vendor" TEXT, "fare" FLOAT, "mta_tax" FLOAT, "tip" FLOAT, "tolls" FLOAT
75+
)
76+
2019/04/12 11:04:33 Preparing TimescaleDB extension:
77+
CREATE EXTENSION IF NOT EXISTS timescaledb
78+
2019/04/12 11:04:33 Creating hypertable with: SELECT create_hypertable('"taxi"', 'time');
79+
2019/04/12 11:04:33 Starting extractor 'pipe_taxi_ext' for measure: taxi
80+
2019/04/12 11:04:33 Starting data ingestor 'pipe_taxi_ing'
81+
2019/04/12 11:04:33 pipe_taxi_ext: Extracting data from database 'outflux_tutorial'
82+
2019/04/12 11:04:33 pipe_taxi_ext: SELECT "time", "location_id", "rating", "vendor", "fare", "mta_tax", "tip", "tolls"
83+
FROM "taxi"
84+
2019/04/12 11:04:33 pipe_taxi_ext:Pulling chunks with size 15000
85+
2019/04/12 11:04:33 Will batch insert 8000 rows at once. With commit strategy: CommitOnEachBatch
86+
2019/04/12 11:04:33 pipe_taxi_ext: Extracted 185 rows from Influx
87+
2019/04/12 11:04:33 pipe_taxi_ing: Complete. Inserted 185 rows.
88+
2019/04/12 11:04:33 All pipelines finished
89+
2019/04/12 11:04:33 Migration execution time: 0.094 seconds
90+
```
91+
92+
## 5. 参考资料
93+
- https://blog.51cto.com/rongfengliang/3124713
94+
- https://docs.timescale.com/v1.2/tutorials/outflux
95+
- https://docs.influxdata.com/influxdb/v1.7/introduction/getting-started/
96+
- https://blog.timescale.com/migrate-outflux-a-smart-way-out-of-influxdb/

0 commit comments

Comments
 (0)