Skip to main content
Delphix

How to Share Delphix vFiles Over SMB (KBA6509)

 

KBA

KBA# 6509

Can Delphix vFiles be shared over SMB?

After provisioning vFiles to a Windows host, they can be shared like any other directory so that they can be accessed from another host via a UNC (Universal Naming Convention) path.

Can creation and removal of the shares be automated?

It is easy to automate the creation and removal of the network shares by creating three hooks.

1. Create a hook script that shares the directory (for example "shareit.ps1"):

function die {
    Write-Error "Error: $($args[0])"

    # run exit handler, if defined
    if (Get-Command -type Function -name atExit 2> $null) {
        atExit
    }
    exit 1
}

function verifySuccess {
    if (!$?) {
        die "$($args[0])"
    }
}

$VFILE_DIRECTORY = $env:DLPX_DATA_DIRECTORY

# Check if the share exists
$exists = Get-SmbShare -Name "Vfiles_Test"

# If the share does not already exist create it
If ($exists -eq $null) {
        New-SMBShare –Name "Vfiles_Test" –Path $VFILE_DIRECTORY
        verifySuccess "Failed to create a share for $VFILE_DIRECTORY"
} else {
    Write-Host "The network share Vfiles_Test already exists."
    exit 1
}
exit 0

2. Call the script in both the "Configure Clone" (so that the share is created when the vFiles are first provisioned) and "Post Start" (so that the files are shared in case someone manually disables and then enables the vFiles) hooks by calling it like this:

PowerShell -File c:\temp\shareit.ps1; exit $LASTEXITCODE

3. Create a hook to stop sharing the files (for examples "stopsharing.ps1"):

function die {
    Write-Error "Error: $($args[0])"

    # run exit handler, if defined
    if (Get-Command -type Function -name atExit 2> $null) {
        atExit
    }
    exit 1
}

function verifySuccess {
    if (!$?) {
        die "$($args[0])"
    }
}

# Check if the share exists
$exists = Get-SmbShare -Name "Vfiles_Test"

# If the share exists, stop sharing it.
# If it doesn't exist, just exit.
If ($exists -ne $null) {
    Remove-SmbShare –Name "Vfiles_Test" –Force
    verifySuccess "Failed to remove SMB share Vfiles_Test"
}
exit 0

4. Call the script from the "Post Stop" hook so that it stops sharing if the vFiles are deleted or disabled:

PowerShell -File c:\temp\stopsharing.ps1; exit $LASTEXITCODE

NOTE: The above are very simple examples to illustrate this capability. You would want to add error handling or logging and return an exit code to indicate success/failure as illustrated in this KB article ( https://support.delphix.com/Delphix_Virtualization_Engine/MSSQL_Server/Executing_SQL_in_a_PowerShell_Hook_Script_(KBA1370) ).

Also consider using the other command line options for the New-SMBShare to restrict access to the share.

Related Articles 

The following articles may provide more information or related information to this article: