不积跬步,无以至千里;不积小流,无以成江海。

elasticdump 备份数据认证密码有特殊字符

网站建设 康康 1179℃ 0评论

elasticsearch-dump 是一款很好用的es数据备份、迁移工具。官方地址为:https://github.com/elasticsearch-dump/elasticsearch-dump

在通过命令备份数据时,如果http认证密码包含特殊字符可能会导致url解析异常:

基本的用法为:

elasticdump --input=http://username:passowrd@localhost:9200/my_index --output=http://username:password@localhost:9200/my_index --type=data

这里如果密码包含 '#' 会解析异常:

elasticdump --input=/root/esdump/index_bak.json --output=http://elastic:xxx#9527@10.172.135.126:9200/newindex --type=mapping

可以看到这里把elastic解析成了要导出的es域名地址,实际我们的地址是10.172.xxx:

Tue, 08 Nov 2022 04:33:29 GMT | starting dump
Tue, 08 Nov 2022 04:33:29 GMT | got 1 objects from source file (offset: 0)
Tue, 08 Nov 2022 04:34:49 GMT | Error Emitted => getaddrinfo ENOTFOUND elastic elastic:80
Tue, 08 Nov 2022 04:34:49 GMT | Error Emitted => getaddrinfo ENOTFOUND elastic elastic:80

尝试了一些其他写法均不能解决:

以下写法也不能解决:

elasticdump --input=/root/esdump/index_bak.json --output=http://'elastic:xxx#9527'@10.172.135.126:9200/newindex --type=mapping
elasticdump --input=/root/esdump/index_bak.json --output="http://elastic:"xxx#9527"@10.172.135.126:9200/newindex" --type=mapping
elasticdump --input=/root/esdump/index_bak.json --output=http://elastic:"xxx#9527"@10.172.135.126:9200/newindex --type=mapping
elasticdump --input=/root/esdump/index_bak.json --output=http://"elastic:xxx#9527"@10.172.135.126:9200/newindex --type=mapping

通过 elasticdump --help 查看帮助发现可通过 --httpAuthFile参数指定认证文件:

编辑认证文件 auth.ini 写入内容:

!!注意这里password内容必须用"",不然也会解析异常

user=elastic
password="xxx#9527"

执行命令:

通过--httpAuthFile参数指定认证文件,成功解决:

elasticdump --input=/root/esdump/index_bak.json --output=http://10.172.135.126:9200/newindex --httpAuthFile=/root/esdump/auth.ini --type=mapping

转载请注明:左手代码右手诗 » elasticdump 备份数据认证密码有特殊字符

喜欢 (31)or分享 (0)
发表我的评论
取消评论

 

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址