Skip to main content
Delphix

Powershell script to remove empty VDB directories left behind after deletion (KBA6909)

 

 

KBA

KBA# 6909

 

Issue

In Delphix engine versions less than 6.0.6.0, an issue was found where after deleting a VDB, the directory corresponding to the VDB in the “DelphixConnector" directory remains, which can clutter the directory and lead to some inconvenience.

Although the issue is fixed in 6.0.6.0, we are providing this script to purge the "DelphixConnector" directory of the stale VDB directories, as the fix does not include its own remediation measures to remove the remaining directories.

Prerequisites

  1. You need PowerShell installed on your Windows machine.

  2. You need to run the script as a local administrator, or the user running the script should have the access to the “DelphixConnector” directory, such as the Delphix OS (Operating System) user in the target environment.

Applicable Delphix Versions

Click here to view the versions of the Delphix engine to which this article applies
Major Release All Sub Releases
6.0 6.0.0.0, 6.0.1.0, 6.0.1.1, 6.0.2.0, 6.0.2.1, 6.0.3.0, 6.0.3.1, 6.0.4.0, 6.0.4.1, 6.0.4.2, 6.0.5.0

5.3

5.3.0.0, 5.3.0.1, 5.3.0.2, 5.3.0.3, 5.3.1.0, 5.3.1.1, 5.3.1.2, 5.3.2.0, 5.3.3.0, 5.3.3.1, 5.3.4.0, 5.3.5.0 5.3.6.0, 5.3.7.0, 5.3.7.1, 5.3.8.0, 5.3.8.1, 5.3.9.0

5.2

5.2.2.0, 5.2.2.1, 5.2.3.0, 5.2.4.0, 5.2.5.0, 5.2.5.1, 5.2.6.0, 5.2.6.1

5.1

5.1.0.0, 5.1.1.0, 5.1.2.0, 5.1.3.0, 5.1.4.0, 5.1.5.0, 5.1.5.1, 5.1.6.0, 5.1.7.0, 5.1.8.0, 5.1.8.1, 5.1.9.0, 5.1.10.0

5.0

5.0.1.0, 5.0.1.1, 5.0.2.0, 5.0.2.1, 5.0.2.2, 5.0.2.3, 5.0.3.0, 5.0.3.1, 5.0.4.0, 5.0.4.1 ,5.0.5.0, 5.0.5.1, 5.0.5.2, 5.0.5.3, 5.0.5.4

4.3

4.3.1.0, 4.3.2.0, 4.3.2.1, 4.3.3.0, 4.3.4.0, 4.3.4.1, 4.3.5.0

4.2

4.2.0.0, 4.2.0.3, 4.2.1.0, 4.2.1.1, 4.2.2.0, 4.2.2.1, 4.2.3.0, 4.2.4.0 , 4.2.5.0, 4.2.5.1

4.1

4.1.0.0, 4.1.2.0, 4.1.3.0, 4.1.3.1, 4.1.3.2, 4.1.4.0, 4.1.5.0, 4.1.6.0

Functionalities of the script

  1. The script takes two inputs from the user, ConnectorDir and EngineUuid.

    1. ConnectorDir is the absolute path to the Delphix Connector directory.

    2. EngineUuid is the Server ID that can be found in the engine GUI in About -> Help.

  1. After receiving the input, the script navigates to the ConnectorDir and lists all the VDB directories of the EngineUuid specified.
  2. The script then checks the DATA directories inside the VDB directories. If the Data directory is empty, the associated VDB directory will be deleted. Otherwise, the script will ignore the associated VDB directory. 

 

Script: cleanup_stale_vdb_folder.ps1

Download the script here:  cleanup_stale_vdb_folder.ps1.

The contents of the "cleanup_stale_vdb_folder.ps1" Powershell script are displayed here for convenience.

 <#
.SYNOPSIS
    The script is used to delete stale entries for the VDB directory from the
    Delphix Connector folder.


.DESCRIPTION
    For Delphix engine version less than or equal to 6.0.5.0, the VDB folders
    from the Connector directory does not get removed even when the VDB is deleted.
    Given the Connector folder and the engine UUID, the script determines such
    stale entries for the VDB directory and deletes them.


.PARAMETER ConnectorDir
    The Delphix Connector directory path where the VDB folder is created.


.PARAMETER EngineUuid
    The Delphix engine UUID; the UUID value is used to filter the VDB directories.


