Highlighted
Absent Member.. Absent Member..
Absent Member..
342 views

NPS database backup

Jump to solution

Hi folks

I put together a PowerShell script to run in Task Scheduler to backup the NPS database. The script errors saying the backup command (backup.ovpl) requires a directory (-b). Are there limitations is using environment vairables with this command? Suggestions are welcome, new to PowerShell scripting here.

Thanks
-LB

$npsBackup = ("C:\Program Files (x86)\HP\HP BTO Software\NNMPerformanceSPI\bin\backup.ovpl")
$emailCmd = ("C:\Program Files (x86)\Blat\blat.exe")
$npsBackupDir = ("D:\nps-database-backup")
$outFile = "C:\Temp\npsBackup.out"
$emailUser = "someUser@domain.com"

if($?)
{
echo "" >> $outFile
echo "=========" >> $outFile
echo "NPS Database Backup Completed Successfully" >> $outFile
echo "=========" >> $outFile
echo "" >> $outFile
& cmd /c $npsBackup –b $npsBackupDir >> $outFile 2>&1
& cmd /c $emailCmd $outfile -to $emailUser
& cmd /c del $outFile
}
else
{
echo "" >> $outFile
echo "=========" >> $outFile
echo "NPS Database Backup Failed, check output file $outFile" >> $outFile
echo "=========" >> $outFile
}

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: NPS database backup

Jump to solution

The task completed successfully in Taks Scheduler. Below is the finished script and procedures I used to add the script to Task Scheduler. With the backups being so large in size I will probably add some logic to remove files older than x days.

$npsBackup = ("C:\Program Files (x86)\HP\HP BTO Software\NNMPerformanceSPI\bin\backup.ovpl")
$emailCmd = ("C:\Program Files (x86)\Blat\blat.exe")
$npsBackupDir = ("D:\nps-database-backup")
$outFile = "C:\Temp\npsBackup.out"
$emailUser = "larry.buss@hpe.com"

if($?)
{
 echo "" >> $outFile
 echo "=========" >> $outFile
 echo "NPS Database Backup Completed Successfully `r" >> $outFile
 echo "=========" >> $outFile
 echo "" >> $outFile
 & cmd /c "$npsBackup" -b $npsBackupDir >> $outFile 2>&1
 & cmd /c $emailCmd $outfile -to $emailUser
 & cmd /c del $outFile
}
else
{
 echo "" >> $outFile
 echo "=========" >> $outFile
 echo "NPS Database Backup Failed, check output file $outFile" >> $outFile
 echo "=========" >> $outFile
}

================

Task Scheduler steps.

Task Scheduler -> Create Task, Enter a name for the task
General tab -> Security Options, Enter the user account that will run the task. Change the settings to run if the user is logged in or not.
Triggers -> New, Select "On Schedule", choose date/time/frequency
Actions -> New, Select "Start a Program", In the Program/script field enter "PowerShell"
In the Add arguements field enter the value ".\Scriptname.ps1"
In the Start in field, enter the location (folder) that contains your script (i.e. c:\Scripts)
Click OK
Configure other settings in the Conditions and Settings tabs, if desired.
Click OK. The Task is configured and ready to run.

 

Cheers
-LB

 

View solution in original post

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: NPS database backup

Jump to solution

Hi Labuss,

Does the PowerShell script fail only when run via the Task Scheduler, or does it fail even when run manually?

In case if fails only when run via the task scheduler, you may want to refer to following discussion thread:

https://blogs.technet.microsoft.com/heyscriptingguy/2012/08/11/weekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script/

In case it fails even when run from command prompt, you may want to try adding double quotes in the cmd statement just in case, such as:

& cmd /c "$npsBackup –b $npsBackupDir >> $outFile 2>&1"

All the best

Marie-Noelle

Micro Focus Customer Support

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.

If you are satisfied with anyone’s response please remember to give them KUDOS and show your appreciation.
0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: NPS database backup

Jump to solution

Thanks for your suggestion. Actually enclosing the $npsBackup variable in quotes resolved the issue I was having. The script runs to completion now. I've configured it to run in Task Scheduler so I'll see how things go in the morning.

Thanks

-LB

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: NPS database backup

Jump to solution

Excellent.  Thanks for sharing the end of the story.

Please don't forget to mark any appropriate solution as Accepted Solution so that we could close the corresponding discussion thread and that our community members could go straight forward to the solution while searching through the forum.

All the best

Marie-Noelle

Micro Focus Customer Support

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.

If you are satisfied with anyone’s response please remember to give them KUDOS and show your appreciation.
0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: NPS database backup

Jump to solution

The task completed successfully in Taks Scheduler. Below is the finished script and procedures I used to add the script to Task Scheduler. With the backups being so large in size I will probably add some logic to remove files older than x days.

$npsBackup = ("C:\Program Files (x86)\HP\HP BTO Software\NNMPerformanceSPI\bin\backup.ovpl")
$emailCmd = ("C:\Program Files (x86)\Blat\blat.exe")
$npsBackupDir = ("D:\nps-database-backup")
$outFile = "C:\Temp\npsBackup.out"
$emailUser = "larry.buss@hpe.com"

if($?)
{
 echo "" >> $outFile
 echo "=========" >> $outFile
 echo "NPS Database Backup Completed Successfully `r" >> $outFile
 echo "=========" >> $outFile
 echo "" >> $outFile
 & cmd /c "$npsBackup" -b $npsBackupDir >> $outFile 2>&1
 & cmd /c $emailCmd $outfile -to $emailUser
 & cmd /c del $outFile
}
else
{
 echo "" >> $outFile
 echo "=========" >> $outFile
 echo "NPS Database Backup Failed, check output file $outFile" >> $outFile
 echo "=========" >> $outFile
}

================

Task Scheduler steps.

Task Scheduler -> Create Task, Enter a name for the task
General tab -> Security Options, Enter the user account that will run the task. Change the settings to run if the user is logged in or not.
Triggers -> New, Select "On Schedule", choose date/time/frequency
Actions -> New, Select "Start a Program", In the Program/script field enter "PowerShell"
In the Add arguements field enter the value ".\Scriptname.ps1"
In the Start in field, enter the location (folder) that contains your script (i.e. c:\Scripts)
Click OK
Configure other settings in the Conditions and Settings tabs, if desired.
Click OK. The Task is configured and ready to run.

 

Cheers
-LB

 

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.