02-27-2015 11:47 PM
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?
Solved! Go to Solution.
02-28-2015 03:59 AM
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
02-28-2015 03:59 AM
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
02-28-2015 08:23 PM
Thanks revarooo. Will try this
03-01-2015 01:12 AM
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.
03-01-2015 02:33 AM
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 #
03-02-2015 06:24 AM
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
03-28-2015 11:29 AM
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.
03-28-2015 01:07 PM
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}'
03-30-2015 09:04 PM
I couldn't find the job id in bprestore log sdo.
03-30-2015 09:16 PM
03-30-2015 09:39 PM
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?
03-30-2015 11:01 PM
03-30-2015 11:26 PM
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
03-31-2015 08:11 AM
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.