cancel
Showing results for 
Search instead for 
Did you mean: 

Need a script or command to extend expiration dates

Dollypee
Moderator
Moderator
   VIP    Certified

NBU version : 7.6.0.3

 

I have a task to extend SQL database backup image expiration date. I've got close to 160 backup IDs on this regards.

Can any one help with a script or command to complete this task at ones? Will greatly appreciate your help

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions

sdo
Moderator
Moderator
Partner    VIP    Certified

Ok - let me know how the date breaking test goes.

Back here, I've added code to do the actual expiry date reset (which I have tested) - but the version of the script with teh actual expiry date reset code in it... I have not shared with you yet... as I want to be sure that it correctly detects that you are running with U.S. dates.

So, I'll let you get on with testing.

In the meantime... here's an example log of the script running on my test rig:

> reset-expiration.bat
16/04/2015 14:43:05
16/04/2015 14:43:05  Checking for presence of NetBackup...
16/04/2015 14:43:05  ...found NetBackup ok...
16/04/2015 14:43:05  ...client name:   myserver
16/04/2015 14:43:05  ...type:          NetBackup Master Server
16/04/2015 14:43:05  ...path:          C:\Program Files\Veritas\
16/04/2015 14:43:05  ...done...
16/04/2015 14:43:05
16/04/2015 14:43:05  Checking input image list...
16/04/2015 14:43:05  ...image `myserver_1428854028` has `1` copies...
16/04/2015 14:43:06  ...image `myserver_1428858281` has `1` copies...
16/04/2015 14:43:06  ...file has `2` entries, and found `2` images...
16/04/2015 14:43:06  ...done...
16/04/2015 14:43:06
16/04/2015 14:43:06  Determining date format for bpexpdate...
16/04/2015 14:43:06  ...bpexpdate format is `dd/mm/yyyy`...
16/04/2015 14:43:06  ...bpexpdate date format is UK...
16/04/2015 14:43:06  ...year has `4` digits...
16/04/2015 14:43:06  ...done...
16/04/2015 14:43:06
16/04/2015 14:43:06  _Enter new expiry date in format `dd/mm/yyyy`, or `infinity` [EXIT] :  01/01/2017
16/04/2015 14:43:17  ...admin entered `01/01/2017`...
16/04/2015 14:43:17
16/04/2015 14:43:17  Checking entry is a valid date...
16/04/2015 14:43:17  ...expiry date of `01/01/2017` appears to be valid...
16/04/2015 14:43:17  ...done...
16/04/2015 14:43:17
16/04/2015 14:43:17  Comparing to today's date...
16/04/2015 14:43:17  ...date appears to be a valid future date...
16/04/2015 14:43:17  ...done...
16/04/2015 14:43:17
16/04/2015 14:43:17  _Are you really sure to set expiry to `01/01/2017 23:59:59` (YESIAMSURE,EXIT) [EXIT] :  YESIAMSURE
16/04/2015 14:43:23  ...admin entered `YESIAMSURE`...
16/04/2015 14:43:23  ...done...
16/04/2015 14:43:23
16/04/2015 14:43:23  Expiry of images will be set to `01/01/2017 23:59:59`...
16/04/2015 14:43:24  ...expiry reset on image `myserver_1428854028`...
16/04/2015 14:43:24  ...expiry reset on image `myserver_1428858281`...
16/04/2015 14:43:24  ...found `2` images, and reset `2` images...
16/04/2015 14:43:24  ...done...
16/04/2015 14:43:24
16/04/2015 14:43:24  Script exiting...

Press any key to continue . . .

View solution in original post

14 REPLIES 14

sdo
Moderator
Moderator
Partner    VIP    Certified

1) Do you have Windows master server?

2) Is the list of c. 160 images already in a text file, of just image IDs?

3) Or does the script need to include some logic to select the images via certain criteria - e.g. by client name, policy name, schedule name, date range?

X2
Moderator
Moderator
   VIP   

I would start with https://www.symantec.com/business/support/index?page=content&id=TECH28114

and write a wrapper script which reads BackupIDs from your list and updates the expiry date

Dollypee
Moderator
Moderator
   VIP    Certified

I do have windows master server: WIN2K8R2

I can also have all the backup IDs copy into a text file.

Would appreciate a script to look into the text file and extend the images expiration accordinly. Thanks

sdo
Moderator
Moderator
Partner    VIP    Certified

Ok - I'll do a script.  But it won't be short.  But it should be easy follow.  It won't be short, because I feel compelled to include lots of date checking type logic, to make sure that it really really really does get the new 'expiry' date in the correct format - i.e. less "chance" for an accident - "chance" being the operative word here.

Do you need it very quickly?  Are the images about to expire within the next few hours?

I ask because it will take an hour, maybe two, to write the script.

If you need something quickly - then I could knock something dirty up - but there's risk of dates being in the wrong layout.  You're in U.S. right?