.EXAMPLE
    path\to\the\script\cleanup_stale_vdb_folder.ps1
#>


<#
Copyright (c) 2020 by Delphix. All rights reserved.
#>


param(
    [Parameter(Mandatory = $true)]
    [String] $ConnectorDir,


    [Parameter(Mandatory = $true)]
    [String] $EngineUuid
)


# Setting the value of ErrorActionPreference to 'Stop' to catch the non terminating errors.
$ErrorActionPreference = 'Stop'


function DeleteVdbDir {
    param([string]$vdb_dir)
    try {
        Write-Host "The VDB directory- [$vdb_folder] is a stale entry, deleting..."
        Remove-Item -Path $vdb_folder -Recurse -Force
    }
    catch [System.Exception] {
        Write-Host "An error occurred while deleting the VDB directory- [$vdb_folder]:"
        Write-Error $_
    }
}


function CheckStaleVdbDir {
    param([string]$vdb_dir)
    try {
        $vdb_folder = Join-Path -Path $ConnectorDir -ChildPath $vdb_dir
        $vdb_data_folder = Join-Path -Path $vdb_folder -ChildPath "\DATA"
        $vdb_data_folder_content = Join-Path -Path $vdb_folder -ChildPath "\DATA\*"


        # Delete the directory if the "DATA" folder is not present or if it is empty.
        if (Test-Path $vdb_data_folder) {
            if (!(Test-Path $vdb_data_folder_content)) {
                DeleteVdbDir $vdb_folder
            }
        }
        else {
            DeleteVdbDir $vdb_folder
        }
    }
    catch [System.Exception] {
        Write-Host "An error occurred while checking if the VDB directory- [$vdb_folder] is stale:"
        Write-Error $_
    }


}


if (Test-Path $ConnectorDir) {


    # Get all the VDB directory names from the Connector directory.
    $filter = $EngineUuid + "-vdb*"
    $all_vdb_dir_names = Get-ChildItem -Path $ConnectorDir -filter $filter -Name


    if ($all_vdb_dir_names) {
        Write-Host "Cleaning up VDB directories from- [$ConnectorDir] for engine- [$EngineUuid] ...`n"
        foreach ($vdb_dir in $all_vdb_dir_names) {
            CheckStaleVdbDir $vdb_dir
        }
    }
    else {
        Write-Host "No stale VDBs found at- [$ConnectorDir] for engine- [$EngineUuid] ...`n"
    }


}
else {
    throw "The given Connector directory- [$ConnectorDir] does not exist."
}

 

 

The script help menu and contents

 

Help parameters

Description

SYNOPSIS

Synopsis of the script

DESCRIPTION

A detailed description of the script

PARAMETER ConnectorDir

The Delphix Connector directory path where the VDB folder is created.

PARAMETER EngineUuid

The Delphix engine UUID

EXAMPLE

Example commands to run the script

Help output

This output is generated by the Powershell command Get-Help. It will not provide real examples, and is limited in what it can display, but does provide the syntax for execution.

 PS C:\delphix> powershell Get-Help .\cleanup_stale_vdb_folder.ps1


NAME
    C:\delphix\cleanup_stale_vdb_folder.ps1
    
SYNOPSIS
    The script is used to delete stale entries for the VDB directory from the
    Delphix Connector folder.
    
    
SYNTAX
    C:\delphix\cleanup_stale_vdb_folder.ps1 [-ConnectorDir] <String> [-EngineUuid] <String> [<CommonParameters>]
    
    
DESCRIPTION
    For Delphix engine version less than or equal to 6.0.5.0, the VDB folders
    from the Connector directory does not get removed even when the VDB is deleted.
    Given the Connector folder and the engine UUID, the script determines such
    stale entries for the VDB directory and deletes them.
    


RELATED LINKS


REMARKS
    To see the examples, type: "get-help C:\delphix\cleanup_stale_vdb_folder.ps1 -examples".
    For more information, type: "get-help C:\delphix\cleanup_stale_vdb_folder.ps1 -detailed".
    For technical information, type: "get-help C:\delphix\cleanup_stale_vdb_folder.ps1 -full".

 

 

 

 


Example executions 

Example 1: DelphixConnector default directory and passing parameters on command line:

In this example the DelphixConnector is installed under the default location of "C:\Program FIles\Delphix\DelphixConnector".  There are two VDB directories that are empty:

  • C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-3
  • C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-5

DelphixConn.png

 

