Solved

run "post backup process" only backup ended successfully


Userlevel 1
Badge +6

Hi, is possible run script to delete files after backup if ended ok ?

Thanks

icon

Best answer by Sunil 12 May 2021, 09:21

View original

20 replies

Userlevel 3
Badge +6

Hi,

You can pass the job status as an argument to the post-process script. And you need to decide your business logic based on the status value.

Please check this documentation page and check the additional argument -status.

https://documentation.commvault.com/commvault/v11_sp20/article?p=12782.htm

 

Thanks,

Sunil-

Userlevel 7
Badge +23

Hey @ITStorageEWL

 @Sunil beat me to it!  You can set the pre/post process to run pretty much any script you can come up with.  You (or commonly, a vendor) have to create the script itself, and we can execute it (as the listed user in the config).

Assuming you’d set this to run AFTER the backup phase, then you likely won’t encounter any issues with premature deletion; however, if the backup is killed BEFORE the script portion runs, then you’ll likely the files sitting in place where you expected them to have been deleted.

Is your intent to stage files in a folder, have them get backed up, then delete them after (to clear the staging area)?

Thanks!

Userlevel 1
Badge +6

@Mike Struening 

 “Is your intent to stage files in a folder, have them get backed up, then delete them after (to clear the staging area)? “  YES

Userlevel 7
Badge +23

Ok, great!  This is a very common arrangement.

Some tips:

  • Make sure the user running the script has the rights required to delete from that location
  • Test it out first by creating a small subclient, or seeding some basic files in that folder
  • Consider what you’ll do if a backup fails before clearing out the folder (i.e. do you have plenty of space in case there are duplicates, or do you have something/part of the initial script clear it out before seeding?)

Here’s another thread where I shared some of my old troubleshooting techniques that will likely help you in testing:

Let me know if this answers your questions!

Userlevel 1
Badge +6

@Sunil sorry, do you have some examples? I am testing the solution, but probably I am wrong to pass the parameters...Thanks

post process

C:\Users\xxxx\Documents\echo.bat "-status 1"

 

Userlevel 7
Badge +23

While we wait for @Sunil I am going to send this page to our documentation team to see if we can get examples added for clarity!

Userlevel 1
Badge +6

@Mike Struening I did some more tests, it seems that in my case you don't have to insert any arguments.…

post process

C:\Users\xxxx\Documents\echo.bat

waiting for confirmation....

 

Userlevel 7
Badge +23

@ITStorageEWL you don’t HAVE to add in that parameter; it’s there if you want to force the script to make a more informed decision to only run IF a prior event succeeded/failed, etc.

You should be able to test it out with a VERY small subclient with some random text files thrown in.  Set the subclient to that folder only, set the script syntax to delete that folder’s content and run a full and see what happens.

Userlevel 1
Badge +6

@Mike Struening OK I'll try some more tests. Thanks

Userlevel 1
Badge +6

@Mike Struening does not work, the logs always show status 1, and it always runs the post process. 

the correct syntax is 

post process

C:\Users\xxxx\Documents\echo.bat "-status 1".

or 

post process

C:\Users\xxxx\Documents\echo.bat 

should the status be tested outside or inside the script? 

Thanks

Userlevel 7
Badge +23

@ITStorageEWL the status argument will only prevent the script running if the prior phase has failed.  Is the prior phase failing?  If the backup phase works (assuming this is a post backup script), then the script will run.

I’ll tag in @Sunil for any additional context.

You can always just do it within the script as you said, though it might be tougher to monitor the phase of the backup/scan, etc. 

 

Userlevel 7
Badge +23

@ITStorageEWL following up on this.  Were you able to get the script running as desired?

Userlevel 7
Badge +23

@ITStorageEWL , let me know if this is resolved or if you need more help.

Thanks!

Userlevel 1
Badge +6

@Mike Struening we have not solved it, we are still testing. 
Need to figure out how to intercept status 1 of the backup phase.It would be interesting to find practical examples of both linux and windows.
Thanks

Userlevel 7
Badge +23

@Sunil , do you have any examples of a script using the status argument?

Userlevel 3
Badge +6

Let me try it in the lab setup and get back.

Userlevel 1
Badge +6

hi guys, @Sunil @Mike Struening any news? 

 

Thanks

Userlevel 3
Badge +6

Hi @ITStorageEWL 

 

Sorry for the delay. Here is the example.

 

The Job Manager launches the command with the below arguments.

-bkplevel 1 -attempt 1 -status 1 -job 4

 

We are trying to access the 6th argument in the list for getting the job status.

 

I’ve created a sample script with this content.

D:\PostBackup>type postbackup.cmd

IF %6==1 (
  echo "Backup Phase succeeded" >> C:\postBackup.log
)ELSE IF %6==2 (
  echo "Backup Phase failed" >> C:\postBackup.log
)

echo %1 >> C:\postBackup.log
echo %2 >> C:\postBackup.log
echo %3 >> C:\postBackup.log
echo %4 >> C:\postBackup.log
echo %5 >> C:\postBackup.log
echo %6 >> C:\postBackup.log

 

And the script output from C:\postBackup.log is this.

"Backup Phase succeeded" 
-bkplevel 

-attempt 

-status 

 

This is how the script is configured in the subclient properties:

 

That’s all.

 

You can use %6 argument to access the jobStatus code inside your script.

So you can check IF %6==1 and delete the files you wanted to delete.

 

Thanks,

Sunil-

Userlevel 1
Badge +6

Thanks @Sunil 

I did some testing, this way the backup phase is not tested. In some cases if the job is killed the status is 1 and the post process starts. 

Userlevel 7
Badge +23

Thanks, @Sunil !

@ITStorageEWL , feel free to mark his reply as the Best Answer if it satisfies your needs :sunglasses:

Reply