redash_toolbelt/examples/migrate.py
def main(command):
    """Redash migration tool. Can be used to migrate objects (users, queries, visualizations, dashboards, alerts, and favorites)
    from one Redash instance to another.

    Commands:

      \b
      init                  Create a meta.json template file in your working directory. You will be
                            prompted to enter authentication information for your origin and desti-
                            nation instances.

      \b
      data-sources          Create stubs of your origin data sources in your destination instance

      \b
      check-data-sources    Compare the data sources in your origin and destination instances

      \b
      users                 Duplicate user names, emails, and enabled/disabled status from the
                            origin instance into the destination instance.

      \b
      groups                Duplicate group names, member lists, and data source permissions from
                            the origin instance into the destination instance.

      \b
      queries               Duplicate queries from the origin instance to the destination instance.
                            Skips queries with an unknown destination data source or user.

      \b
      visualizations        Duplicate visualizations from the origin instance to the destination
                            instance. Only duplicates visualizations for queries moved by the
                            `queries` command.

      \b
      dashboards            Duplicate dashboards from the origin instance to the destination
                            instance. Skips any dashboard widget whose visualization was not moved
                            using the `visualizations` command.

      \b
      destinations          Create stubs of your origin alert destinations in your destination
                            instance

      \b
      alerts                Duplicate alert definitions from the origin instance to the destination
                            instance. Skips alerts that point to queries that were not migrated by
                            the `queries` command. Run the `destinations` command first.

      \b
      favorites             Duplicate favorite flags on queries and dashboards from the origin
                            instance to the destination instance.

      \b
      disable-users         Disable users in the destination instance that are disabled in the
                            origin instance.

      \b
      fix-qrds-refs         Replace references to origin query id's in query results data source
                            (QRDS) queries with their new id at the destination. Does nothing if
                            the destination has no QRDS sources.

      \b
      fix-csv-queries       Reformat queries against app.redash.io's csvurl data source so they are
                            compatible with OSS Redash's csv data source. Do not use this command if
                            you did not migrate from app.redash.io.

      \b
      Commands should be called in the order specified here. Check meta.json between steps to
      confirm expected behavior.
    """

    try:
        make_global_meta()
    except Exception as e:
        if command == "init":
            pass
        else:
            print(
                f"Script could not proceed because of a problem reading meta.json: {e}"
            )
            print("Please run redash-migrate init before proceeding")
            return

    if command == "init":
        return init()

    from_client = Redash(ORIGIN, ORIGIN_API_KEY)
    to_client = Redash(DESTINATION, DESTINATION_API_KEY)

    command_map = {
        "data-sources": import_data_sources,
        "check-data-sources": check_data_sources,
        "users": import_users,
        "groups": import_groups,
        "destinations": import_destinations,
        "queries": import_queries,
        "fix-qrds-refs": fix_qrds_refs,
        "fix-csv-queries": fix_csv_queries,
        "visualizations": import_visualizations,
        "dashboards": import_dashboards,
        "alerts": import_alerts,
        "favorites": import_favorites,
        "disable-users": disable_users,
    }

    _command = command_map.get(command)
    if _command is None:
        print(f"{command} is not a valid command. See --help for instructions")
        return

    wrapped = save_meta_wrapper(command_map.get(command))

    if wrapped is None:
        print("No command provided. See --help for instructions")

    return wrapped(from_client, to_client)
Redash migration tool. Can be used to migrate objects (users, queries, visualizations, dashboards, alerts, and favorites)
    from one Redash instance to another.

    Commands:

      \b
      init                  Create a meta.json template file in your working directory. You will be
                            prompted to enter authentication information for your origin and desti-
                            nation instances.

      \b
      data-sources          Create stubs of your origin data sources in your destination instance

      \b
      check-data-sources    Compare the data sources in your origin and destination instances

      \b
      users                 Duplicate user names, emails, and enabled/disabled status from the
                            origin instance into the destination instance.

      \b
      groups                Duplicate group names, member lists, and data source permissions from
                            the origin instance into the destination instance.

      \b
      queries               Duplicate queries from the origin instance to the destination instance.
                            Skips queries with an unknown destination data source or user.

      \b
      visualizations        Duplicate visualizations from the origin instance to the destination
                            instance. Only duplicates visualizations for queries moved by the
                            `queries` command.

      \b
      dashboards            Duplicate dashboards from the origin instance to the destination
                            instance. Skips any dashboard widget whose visualization was not moved
                            using the `visualizations` command.

      \b
      destinations          Create stubs of your origin alert destinations in your destination
                            instance

      \b
      alerts                Duplicate alert definitions from the origin instance to the destination
                            instance. Skips alerts that point to queries that were not migrated by
                            the `queries` command. Run the `destinations` command first.

      \b
      favorites             Duplicate favorite flags on queries and dashboards from the origin
                            instance to the destination instance.

      \b
      disable-users         Disable users in the destination instance that are disabled in the
                            origin instance.

      \b
      fix-qrds-refs         Replace references to origin query id's in query results data source
                            (QRDS) queries with their new id at the destination. Does nothing if
                            the destination has no QRDS sources.

      \b
      fix-csv-queries       Reformat queries against app.redash.io's csvurl data source so they are
                            compatible with OSS Redash's csv data source. Do not use this command if
                            you did not migrate from app.redash.io.

      \b
      Commands should be called in the order specified here. Check meta.json between steps to
      confirm expected behavior.
    
