Backup DataCore SANsymphony-V config using PowerShell
In November 2013 I published a PowerShell script on blazilla.de that creates a backup of your SANsymphony-V config by using the DataCore SANsymphony-V PowerShell cmdlets. I would like to thank Marcel, Michael and Frank for their feedback and comments to improve the script. The password is stored in the securestring.txt that needs to be stored in the same directory as the script. Kudos to Marcel, who has the part of the script contributed, that stores the password in an encrypted file.
Currently there is no way to schedule a configuration backup using the DataCore GUI. A valid backup of the configuration can be a lifesaver, especially in the case, that you storage server crashed and it has to be re-installed. So it’s a good idea to regularly backup the configuration to the local disk and copy this backup to another location. One way to create a backup, is an Outlook task and the DataCore GUI. Belive me, that will not work… At this point my script comes into play. The script uses Microsoft PowerShell, DataCore SANsymphony-V PowerShell cmdlets and the Windows Task Scheduler to automate the backup of SANsymphony-V configuration.
There are a couple of variables used in the script. Two of them are used to change the number of stored backups and the directory in which the backups will be saved. The script saves the last three versions of the configuration backups, but you can change this with the $Keep
variable. The directory, in which the backup will be saved, is influenced by the $BackupFolder
variable.
<# | |
.SYNOPSIS | |
No parameters needed. Just execute the script. | |
.DESCRIPTION | |
This script creates a backup of the DataCore SANsymphony-V configuration. | |
.EXAMPLE | |
Create-DataCoreSSVBackup | |
.NOTES | |
Author: Patrick Terlisten, patrick@blazilla.de, Twitter @PTerlisten | |
This script is provided “AS IS” with no warranty expressed or implied. Run at your own risk. | |
This work is licensed under a Creative Commons Attribution NonCommercial ShareAlike 4.0 | |
International License (https://creativecommons.org/licenses/by-nc-sa/4.0/). | |
.LINK | |
http://www.vcloudnine.de | |
#> | |
# Register DataCore Cmdlets | |
Import-Module 'C:\Program Files\DataCore\SANsymphony\DataCore.Executive.Cmdlets.dll' -WarningAction silentlyContinue | |
# To create an encrypted password file, execute the following command | |
# Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File securestring.txt | |
# Be sure to set $$ScriptFolder to the folder where the script is located. | |
# Variables | |
$BackupFolder = 'C:\SSVBACKUP' | |
$ScriptFolder = 'C:\Scripts' | |
$DcsLoginServer = HOSTNAME.EXE | |
$DcsUserName = 'Administrator' | |
$DcsPassword = Get-Content $ScriptFolder\securestring.txt | ConvertTo-SecureString | |
$DcsCredItem = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist $DcsUserName, $DcsPassword | |
$Keep = 3 | |
# Connect to Server Group using $server | |
Connect-DcsServer -Server $DcsLoginServer -Credential $DcsCredItem -Connection $DcsLoginServer | |
# Rotate backup files | |
ForEach ($Dcs in (Get-DcsServer)) {Invoke-Command -ComputerName $Dcs -ScriptBlock { | |
# Keep last x files - see $Keep for number of files to keep | |
# $Files is a variable which stores the filenames of all files that match *.cab | |
$Files = Get-ChildItem -Path $using:BackupFolder -Recurse | Where-Object {-not $_.PsIsContainer} | where {$_.name -like '*.zip'} | |
# Remove old files | |
$Files | Sort-Object CreationTime | Select-Object -First ($Files.Count - $using:Keep)| Remove-Item | |
} | |
} | |
# Set Backupfolder | |
ForEach ($Dcs in (Get-DcsServer)) {Set-DcsBackUpFolder -Server $Dcs -Folder $BackupFolder} | |
# Take Configbackup | |
Backup-DcsConfiguration | |
# Disconnect Server Group | |
Disconnect-DcsServer |
You can call the script using the Taskplanner with the following command:
powershell.exe -c "C:\Scripts\Backup-DataCoreConfig.ps1 | Out-Null"
You can select a different directory than C:\Scripts
. The “Out-Null” behind the pipe symbol suppresses the output of the script.