cancel
Showing results for 
Search instead for 
Did you mean: 

Restoring a single file from different backup images through CLI

King25may
Level 4

Hi,

I need to restore a file from a backup of each month (i.e jan, feb, march etc...) to the same folder. The name of the restored file should contain the backup date from which the file has been restored (i.e raja02282015). Ho w can I do this through Unix cli.? Can any one suggest me an idea?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

revarooo
Level 6
Employee

You stated you want the file from every month but you want the file renamed to the RESTORE date - that would result in 1 file!

you would need to script this and it's pretty tricky. I have used the date from the specificed date for restore not the date you are running the restore on but FROM

something like this might work. It's only as reliable as you restore success rates

 

We assume the restore will be from the 1st of the month.

I have made it so it only restore from Jan - Jun (01 to 06) and from 2014 - you can adjust this for your needs

 

I have left the restore for 30 minutes from the time it starts writing the file to the time it finishes - so you'd have to tweak this for your environment.

DAY=01
YEAR=2014

echo "change /tmp/test/hosts to /tmp/test/restore/raja" > /tmp/test/RENAME  # move the restore into /tmp/test/restore and not the original location

for MONTH in 01 02 03 04 05 06

do

bprestore -R /tmp/test/RENAME -s $MONTH/$DAY/$YEAR -e $MONTH/$DAY/$YEAR /tmp/test/raja

while true
do
if [ -f /tmp/test/restore/raja]  # if file exists (restore has started creating the file
then
 sleep 1800                           # wait for 30 minutes to allow restore to finish - then rename the file
 mv /tmp/test/restore/raja /tmp/test/raja$MONTH$DAY$YEAR
 exit 1
else                                     # otherwise continue looping
 echo "Restoring....."
fi
done

done

View solution in original post

13 REPLIES 13

revarooo
Level 6
Employee

You stated you want the file from every month but you want the file renamed to the RESTORE date - that would result in 1 file!

you would need to script this and it's pretty tricky. I have used the date from the specificed date for restore not the date you are running the restore on but FROM

something like this might work. It's only as reliable as you restore success rates

 

We assume the restore will be from the 1st of the month.

I have made it so it only restore from Jan - Jun (01 to 06) and from 2014 - you can adjust this for your needs

 

I have left the restore for 30 minutes from the time it starts writing the file to the time it finishes - so you'd have to tweak this for your environment.

DAY=01
YEAR=2014

echo "change /tmp/test/hosts to /tmp/test/restore/raja" > /tmp/test/RENAME  # move the restore into /tmp/test/restore and not the original location

for MONTH in 01 02 03 04 05 06

do

bprestore -R /tmp/test/RENAME -s $MONTH/$DAY/$YEAR -e $MONTH/$DAY/$YEAR /tmp/test/raja

while true
do
if [ -f /tmp/test/restore/raja]  # if file exists (restore has started creating the file
then
 sleep 1800                           # wait for 30 minutes to allow restore to finish - then rename the file
 mv /tmp/test/restore/raja /tmp/test/raja$MONTH$DAY$YEAR
 exit 1
else                                     # otherwise continue looping
 echo "Restoring....."
fi
done

done

King25may
Level 4

Thanks revarooo. Will try this

Nicolai
Moderator
Moderator
Partner    VIP   

FYI

if you use -w qualifyer for bprestore the command will not go into background.

http://www.symantec.com/docs/HOWTO103842

By default, you are returned to the system prompt after bprestore is successfully submitted. The command works in the background and does not return completion status directly to you. The -woption lets you change this behavior so bprestore works in the foreground and then returns completion status after a specified time period.

revarooo
Level 6
Employee

it does for me. See below, it returned to the prompt immediately and the job had not completed.

 


cyborg:/etc # bprestore /etc/hosts -w 0
cybord:/etc # 

 

Nicolai
Moderator
Moderator
Partner    VIP   

Switch those two around - File to restore must be last qualifyer.

I bet you got a policy restore error using that command :D

[root@ural ]# time bprestore -w  -L /tmp/restore.txt /home/acme/iperf

real    0m5.809s


[root@ural nma]# time bprestore  -L /tmp/restore.txt /home/acme/iperf

real    0m0.428s
 

 

King25may
Level 4

I've completed the scripts. Now I need to get the Restore job ids which I've started through the script.

I thought to get it from bpdbjobs output, I don't know how to grep the restore jobs I've started.

sdo
Moderator
Moderator
Partner    VIP    Certified

Looks like bprestore log contains the job ID:

13:32:44 (1865335.xxx) Restore job id 1865335 will require 1 image.

...so maybe you could use something like this in a script...

egrep "^..:..:.. \(.*\.xxx\) Restore job id .* will require .* imag.*" my-log-file-name.log | awk '{print $6}'

King25may
Level 4

I couldn't find the job id in bprestore log sdo.

 

Marianne
Level 6
Partner    VIP    Accredited Certified
Did you add a log file to your command with -L option? Can you post this log file? If more than about 10 lines, please upload as File attachment.

King25may
Level 4

No i didn't add a log file to the command. 

I've used a for loop to start n number of restore jobs. Do i need to specify single log file in the command or n number of log files?

 

Marianne
Level 6
Partner    VIP    Accredited Certified
If memory serves me right, a single log file can be used and will be appended to by each restore. Unfortunately not able to test and confirm...

King25may
Level 4

Okay I will check it. Actaully I had planned to get the restore job ids using bpdbjobs command. We can get the required job id by filtering the job type, client and start time colums using awk command. But i may be a long procedure

Nicolai
Moderator
Moderator
Partner    VIP   

The command i provided in my last post show a example of a log file. Referring it multiple time may render it almost unreadable because of the multiple job status.

bprestore -w  -L /tmp/restore.txt /home/acme/iperf

Using the -w option and bprestore will return Netbackup job status as exit status. This mean you will be able to tell if the restore went well inspection variable $? right after the command return to the shell.