# Db2 11.1 for Windows Powershell Backup Script

#### Daniel Luksetich

Db2 11.1 for Windows Powershell Backup Script
Hello,
Does anyone have an example of doing a DB2 database backup on Windows
using a Powershell script. I'm having a heck of a time with error
handling. I can do backup without issue, but can't catch errors.
Dan

#### Daniel Luksetich

Db2 11.1 for Windows Powershell Backup Script
(in response to Daniel Luksetich)
OK, let's simplify my request. All I want to do is handle errors...

here is an example:
prompting" >> \$Log

there is no DOLADAX database and so the backup fails. If I do this in a
Windows bat job, the %ERRORLEVEL% variable is set on error.

In PowerShell I've tried \$error.Count, \$_, \$error[0] and Try/Catch. It's
not working. I'm trying to keep the scripts simple because we are all
PowerShell novices here. I know I can parse the file that is \$Log to
check for errors, but was hoping for something simpler.

Thanks,
Dan

On 10.05.2017 07:18, Daniel Luksetich wrote:
> Hello,
> Does anyone have an example of doing a DB2 database backup on Windows
> using a Powershell script. I'm having a heck of a time with error
> handling. I can do backup without issue, but can't catch errors.
> Dan
>
> -----End Original Message-----

#### Daniel Luksetich

Db2 11.1 for Windows Powershell Backup Script
(in response to Daniel Luksetich)
I think I found it! \$LastExitCode. Also, apparently \$? (true/false) will
work as well.
Dan

On 10.05.2017 09:01, Daniel Luksetich wrote:
> OK, let's simplify my request. All I want to do is handle errors...
>
> here is an example:
> prompting" >> \$Log
>
> there is no DOLADAX database and so the backup fails. If I do this in a
> Windows bat job, the %ERRORLEVEL% variable is set on error.
>
> In PowerShell I've tried \$error.Count, \$_, \$error[0] and Try/Catch.
> It's
> not working. I'm trying to keep the scripts simple because we are all
> PowerShell novices here. I know I can parse the file that is \$Log to
> check for errors, but was hoping for something simpler.
>
> Thanks,
> Dan
>
>
> On 10.05.2017 07:18, Daniel Luksetich wrote:
>> Hello,
>> Does anyone have an example of doing a DB2 database backup on Windows
>> using a Powershell script. I'm having a heck of a time with error
>> handling. I can do backup without issue, but can't catch errors.