12

How to check if the mount point is already mounted before mount in databricks python ??

dbutils.fs.mount

Thanks

CHEEKATLAPRADEEP
  • 12,191
  • 1
  • 19
  • 42
mytabi
  • 639
  • 2
  • 12
  • 28

4 Answers4

18

Try this:

def sub_unmount(str_path):
    if any(mount.mountPoint == str_path for mount in dbutils.fs.mounts()):
        dbutils.fs.unmount(str_path)

sub_unmount('/mnt/flightdata')

Result:

/mnt/flightdata has been unmounted.

Verify with this:

dbutils.fs.ls("/mnt/")

Inspired by this: https://forums.databricks.com/questions/8103/graceful-dbutils-mountunmount.html

howchoy
  • 311
  • 3
  • 5
  • thanks for this! Hvae a question, what happens if we don't unmount a path? Lets say a data lake path – mas Feb 15 '21 at 22:51
6

Open a new cell in Databricks notebook and write the below command:

%fs mounts
OR
display(dbutils.fs.mounts())

As an output, you will get mountpoint, path, and the encryption type.

venus
  • 1,188
  • 9
  • 18
2

How to check if the mount point is already mounted before mount in databricks python ??

You can use the below cmdlet to check if the mount point is already mounted before mount in databricks python.

%fs ls dbfs:/mnt

Example: I have two mount points attached to the DBFS and the results as shown as follows.

enter image description here

OR

You can use the below cmdlet to check if the mount point is already mounted before mount in databricks python.

dbutils.fs.ls('/mnt/')

enter image description here

Hope this helps.

CHEEKATLAPRADEEP
  • 12,191
  • 1
  • 19
  • 42
0

For someone looking for scala solution

val mounts = dbutils.fs.ls("/mnt/").filter(_.name.contains("is_mounted_blob"))
println(mounts .size)

If the blob is mounted it will give a non zero size.

Abhi
  • 6,471
  • 6
  • 40
  • 57