工作区 CLI (旧版)

重要

本文档已停用,可能不会更新。

此信息适用于旧版 Databricks CLI 0.18 及更低版本。 Databricks 建议改用较新的 Databricks CLI 0.205 或更高版本。 请参阅 Databricks CLI。 若要查找你的 Databricks CLI 的版本,请运行 databricks -v

要从 Databricks CLI 版本 0.18 或更低版本迁移到 Databricks CLI 版本 0.205 或更高版本,请参阅 Databricks CLI 迁移

可以通过将 Databricks 工作区 CLI 子命令附加到 databricks workspace 来运行。 这些子命令调用 工作区 API

databricks workspace -h
Usage: databricks workspace [OPTIONS] COMMAND [ARGS]...

  Utility to interact with the Databricks workspace. Workspace paths must be
  absolute and be prefixed with `/`.

Common Options:
  -v, --version  [VERSION]
  -h, --help     Show this message and exit.

Commands:
  delete      Deletes objects from the Databricks workspace. rm and delete are synonyms.
    Options:
        -r, --recursive
  export      Exports a file from the Databricks workspace.
    Options:
      -f, --format FORMAT      SOURCE, HTML, JUPYTER, or DBC. Set to SOURCE by default.
      -o, --overwrite          Overwrites file with the same name as a workspace file.
  export_dir  Recursively exports a directory from the Databricks workspace.
    Options:
      -o, --overwrite          Overwrites local files with the same names as workspace files.
  import      Imports a file from local to the Databricks workspace.
    Options:
      -l, --language LANGUAGE  SCALA, PYTHON, SQL, R  [required]
      -f, --format FORMAT      SOURCE, HTML, JUPYTER, or DBC. Set to SOURCE by default.
      -o, --overwrite          Overwrites workspace files with the same names as local files.
  import_dir  Recursively imports a directory to the Databricks workspace.

    Only directories and files with the extensions .scala, .py, .sql, .r, .R,
    .ipynb are imported. When imported, these extensions are stripped off
    the name of the notebook.

    Options:
      -o, --overwrite          Overwrites workspace files with the same names as local files.
      -e, --exclude-hidden-files
  list        Lists objects in the Databricks workspace. ls and list are synonyms.
    Options:
      --absolute               Displays absolute paths.
      -l                       Displays full information including ObjectType, Path, Language
  ls          Lists objects in the Databricks workspace. ls and list are synonyms.
    Options:
      --absolute               Displays absolute paths.
      -l                       Displays full information including ObjectType, Path, Language
  mkdirs      Makes directories in the Databricks workspace.
  rm          Deletes objects from the Databricks workspace. rm and delete are synonyms.
    Options:
        -r, --recursive

从工作区中删除对象

若要显示使用情况文档,请运行 databricks workspace delete --helpdatabricks workspace rm --help

databricks workspace delete --recursive "/Users/[email protected]/My Folder"

或者:

databricks workspace rm --recursive "/Users/[email protected]/My Folder"

如果成功,则不显示任何输出。

将文件从工作区导出到本地文件系统

若要显示使用情况文档,请运行 databricks workspace export --help

databricks workspace export --overwrite --format JUPYTER "/Users/[email protected]/My Python Notebook" /Users/me/Downloads

此选项还可用于从 Databricks Git 文件夹导出笔记本:

databricks workspace export "/Repos/[email protected]/MyRepoNotebook" /Users/me/Downloads

如果成功,则不显示任何输出。

将目录从工作区导出到本地文件系统

若要显示使用情况文档,请运行 databricks workspace export_dir --help

databricks workspace export_dir --overwrite /Users/[email protected]/my-folder /Users/me/Downloads/my-folder
/Users/[email protected]/my-folder/My Python Notebook -> /Users/me/Downloads/my-folder/My Python Notebook.py
/Users/[email protected]/my-folder/My Scala Notebook -> /Users/me/Downloads/my-folder/My Scala Notebook.scala
/Users/[email protected]/my-folder/My R Notebook -> /Users/me/Downloads/my-folder/My R Notebook.r
/Users/[email protected]/my-folder/My SQL Notebook -> /Users/me/Downloads/my-folder/My SQL Notebook.sql

将文件从本地文件系统导入工作区

若要显示使用情况文档,请运行 databricks workspace import --help

只能导入扩展名为 .scala.py.sql.r.R 的文件。 导入后,这些扩展将从笔记本名称中剥离。

databricks workspace import ./a.py /Users/[email protected]/example
./a.py -> /Users/[email protected]/example/a

将目录从本地文件系统导入工作区

若要显示使用情况文档,请运行 databricks workspace import_dir --help

此命令以递归方式将目录从本地文件系统导入工作区。 仅导入扩展名为.scala.py.sql.r.R的目录和文件。 导入后,这些扩展将从笔记本名称中剥离。

若要覆盖目标路径上的现有笔记本,请添加标志 --overwrite-o

tree
.
├── a.py
├── b.scala
├── c.sql
├── d.R
└── e
databricks workspace import_dir . /Users/[email protected]/example
./a.py -> /Users/[email protected]/example/a
./b.scala -> /Users/[email protected]/example/b
./c.sql -> /Users/[email protected]/example/c
./d.R -> /Users/[email protected]/example/d
databricks workspace ls /Users/[email protected]/example -l
NOTEBOOK   a  PYTHON
NOTEBOOK   b  SCALA
NOTEBOOK   c  SQL
NOTEBOOK   d  R
DIRECTORY  e

列出工作区中的对象

若要显示使用情况文档,请运行 databricks workspace list --helpdatabricks workspace ls --help

databricks workspace list --absolute --long --id /Users/[email protected]

或者:

databricks workspace ls --absolute --long --id /Users/[email protected]
NOTEBOOK           /Users/[email protected]/My Python Notebook  PYTHON  1234567898012345
NOTEBOOK           /Users/[email protected]/My Scala Notebook   SCALA   2345678980123456
NOTEBOOK           /Users/[email protected]/My R Notebook       R       3456789801234567
DIRECTORY          /Users/[email protected]/My Directory                4567898012345678
MLFLOW_EXPERIMENT  /Users/[email protected]/My_Experiment               5678980123456789

在工作区中创建目录

若要显示使用情况文档,请运行 databricks workspace mkdirs --help

databricks workspace mkdirs "/Users/[email protected]/My New Folder"

如果成功,则不显示任何输出。