Dollypee
Moderator
Moderator
   VIP    Certified

Images will expire by Fri 17th of April. They need to be extended to next 3 months. Thanks for your help, looking forward to your feedback. Yes am in US on EST time. Thanks

sdo
Moderator
Moderator
Partner    VIP    Certified

Ok mate.  Try the attached.  It does not actually do the reset of the expiry date.  I have not put that code in yet.

Create a folder, like:

D:\Scripts\reset-expiration\

save the attached as reset-expiration.bat

create an input file in the same folder named "reset-expiration.inp", containing a list of images.

.

What I would like you to do is test it... try to break it... try running it as if you really were trying to use it properly, but more importantly test it by entering all manner of goofy input and goofy dates.

See if you can break it  :)

We need to be certain of it's date handling ability BEFORE we put the code in to actually reset the expiry date.

It is safe to run as it stands - as it does not yet do any actual expiry reset of any images.

Thanks.

sdo
Moderator
Moderator
Partner    VIP    Certified

I'll pick this up again tomorrow morning UK time.

DG-2005
Level 5

Just something I had lying around. read the bpexpdate and make sure you understand it completely BEFORE running this. 

 

ForEach ($system in Get-Content "imagelist.txt"){
Write-Host "============================================================" -ForegroundColor "Yellow" 
Write-Host $system Retention change
Write-Host "============================================================" -ForegroundColor "Yellow" 
Write-Host ""
bpexpdate -recalculate -backupid $system -ret [0-9] -force -copy 1
bpimagelist -backupid $system -L | Select-String "Expiration Time:|Sched Label"
}

 

 

 

sdo
Moderator
Moderator
Partner    VIP    Certified

 

The copy number is a good pointer... so thanks for that.

Dolly, dude, the images that need to be reset, is there only the one copy for each image?  Or are there multiple copies?  If there are multiple copies... then do all copies need their expiry reset.. or just certain copies?

Dollypee
Moderator
Moderator
   VIP    Certified

Hi SDO, thanks for your help and following up. I will be testing the script today. I believe if you have to extend all copies, there wont be need of specifying copy right? The intention is to extend all 3 copies that I have. Thank you.

sdo
Moderator
Moderator
Partner    VIP    Certified

Ok - let me know how the date breaking test goes.

Back here, I've added code to do the actual expiry date reset (which I have tested) - but the version of the script with teh actual expiry date reset code in it... I have not shared with you yet... as I want to be sure that it correctly detects that you are running with U.S. dates.

So, I'll let you get on with testing.

In the meantime... here's an example log of the script running on my test rig:

> reset-expiration.bat
16/04/2015 14:43:05
16/04/2015 14:43:05  Checking for presence of NetBackup...
16/04/2015 14:43:05  ...found NetBackup ok...
16/04/2015 14:43:05  ...client name:   myserver
16/04/2015 14:43:05  ...type:          NetBackup Master Server
16/04/2015 14:43:05  ...path:          C:\Program Files\Veritas\
16/04/2015 14:43:05  ...done...
16/04/2015 14:43:05
16/04/2015 14:43:05  Checking input image list...
16/04/2015 14:43:05  ...image `myserver_1428854028` has `1` copies...
16/04/2015 14:43:06  ...image `myserver_1428858281` has `1` copies...
16/04/2015 14:43:06  ...file has `2` entries, and found `2` images...
16/04/2015 14:43:06  ...done...
16/04/2015 14:43:06
16/04/2015 14:43:06  Determining date format for bpexpdate...
16/04/2015 14:43:06  ...bpexpdate format is `dd/mm/yyyy`...
16/04/2015 14:43:06  ...bpexpdate date format is UK...
16/04/2015 14:43:06  ...year has `4` digits...
16/04/2015 14:43:06  ...done...
16/04/2015 14:43:06
16/04/2015 14:43:06  _Enter new expiry date in format `dd/mm/yyyy`, or `infinity` [EXIT] :  01/01/2017
16/04/2015 14:43:17  ...admin entered `01/01/2017`...
16/04/2015 14:43:17
16/04/2015 14:43:17  Checking entry is a valid date...
16/04/2015 14:43:17  ...expiry date of `01/01/2017` appears to be valid...
16/04/2015 14:43:17  ...done...
16/04/2015 14:43:17
16/04/2015 14:43:17  Comparing to today's date...
16/04/2015 14:43:17  ...date appears to be a valid future date...
16/04/2015 14:43:17  ...done...
16/04/2015 14:43:17
16/04/2015 14:43:17  _Are you really sure to set expiry to `01/01/2017 23:59:59` (YESIAMSURE,EXIT) [EXIT] :  YESIAMSURE
16/04/2015 14:43:23  ...admin entered `YESIAMSURE`...
16/04/2015 14:43:23  ...done...
16/04/2015 14:43:23
16/04/2015 14:43:23  Expiry of images will be set to `01/01/2017 23:59:59`...
16/04/2015 14:43:24  ...expiry reset on image `myserver_1428854028`...
16/04/2015 14:43:24  ...expiry reset on image `myserver_1428858281`...
16/04/2015 14:43:24  ...found `2` images, and reset `2` images...
16/04/2015 14:43:24  ...done...
16/04/2015 14:43:24
16/04/2015 14:43:24  Script exiting...