Redash migration tool. Can be used to migrate objects (users, queries, visualizations, dashboards, alerts, and favorites)
from one Redash instance to another.



\b
init                  Create a meta.json template file in your working directory. You will be
prompted to enter authentication information for your origin and desti
nation instances.

\b
data-sources          Create stubs of your origin data sources in your destination instance

\b
check-data-sources    Compare the data sources in your origin and destination instances

\b
users                 Duplicate user names, emails, and enabled/disabled status from the
origin instance into the destination instance.

\b
groups                Duplicate group names, member lists, and data source permissions from
the origin instance into the destination instance.

\b
queries               Duplicate queries from the origin instance to the destination instance.
Skips queries with an unknown destination data source or user.

\b
visualizations        Duplicate visualizations from the origin instance to the destination
instance. Only duplicates visualizations for queries moved by the
`queries` command.

\b
dashboards            Duplicate dashboards from the origin instance to the destination
instance. Skips any dashboard widget whose visualization was not moved
using the `visualizations` command.

\b
destinations          Create stubs of your origin alert destinations in your destination
instance

\b
alerts                Duplicate alert definitions from the origin instance to the destination
instance. Skips alerts that point to queries that were not migrated by
the `queries` command. Run the `destinations` command first.

\b
favorites             Duplicate favorite flags on queries and dashboards from the origin
instance to the destination instance.

\b
disable-users         Disable users in the destination instance that are disabled in the
origin instance.

\b
fix-qrds-refs         Replace references to origin query id's in query results data source
(QRDS) queries with their new id at the destination. Does nothing if
the destination has no QRDS sources.

\b
fix-csv-queries       Reformat queries against app.redash.io's csvurl data source so they are
compatible with OSS Redash's csv data source. Do not use this command if
you did not migrate from app.redash.io.

\b
Commands should be called in the order specified here. Check meta.json between steps to
confirm expected behavior.
Redash migration tool . Can be used to migrate objects ( users queries visualizations dashboards alerts and favorites ) from one Redash instance to another . \ b init Create a meta . json template file in your working directory . You will be prompted to enter authentication information for your origin and desti nation instances . \ b data - sources Create stubs of your origin data sources in your destination instance \ b check - data - sources Compare the data sources in your origin and destination instances \ b users Duplicate user names emails and enabled / disabled status from the origin instance into the destination instance . \ b groups Duplicate group names member lists and data source permissions from the origin instance into the destination instance . \ b queries Duplicate queries from the origin instance to the destination instance . Skips queries with an unknown destination data source or user . \ b visualizations Duplicate visualizations from the origin instance to the destination instance . Only duplicates visualizations for queries moved by the ` queries ` command . \ b dashboards Duplicate dashboards from the origin instance to the destination instance . Skips any dashboard widget whose visualization was not moved using the ` visualizations ` command . \ b destinations Create stubs of your origin alert destinations in your destination instance \ b alerts Duplicate alert definitions from the origin instance to the destination instance . Skips alerts that point to queries that were not migrated by the ` queries ` command . Run the ` destinations ` command first . \ b favorites Duplicate favorite flags on queries and dashboards from the origin instance to the destination instance . \ b disable - users Disable users in the destination instance that are disabled in the origin instance . \ b fix - qrds - refs Replace references to origin query id ' s in query results data source ( QRDS ) queries with their new id at the destination . Does nothing if the destination has no QRDS sources . \ b fix - csv - queries Reformat queries against app . redash . io ' s csvurl data source so they are compatible with OSS Redash ' s csv data source . Do not use this command if you did not migrate from app . redash . io . \ b Commands should be called in the order specified here . Check meta . json between steps to confirm expected behavior .
def main(command):
    try:
        make_global_meta()
    except Exception as e:
        if command == "init":
            pass
        else:
            print(
                f"Script could not proceed because of a problem reading meta.json: {e}"
            )
            print("Please run redash-migrate init before proceeding")
            return
    if command == "init":
        return init()
    from_client = Redash(ORIGIN, ORIGIN_API_KEY)
    to_client = Redash(DESTINATION, DESTINATION_API_KEY)
    command_map = {
        "data-sources": import_data_sources,
        "check-data-sources": check_data_sources,
        "users": import_users,
        "groups": import_groups,
        "destinations": import_destinations,
        "queries": import_queries,
        "fix-qrds-refs": fix_qrds_refs,
        "fix-csv-queries": fix_csv_queries,
        "visualizations": import_visualizations,
        "dashboards": import_dashboards,
        "alerts": import_alerts,
        "favorites": import_favorites,
        "disable-users": disable_users,
    }
    _command = command_map.get(command)
    if _command is None:
        print(f"{command} is not a valid command. See --help for instructions")
        return
    wrapped = save_meta_wrapper(command_map.get(command))
    if wrapped is None:
        print("No command provided. See --help for instructions")
    return wrapped(from_client, to_client)