You need single or double quotes on the ConnectorDir parameter when involving directories that include spaces in their name such as "Program Files".

The example uses these parameter values:

  • ConnectorDir:  C:\Program FIles\Delphix\DelphixConnector
  • EngineUuid:  564d1b59-6471-0734-1d87-475ed27f79ba
Double quotes
PS C:\Program Files\Delphix> .\cleanup_stale_vdb_folder.ps1 -ConnectorDir "C:\Program Files\Delphix\DelphixConnector" -EngineUuid 564d1b59-6471-0734-1d87-475ed27f79ba
Cleaning up VDB directories from- [C:\Program Files\Delphix\DelphixConnector] for engine- [564d1b59-6471-0734-1d87-475ed27f79ba] ...

The VDB directory- [C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-3] is a stale entry, deleting...
The VDB directory- [C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-5] is a stale entry, deleting...

File Explorer view after the cleanup:

DelphixConn_after.png

 

Single quotes
PS C:\Program Files\Delphix>  .\cleanup_stale_vdb_folder.ps1 -ConnectorDir 'C:\Program Files\Delphix\DelphixConnector' -EngineUuid 564d1b59-6471-0734-1d87-475ed27f79ba
Cleaning up VDB directories from- [C:\Program Files\Delphix\DelphixConnector] for engine- [564d1b59-6471-0734-1d87-475ed27f79ba] ...

The VDB directory- [C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-3] is a stale entry, deleting...
The VDB directory- [C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-5] is a stale entry, deleting...
Example 2: Running script with no parameters; prompting for values

In this example no script parameters are provided on command line.

Since there are mandatory parameters, Powershell will prompt for the values.

important

Important:

Do not quote the "ConnectorDir" when entering the directory interactively even if there are spaces in the path.

 

PS C:\Program Files\Delphix> .\cleanup_stale_vdb_folder.ps1

cmdlet cleanup_stale_vdb_folder.ps1 at command pipeline position 1
Supply values for the following parameters:
ConnectorDir: C:\Program Files\Delphix\DelphixConnector
EngineUuid: 564d1b59-6471-0734-1d87-475ed27f79ba
Cleaning up VDB directories from- [C:\Program Files\Delphix\DelphixConnector] for engine- [564d1b59-6471-0734-1d87-475ed27f79ba] ...

The VDB directory- [C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-3] is a stale entry, deleting...
The VDB directory- [C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-5] is a stale entry, deleting...
Example 3: Non-conventional DelphixConnector directory

In this simple example the DelphixConnector directory, named "C:\delphix\vdb-delete-test" (a mock directory) has targeted the one VDB empty folder from an engine specified by the EngineUuid parameter.

This example does not provide parameters on command line, and the script code prompts the user to enter the specified values.

 PS C:\delphix> .\cleanup_stale_vdb_folder.ps1
cmdlet cleanup_stale_vdb_folder.ps1 at command pipeline position 1
Supply values for the following parameters:
ConnectorDir: C:\delphix\vdb-delete-test
EngineUuid: 564d1b59-6471-0734-1d87-475ed27f79bb
Cleaning up VDB directories from- [C:\delphix\vdb-delete-test] for engine- [564d1b59-6471-0734-1d87-475ed27f79bb] ...


The VDB directory- [C:\delphix\vdb-delete-test\564d1b59-6471-0734-1d87-475ed27f79bb-vdb-4] is a stale entry, deleting... 

The script locates an empty "DATA" folder and removes "C:\delphix\vdb-delete-test\564d1b59-6471-0734-1d87-475ed27f79bb-vdb-4"

Example 4: DelphixConnector with different EngineUuid values under DelphixConnector directory:

In this example there are four VDB directories under on Engine UUID (vdb-1, -2, -3, -5), and vdb-4 is under a different Engine UUID.  Also, the vdb-3 DATA directory contains "db" and it contains a file, hence, not empty. 

Note

Note:

The issue is that Delphix removes the "db" directory, leaving behind an empty "DATA" directory.

 

vdb-delete.png

 

Results
 PS C:\delphix> C:\delphix\cleanup_stale_vdb_folder.ps1 -ConnectorDir C:\delphix\vdb-delete-test -EngineUuid 564d1b59-6471-0734-1d87-475ed27f79ba
Cleaning up VDB directories from- [C:\delphix\vdb-delete-test] for engine- [564d1b59-6471-0734-1d87-475ed27f79ba] ...