Press any key to continue . . .

sdo
Moderator
Moderator
Partner    VIP    Certified

I think I can be accused of seriously over-cooking the ham.

Let's keep it simple.

Put your list of backup IDs in a file named images.lis

...and save these lines to a file named something like my-reset.bat

@echo on
for /f "tokens=1" %%a in ('type "images.lis"') do (
  bpexpdate -backupid %%a -d 07/31/2015 -force
)
exit /b

...and then run my-reset.bat.

When all is done.  Make sure that you rename the file my-reset.bat to my-reset.txt - so that it doesn't accdentally get run again.  Or edit it and change the date to MM/DD/YYYY - so that if it does get accidentally run again, then it won't do anything harmful.

HTH.

Dollypee
Moderator
Moderator
   VIP    Certified

Hi SDO,

I just tested the 1st script and works fine. Except the fact that code not in yet. Please see below :

 

 

D:\script>reset-expiration.bat
Thu 04/16/2015 11:46:06
Thu 04/16/2015 11:46:06  Checking for presence of NetBackup...
Thu 04/16/2015 11:46:06  ...found NetBackup ok...
Thu 04/16/2015 11:46:06  ...client name:   crppms1nbudev0.nychhc.org
Thu 04/16/2015 11:46:06  ...type:          NetBackup Master Server
Thu 04/16/2015 11:46:06  ...path:          D:\Program Files\Veritas\
Thu 04/16/2015 11:46:06  ...done...
Thu 04/16/2015 11:46:06
Thu 04/16/2015 11:46:06  Checking input image list...
Thu 04/16/2015 11:46:06  ...file has `1` entries, and found `1` images...
Thu 04/16/2015 11:46:06  ...done...
Thu 04/16/2015 11:46:06
Thu 04/16/2015 11:46:06  Determining date format for bpexpdate...
Thu 04/16/2015 11:46:07  ...bpexpdate format is `mm/dd/yyyy`...
Thu 04/16/2015 11:46:07  ...bpexpdate date format in US...
Thu 04/16/2015 11:46:07  ...year has `4` digits...
Thu 04/16/2015 11:46:07  ...done...
Thu 04/16/2015 11:46:07
Thu 04/16/2015 11:46:07  _Enter new expiry date in format `mm/dd/yyyy`, or `infinity` [EXIT] :  5/16/2015
Thu 04/16/2015 11:47:00  ...admin entered `5/16/2015`...
Thu 04/16/2015 11:47:00
Thu 04/16/2015 11:47:00  Checking entry is a valid date...
Thu 04/16/2015 11:47:00  ...entry has bad first structure, try again...
Thu 04/16/2015 11:47:00
Thu 04/16/2015 11:47:00  _Enter new expiry date in format `mm/dd/yyyy`, or `infinity` [EXIT] :  05/16/2015
Thu 04/16/2015 11:47:27  ...admin entered `05/16/2015`...
Thu 04/16/2015 11:47:27
Thu 04/16/2015 11:47:27  Checking entry is a valid date...
Thu 04/16/2015 11:47:27  ...expiry date of `05/16/2015` appears to be valid...
Thu 04/16/2015 11:47:27  ...done...
Thu 04/16/2015 11:47:27
Thu 04/16/2015 11:47:27  Comparing to today's date...
Thu 04/16/2015 11:47:27  ...date appears to be a valid future date...
Thu 04/16/2015 11:47:27  ...done...
Thu 04/16/2015 11:47:27
Thu 04/16/2015 11:47:27  _Are you really sure to set expiry to `05/16/2015 23:59:59` (YESIAMSURE,EXIT) [EXIT] :  YES
Thu 04/16/2015 11:47:41  ...admin entered `YES`...
Thu 04/16/2015 11:47:41  ...invalid input, try again...
Thu 04/16/2015 11:47:41
Thu 04/16/2015 11:47:41  _Are you really sure to set expiry to `05/16/2015 23:59:59` (YESIAMSURE,EXIT) [EXIT] :  YESIAMSURE
Thu 04/16/2015 11:47:54  ...admin entered `YESIAMSURE`...
Thu 04/16/2015 11:47:54
Thu 04/16/2015 11:47:54  Expiry would be set to `05/16/2015 23:59:59`...
Thu 04/16/2015 11:47:54  ...however code is not yet implemented...
Thu 04/16/2015 11:47:54
Thu 04/16/2015 11:47:54  Script exiting...

Press any key to continue . . .

sdo
Moderator
Moderator
Partner    VIP    Certified

Ok - it appeared to work.  Let's continue via PM.