将所有气流连接导出到新环境 [英] Export all airflow connections to new environment

查看:63
本文介绍了将所有气流连接导出到新环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将所有现有的气流连接迁移到新的气流。

I'm trying to migrate all the existing airflow connections to a new airflow.

我在查看cli选项气流连接--help ,它提供了一个列出选项,但没有

I was looking at the cli options airflow connections --help, it gives an option to list but doesn't give an option to export/import to/from json format.

是否可以通过cli / airflow ui跨多种气流迁移连接?

Is there a way via cli/airflow ui to migrate connections across multiple airflows?

推荐答案

您可以直接连接到Airflow元数据库并转储那些连接,然后将它们加载到单独的数据库中。
但是,如果要自动化这样的操作,可以先将它们转储到CSV文件中:

You can either connect directly to the Airflow meta db and dump those connections, then load them in a separate database. However, if you want to automate something like this, you can get started by dumping them in a CSV file:

from airflow.utils import db
from airflow.models import Connection
import csv

outfile = open('myconnections.csv', 'w')
outcsv = csv.writer(outfile)

with db.create_session() as session:
    connections = session.query(Connection).all()

conn_list = [
    [getattr(c, column.name) for column in Connection.__mapper__.columns]
    for c in connections
]
outcsv.writerows(conn_list)
outfile.close()

之后,您可以将其加载到

After that, you can load that to a new DB manually or with a similar script.

重要:如果启用了加密,则为这些连接存储的密码将被加密,并且当您将它们加载到新数据库时,必须使用相同的Fernet密钥,否则您将不会成为可以解密它们。

IMPORTANT: if you have enabled encryption, the passwords stored for these connections will be encrypted, and when you load them to the new DB, you must use the identical fernet key, or otherwise you won't be able to decrypt them.

这篇关于将所有气流连接导出到新环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