The VDB directory- [C:\delphix\vdb-delete-test\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-1] is a stale entry, deleting...
The VDB directory- [C:\delphix\vdb-delete-test\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-2] is a stale entry, deleting...
The VDB directory- [C:\delphix\vdb-delete-test\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-5] is a stale entry, deleting...
 

The directories for vdb-3 and vdb-4 are not deleted.

vdb-delete-results.png

The other three directories have been deleted.

 

Troubleshooting

If you encounter problems executing the script check here for possible solutions.

Digitally signed issues

If you see the following output upon execution:

 PS C:\delphix\test> .\cleanup_stale_vdb_folder.ps1  -ConnectorDir C:\delphix\vdb-delete-test -EngineUuid 564d1b59-6471-0734-1d87-475ed27f79ba Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass


.\cleanup_stale_vdb_folder.ps1 : File C:\delphix\test\cleanup_stale_vdb_folder.ps1 cannot be loaded. The file C:\delphix\test\cleanup_stale_vdb_folder.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\cleanup_stale_vdb_folder.ps1  -ConnectorDir C:\delphix\vdb-delete-t ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess


 
  • Check the indicated web site:  Execution_Policies
  • Check with security administrator to verify downloads such as this are allowed.
  • As an alternative, copy the script text and paste to a blank powershell script file and execute from there.
  • Try a solution such as this, which will bypass the policy for the session only:
PS C:\tmp> Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the
about_Execution_Policies help topic at https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y
PS C:\tmp> .\cleanup_stale_vdb_folder.ps1

cmdlet cleanup_stale_vdb_folder.ps1 at command pipeline position 1
Supply values for the following parameters:
ConnectorDir:

Permission issue

If the user running the script doesn't have adequate permissions to remove the VDB directories:

PS C:\Program Files\Delphix>  .\cleanup_stale_vdb_folder.ps1 -ConnectorDir "C:\Program Files\Delphix\DelphixConnector" -EngineUuid 564d1b59-6471-0734-1d87-475ed27f79ba
Cleaning up VDB directories from- [C:\Program Files\Delphix\DelphixConnector] for engine- [564d1b59-6471-0734-1d87-475ed27f79ba] ...

The VDB directory- [C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-3] is a stale entry, deleting...
An error occurred while deleting the VDB directory- [C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-3]:
An error occurred while checking if the VDB directory- [C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-3] is stale:
CheckStaleVdbDir : Cannot remove item C:\Program Files\Delphix\DelphixConnector\564d1b59-6471-0734-1d87-475ed27f79ba-vdb-3\DATA: Access to the path is denied.
At C:\Program Files\Delphix\cleanup_stale_vdb_folder.ps1:84 char:13
+             CheckStaleVdbDir $vdb_dir
+             ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CheckStaleVdbDir

 

Incorrect Parameter

Using ConnectionDir instead of ConnectorDir

PS C:\Program Files\Delphix> .\cleanup_stale_vdb_folder.ps1 -ConnectionDir 'C:\Program FIles\Delphix\DelphixConnector' -EngineUuid 564d1b59-6471-0734-1d87-475ed27f79ba
C:\Program Files\Delphix\cleanup_stale_vdb_folder.ps1 : A parameter cannot be found that matches parameter name 'ConnectionDir'.
At line:1 char:32
+ .\cleanup_stale_vdb_folder.ps1 -ConnectionDir 'C:\Program FIles\Delph ...
+                                ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [cleanup_stale_vdb_folder.ps1], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,cleanup_stale_vdb_folder.ps1

Non-existing Directory

PS C:\Program Files\Delphix> .\cleanup_stale_vdb_folder.ps1

cmdlet cleanup_stale_vdb_folder.ps1 at command pipeline position 1
Supply values for the following parameters:
ConnectorDir: C:\Program Files\NoDir
EngineUuid: 564d1b59-6471-0734-1d87-475ed27f79ba
The given Connector directory- [C:\Program Files\NoDir] does not exist.
At C:\Program Files\Delphix\cleanup_stale_vdb_folder.ps1:93 char:5
+     throw "The given Connector directory- [$ConnectorDir] does not ex ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (The given Conne...does not exist.:String) [], RuntimeException
    + FullyQualifiedErrorId : The given Connector directory- [C:\Program Files\NoDir] does not exist.

As other issues are encountered this KBA will be updated.

 

Additional Information

For Digitally signed or similar issues refer to this link:  Execution_Policies