databricks: check if the mountpoint already mounted

11,172

Solution 1

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

Solution 2

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

%fs mounts

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

Solution 3

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.

Share:
11,172
mytabi
Author by

mytabi

Updated on June 25, 2022

Comments

  • mytabi
    mytabi almost 2 years

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

    dbutils.fs.mount
    

    Thanks