def main ( command ) : try : make_global_meta ( ) except Exception as e : if command == "init" : pass else : print ( f"Script could not proceed because of a problem reading meta.json: {e}" ) print ( "Please run redash-migrate init before proceeding" ) return if command == "init" : return init ( ) from_client = Redash ( ORIGIN , ORIGIN_API_KEY ) to_client = Redash ( DESTINATION , DESTINATION_API_KEY ) command_map = { "data-sources" : import_data_sources , "check-data-sources" : check_data_sources , "users" : import_users , "groups" : import_groups , "destinations" : import_destinations , "queries" : import_queries , "fix-qrds-refs" : fix_qrds_refs , "fix-csv-queries" : fix_csv_queries , "visualizations" : import_visualizations , "dashboards" : import_dashboards , "alerts" : import_alerts , "favorites" : import_favorites , "disable-users" : disable_users , } _command = command_map . get ( command ) if _command is None : print ( f"{command} is not a valid command. See --help for instructions" ) return wrapped = save_meta_wrapper ( command_map . get ( command ) ) if wrapped is None : print ( "No command provided. See --help for instructions" ) return wrapped ( from_client , to_client )
Redash migration tool.
Redash migration tool .
"""Redash migration tool. Can be used to migrate objects (users, queries, visualizations, dashboards, alerts, and favorites)
    from one Redash instance to another.

    Commands:

      \b
      init                  Create a meta.json template file in your working directory. You will be
                            prompted to enter authentication information for your origin and desti-
                            nation instances.

      \b
      data-sources          Create stubs of your origin data sources in your destination instance

      \b
      check-data-sources    Compare the data sources in your origin and destination instances

      \b
      users                 Duplicate user names, emails, and enabled/disabled status from the
                            origin instance into the destination instance.

      \b
      groups                Duplicate group names, member lists, and data source permissions from
                            the origin instance into the destination instance.

      \b
      queries               Duplicate queries from the origin instance to the destination instance.
                            Skips queries with an unknown destination data source or user.

      \b
      visualizations        Duplicate visualizations from the origin instance to the destination
                            instance. Only duplicates visualizations for queries moved by the
                            `queries` command.

      \b
      dashboards            Duplicate dashboards from the origin instance to the destination
                            instance. Skips any dashboard widget whose visualization was not moved
                            using the `visualizations` command.

      \b
      destinations          Create stubs of your origin alert destinations in your destination
                            instance

      \b
      alerts                Duplicate alert definitions from the origin instance to the destination
                            instance. Skips alerts that point to queries that were not migrated by
                            the `queries` command. Run the `destinations` command first.

      \b
      favorites             Duplicate favorite flags on queries and dashboards from the origin
                            instance to the destination instance.

      \b
      disable-users         Disable users in the destination instance that are disabled in the
                            origin instance.

      \b
      fix-qrds-refs         Replace references to origin query id's in query results data source
                            (QRDS) queries with their new id at the destination. Does nothing if
                            the destination has no QRDS sources.

      \b
      fix-csv-queries       Reformat queries against app.redash.io's csvurl data source so they are
                            compatible with OSS Redash's csv data source. Do not use this command if
                            you did not migrate from app.redash.io.

      \b
      Commands should be called in the order specified here. Check meta.json between steps to
      confirm expected behavior.
    """
command