InfluxDB2.7.6 备份以及解决root token丢失导致cli无法备份数据的问题

今天项目需要将influxdb的数据导入一份到其他系统,总结一下我遇到的问题

influxdb导出导入参考官方文档:https://docs.influxdata.com/influxdb/v2/admin/backup-restore/backup/

本来导出导入是很简单的事情,但是因为第一次进入系统的token丢失,并且在管理后台界面还删除掉了,造成认证一直失败

在管理页面Load Data->API TOKENS->GENERATE API TOKEN,创建拥有全部权限的token,尝试使用该token进行导出
导出并指定bucket

influx.exe backup F:\influxDB\backup -t csuS6MIxxpx...vQg== --bucket example

结果提示未授权,但是创建的时候给的是全部权限

Error: failed to backup metadata: failed to download metadata snapshot: 401 Unauthorized: unauthorized access

琢磨了一会发现,在API文档中看到/api/v2/authorizations可以返回所有授权token信息,可以在游览器中先登录influxdb(也可以在文档中找到登录接口进行登录),然后在请求http://xxx:8086/api/v2/authorizations,即可查询到所有已授权token


{
    "links": {
        "self": "/api/v2/authorizations"
    },
    "authorizations": [             
        {
            "id": "0dda132dcf0d6000",
            "token": "csuS6MIxxpxuW0z7wWDc...vQg==",
             ...
            "permissions": [
                {
                    "action": "read",
                    "resource": {
                        "type": "annotations",
                        "orgID": "d008309eead47874",
                        "org": "yykj"
                    }
                }       
                 ... ... ...
                {
                    "action": "write",
                    "resource": {
                        "type": "replications"
                    }
                }
            ],
            ... ... ...
            "createdAt": "2024-04-29T17:40:22.6876761+08:00",
        }
    ]
}

通过对比permissions发现,权限不一样,新建的token权限与管理员token对比resource查看到新建的并不是管理员token,以下是某个action的对比

普通token
{
    "action": "write",
    "resource": {
        "type": "annotations",
        "orgID": "d008309eead47874",
        "org": "xxx"
    }
}
管理员token
{
    "action": "write",
    "resource": {
        "type": "buckets"
    }
}

我本来向安装文档里写的通过client命令行创建一个管理员用户,但是尝试后发现想要使用client就必须要有管理员token,那只能使用API接口创建了,我是通过postman来调用的接口所以要带上cookie,cookie可以登录influxdb后在控制台获取到,下面是完整创建过程及参数

POST
请求路径:
http://10.10.0.203:8086/api/v2/authorizations
完整请求参数:
{
    "status": "active",
    "description": "iot-center-device",
    "orgID": "d008309eead47874",
    "permissions": [
        {
            "action": "read",
            "resource": {
                "type": "authorizations"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "authorizations"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "buckets"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "buckets"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "dashboards"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "dashboards"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "orgs"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "orgs"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "sources"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "sources"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "tasks"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "tasks"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "telegrafs"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "telegrafs"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "users"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "users"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "variables"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "variables"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "scrapers"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "scrapers"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "secrets"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "secrets"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "labels"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "labels"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "views"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "views"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "documents"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "documents"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "notificationRules"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "notificationRules"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "notificationEndpoints"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "notificationEndpoints"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "checks"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "checks"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "dbrp"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "dbrp"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "notebooks"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "notebooks"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "annotations"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "annotations"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "remotes"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "remotes"
            }
        },
        {
            "action": "read",
            "resource": {
                "type": "replications"
            }
        },
        {
            "action": "write",
            "resource": {
                "type": "replications"
            }
        }
    ]
}

调用成功后接口会返回本次创建的token和描述,这个token就可以操作client了,在influxdb管理页面API TOKENS和接口/api/v2/authorizations中也都可以查看到该token

备份和恢复命令参考官方文档:https://docs.influxdata.com/influxdb/v2/admin/backup-restore/backup/

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,402评论 6 499
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,377评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,483评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,165评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,176评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,146评论 1 297
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,032评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,896评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,311评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,536评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,696评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,413评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,008评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,659评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,815评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,698评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,592评论 2 353

推荐阅读更多精彩内容