ISCSI Target Scheduled Snapshots

I know there are cmdlets to snapshot a target but is there a built in way to schedule snapshots?

Alternatively, is there a cmdlet to list snapshots for a target so I can create a script to run on a schedule to remove old snapshots and create new ones.

February 1st, 2014 10:29am

I know there are cmdlets to snapshot a target but is there a built in way to schedule snapshots?

Alternatively, is there a cmdlet to list snapshots for a target so I can create a script to run on a schedule to remove old snapshots and create new ones.

Yes, you can use Schedule Snapshot Wizard to have automatic snapshots. See:

Creating and Managing Snapshots and Schedules

http://technet.microsoft.com/en-us/library/gg232620(v=ws.10).aspx

Creating and Scheduling Snapshots of Virtual Disks

http://technet.microsoft.com/en-us/library/gg232610(v=ws.10).aspx

Alternatively you can use cmdlets to deal with these tasks (PowerShell would give you more control over creation / deletion of a snapshots. See:

iSCSI Target Cmdlets in Windows PowerShell

http://technet.microsoft.com/en-us/library/jj612803.aspx

The ones should be of your interest are Checkpoint-IscsiVirtualDisk and Remove-IscsiVirtualDiskSnapshot cmdlets.

Also you may use SMI-S and WMI if you want to use say C# or C++ and not PowerShell. 

Some more of the cmdlets use links (including samples). See:

PowerShell cmdlets for the Microsoft iSCSI Target 3.3 (included in Windows Storage Server 2008 R2)

http://blogs.technet.com/b/josebda/archive/2010/09/29/powershell-cmdlets-for-the-microsoft-iscsi-target-3-3-included-in-windows-storage-server-2008-r2.aspx

(that's for Windows Server 2008 R2 and up)

Managing iSCSI Target Server through Storage Cmdlets

http://blogs.technet.com/b/filecab/archive/2013/09/28/managing-iscsi-target-server-through-storage-cmdlets.aspx

(the most recent one about Windows Server 2012 R2)

Hope this helped a bit. Good luck :)

Free Windows Admin Tool Kit Click here and download it now
February 1st, 2014 11:44am

I forgot to mention that I'm using Server 2012 R2.  I can't find any UI in Server 2012 R2 for scheduling snapshots.

Here is the script I wrote.  You can create a scheduled task in Windows to run it daily.

$DaysToKeep = 7;


$Disks = Get-IscsiVirtualDisk

foreach($Disk in $Disks){



    $Snapshots = Get-IscsiVirtualDiskSnapshot $Disk.Path;

    Write-Host ""
    Write-Host "Deleting Old Snapshots for Disk" $Disk.Path;

    foreach($Snapshot in $Snapshots){

    $SnapshotDate = $Snapshot.Timestamp;

        $SnapshotFound = $false

        if($SnapshotDate -lt (Get-Date).AddDays(-$DaysToKeep)){

            $SnapshotFound = $true

            Write-Host "Deleting Snapshot" $Snapshot.SnapshotId;

            Remove-IscsiVirtualDiskSnapshot $Snapshot.SnapshotId;

            Write-Host "Snapshot" $Snapshot.SnapshotId "Deleted";

            Write-Host "";
        }

    }

    if($SnapshotFound -ne $true){
    Write-Host "No Snapshots Found";
    }
    Write-Host "Done"



    Write-Host "";
    Write-Host "Creating Snapshot for Disk" $Disk.Path;
    $NewSnapshot = Checkpoint-IscsiVirtualDisk $Disk.Path;
    Write-Host "Snapshot" $NewSnapshot.SnapshotId "Created";

     

}
Write-Host ""
Write-Host ""
Write-Host "Script Complete"


February 2nd, 2014 12:48am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics