Saturday, 25 October 2014

WFA: Backup.ps1 “Invalid Credentials Specified, Cannot take a Backup”

On a newly installed OnCommand Workflow Automation 2.2 box, I was setting up scheduled backups of the database using the provided Backup.ps1, but was encountering difficulties:

PS D:\Program Files\NetApp\WFA\bin>
.\Backup.ps1 -User backup -Password backup

Invalid credentials specified, cannot take a backup!

Note: By default WFA takes daily backup at 2 am, and retains the latest 2 in the {INSTALL_DRIVE}:\Program Files\NetApp\WFA-Backups.

I knew the credentials were definitely correct as could log into - http://localhost/rest/backups - with the same credentials and download the backup file with no issue. Also, I’d used this process before when upgrading from WFA 2.2RC1 to WFA 2.2 GA and it had worked fine, so maybe something changed in the WFA 2.2 GA release!?

After a while scratching my head ... I was looking at the Backup.ps1 script, and it occurred to me that we can do this in another way with PowerShell 3’s Invoke-WebRequest (Windows 2012+ come with PowerShell 3 pre-installed.)


We’re going to supply the username, password, and backup location in the script, for ease of getting the script setup on an Enterprise Scheduled Task Management system (backup can only do backup anyway!) Also, we know we’re using the default port 80 for HTTP and the backup folder already exists - which makes our script super simple! Copy the content below into a text editor and save as say Backup-WFA.ps1 in the WFA\bin folder.


# Handle credentials
$User = "backup"
$Pass = "backup"
$SecP = $Pass | ConvertTo-SecureString  -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PsCredential($User,$SecP)

# Handle Backup Folder, File and Path
$Folder   = "D:\Backups\"
$File     = "wfa_backup." + (Get-Date -Format "yyyyMMddHHmmss") + ".sql.gz"
$FilePath = $Folder + $File

# Invoke-WebRequest
[Void](Invoke-WebRequest -Uri http://localhost/rest/backups -OutFile $FilePath -Credential $Cred)


Note: Backup.ps1 also uses System.Management.Automation.PsCredential

The Proof that the Backups Work!

After running a backup using Backup-WFA.ps1:

PS D:\Program Files\NetApp\WFA\bin>

We login to http://localhost/wfa/ > Administration > Backup & Restore

Image: WFA > Backup & Restore

Browse to our newly backed up WFA database file, and hit the Restore button. If all is good we are greeted with “Successfully restored WFA’s database”!

Image: Successfully restoring the WFA database
Running Backup-WFA.ps1 from the Command Prompt

Before getting this to run as a scheduled task, we first check this will run via the DOS Command Prompt:

powershell.exe -File "D:\Program Files\NetApp\WFA\bin\Backup-WFA.ps1" -ExecutionPolicy Bypass

Running Backup-WFA.ps1 from Task Scheduler

Pretty much as above, with:

Program/script =

Arguments =
-File "D:\Program Files\NetApp\WFA\bin\Backup-WFA.ps1" -ExecutionPolicy Bypass

Image: Task Scheduler Action to run Backup-WFA.ps1
And test it runs!


No comments:

Post a Comment