Elasticdump导出Elastic索引到JSON遇密码双引号转义失败问题
Elasticdump导出Elasticsearch索引时的特殊字符密码问题解决
问题根源
- 密码中的未闭合双引号导致bash解析
--input参数时发生拆分,将@localhost:9200/employee误认为独立的文件路径,触发"No such file or directory"错误。 - 参数解析混乱后,elasticdump无法正确识别
--output参数,进而抛出"output是必填项"的错误。 - 原命令中
NODE_TLS_REJECT_UNAUTHORIZED=0末尾未加反斜杠,导致环境变量未传递给后续的elasticdump进程。
解决方法
方法1:用单引号包裹完整的input URL
bash中单引号内的内容会被原样解析,无需处理特殊字符转义:
NODE_TLS_REJECT_UNAUTHORIZED=0 \ elasticdump \ --input='https://elastic:4erw"x25{67@localhost:9200/employee' \ --output=./data/sample_file.json \ --type=data
方法2:双引号内转义特殊字符
若必须使用双引号,需用反斜杠转义密码中的双引号,同时用双引号包裹整个URL:
NODE_TLS_REJECT_UNAUTHORIZED=0 \ elasticdump \ --input="https://elastic:4erw\"x25{67@localhost:9200/employee" \ --output=./data/sample_file.json \ --type=data
方法3:合并为单行命令
避免换行符导致的参数拆分问题,直接写成单行:
NODE_TLS_REJECT_UNAUTHORIZED=0 elasticdump --input='https://elastic:4erw"x25{67@localhost:9200/employee' --output=./data/sample_file.json --type=data
额外注意
确保./data目录已存在,若不存在需先执行mkdir -p ./data创建目录,否则会出现写入失败的问题。
内容的提问来源于stack exchange,提问作者Madhu
相关产品推荐
相关产品推荐

