Need help in creating file restoration script from a backup script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in creating file restoration script from a backup script.
# 1  
Old 12-01-2011
MySQL Need help in creating file restoration script from a backup script.

Hi all

i am struggling in creating a restore of env files while doing applications clone.
the first file i created for copying the important configurations file
which is running perfect
now for reverting the changes i mean when i am restoring these files to its original places
i have to do manual woking

i use this command to create a restore file
Code:
grep -i cp abc.sh |awk '{print $1 " " $3 "                   " $2}'

but after doing this also i have to lots of manual cuttings filterings
i need to cut the last part of 3rd column and then past it in last of 2nd column

can i have your valuble suggestions to do this work through an command or script.
it would be a great help.


backup script:
###########
Code:
[appxdb72@pks19jkp]/fsaixxdb72/applmgr/pgbcxdb72> cat abc.sh

BKPDIR=/patch/bak_`uname`/bak_${ORASID}_`date +%d%b%Y`
export BKPDIR


mkdir -p $BKPDIR/appl $BKPDIR/comn $BKPDIR/8.0.6 $BKPDIR/iAS $BKPDIR/db
chmod -Rf 777 $BKPDIR/db


cp $APPL_TOP/*.env                              $BKPDIR/appl
cp $APPL_TOP/admin/*.env                          $BKPDIR/appl
cp $APPL_TOP/admin/*.xml                          $BKPDIR/appl
cp $APPL_TOP/admin/topfile*                          $BKPDIR/appl
cp $APPL_TOP/admin/*def*                          $BKPDIR/appl
cp $FND_TOP/resource/pasta*                          $BKPDIR/appl
cp $FND_TOP/resource/ixlib*                          $BKPDIR/appl
cp $MSC_TOP/bin/MSCPLD.sh                         $BKPDIR/appl
cp $ORACLE_HOME/*.env                             $BKPDIR/8.0.6
cp $TNS_ADMIN/listener.ora                          $BKPDIR/8.0.6
cp $TNS_ADMIN/tnsnames.ora                          $BKPDIR/8.0.6
cp $ORACLE_HOME/guicommon6/tk60/admin/uifont.ali              $BKPDIR/8.0.6
cp $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/adautocfg.sh          $BKPDIR/comn
cp $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/adcmctl.sh          $BKPDIR/comn
cp $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/oai_x_ftp.sh         $BKPDIR/comn
cp $OA_HTML/bin/appsweb*.cfg                          $BKPDIR/comn
cp $IAS_ORACLE_HOME/*.env                         $BKPDIR/iAS
cp $IAS_ORACLE_HOME/network/admin/${CONTEXT_NAME}/*.ora          $BKPDIR/iAS
cp $IAS_ORACLE_HOME/Apache/Jserv/servlets/buildFileMoverServlet.sh     $BKPDIR/iAS
cp $IAS_ORACLE_HOME/Apache/Jserv/servlets/FileMoverServlet*         $BKPDIR/iAS
[appxdb72@pks19jkp]/fsaixxdb72/applmgr/pgbcxdb72>

Restoration command:
#################
Code:
[appxdb72@pks19jkp]/fsaixxdb72/applmgr/pgbcxdb72>    grep -i cp abc.sh |awk '{print $1 " " $3 "                   " $2}'
cp $BKPDIR/appl                         $APPL_TOP/*.env
cp $BKPDIR/appl                         $APPL_TOP/admin/*.env
cp $BKPDIR/appl                         $APPL_TOP/admin/*.xml
cp $BKPDIR/appl                         $APPL_TOP/admin/topfile*
cp $BKPDIR/appl                         $APPL_TOP/admin/*def*
cp $BKPDIR/appl                         $FND_TOP/resource/pasta*
cp $BKPDIR/appl                         $FND_TOP/resource/ixlib*
cp $BKPDIR/appl                         $MSC_TOP/bin/MSCPLD.sh
cp $BKPDIR/8.0.6                        $ORACLE_HOME/*.env
cp $BKPDIR/8.0.6                        $TNS_ADMIN/listener.ora
cp $BKPDIR/8.0.6                        $TNS_ADMIN/tnsnames.ora
cp $BKPDIR/8.0.6                        $ORACLE_HOME/guicommon6/tk60/admin/uifont.ali
cp $BKPDIR/comn                         $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/adautocfg.sh
cp $BKPDIR/comn                         $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/adcmctl.sh
cp $BKPDIR/comn                         $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/oai_x_ftp.sh
cp $BKPDIR/comn                         $OA_HTML/bin/appsweb*.cfg
cp $BKPDIR/iAS                          $IAS_ORACLE_HOME/*.env
cp $BKPDIR/iAS                          $IAS_ORACLE_HOME/network/admin/${CONTEXT_NAME}/*.ora
cp $BKPDIR/iAS                          $IAS_ORACLE_HOME/Apache/Jserv/servlets/buildFileMoverServlet.sh
cp $BKPDIR/iAS                          $IAS_ORACLE_HOME/Apache/Jserv/servlets/FileMoverServlet*
[appxdb72@pks19jkp]/fsaixxdb72/applmgr/pgbcxdb72>

my requirement looks like this
################################
Code:
cp     $BKPDIR/appl/*.env                               $APPL_TOP
cp     $BKPDIR/appl/*.env                                $APPL_TOP/admin
cp     $BKPDIR/appl/*.xml                                $APPL_TOP/admin
cp     $BKPDIR/appl/topfile*                             $APPL_TOP/admin
cp     $BKPDIR/appl/*def*                                $APPL_TOP/admin
cp     $BKPDIR/appl/pasta*                               $FND_TOP/resource
cp     $BKPDIR/appl/ixlib*                                 $FND_TOP/resource
cp     $BKPDIR/appl/MSCPLD.sh                     $MSC_TOP/bin
cp     $BKPDIR/8.0.6/*.env                               $ORACLE_HOME
cp     $BKPDIR/8.0.6/listener.ora                       $TNS_ADMIN
cp     $BKPDIR/8.0.6/tnsnames.ora                    $TNS_ADMIN
cp     $BKPDIR/8.0.6/uifont.ali                           $ORACLE_HOME/guicommon6/tk60/admin
cp     $BKPDIR/comn/adautocfg.sh                    $COMMON_TOP/admin/scripts/${CONTEXT_NAME}
cp     $BKPDIR/comn/adcmctl.sh                       $COMMON_TOP/admin/scripts/${CONTEXT_NAME}
cp     $BKPDIR/comn/oai_x_ftp.sh                     $COMMON_TOP/admin/scripts/${CONTEXT_NAME}
cp     $BKPDIR/comn/appsweb*.cfg                  $OA_HTML/bin
cp     $BKPDIR/iAS/*.env                                  $IAS_ORACLE_HOME
cp     $BKPDIR/iAS/*.ora                                  $IAS_ORACLE_HOME/network/admin/${CONTEXT_NAME}
cp     $BKPDIR/iAS/buildFileMoverServlet.sh    $IAS_ORACLE_HOME/Apache/Jserv/servlets
cp     $BKPDIR/iAS/FileMoverServlet*              $IAS_ORACLE_HOME/Apache/Jserv/servlets



Thanks & Regards

Syed Kaleemuddin.



Moderator's Comments:
Mod Comment How to use code tags

Last edited by zaxxon; 12-01-2011 at 07:49 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 12-01-2011
This might work..
Code:
awk  '/^cp/ { n= split($2,A,"/"); s=A[n];  printf ("%s/%s ",$3,s); for (i=1;i<n;i++) {printf ("%s/",A[i])} print j}' abc.sh


output:

Code:
$BKPDIR/appl/*.env $APPL_TOP/
$BKPDIR/appl/*.env $APPL_TOP/admin/
$BKPDIR/appl/*.xml $APPL_TOP/admin/
$BKPDIR/appl/topfile* $APPL_TOP/admin/
$BKPDIR/appl/*def* $APPL_TOP/admin/
$BKPDIR/appl/pasta* $FND_TOP/resource/
$BKPDIR/appl/ixlib* $FND_TOP/resource/
$BKPDIR/appl/MSCPLD.sh $MSC_TOP/bin/
$BKPDIR/8.0.6/*.env $ORACLE_HOME/
$BKPDIR/8.0.6/listener.ora $TNS_ADMIN/
$BKPDIR/8.0.6/tnsnames.ora $TNS_ADMIN/
$BKPDIR/8.0.6/uifont.ali $ORACLE_HOME/guicommon6/tk60/admin/
$BKPDIR/comn/adautocfg.sh $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/
$BKPDIR/comn/adcmctl.sh $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/
$BKPDIR/comn/oai_x_ftp.sh $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/
$BKPDIR/comn/appsweb*.cfg $OA_HTML/bin/
$BKPDIR/iAS/*.env $IAS_ORACLE_HOME/
$BKPDIR/iAS/*.ora $IAS_ORACLE_HOME/network/admin/${CONTEXT_NAME}/
$BKPDIR/iAS/buildFileMoverServlet.sh $IAS_ORACLE_HOME/Apache/Jserv/servlets/
$BKPDIR/iAS/FileMoverServlet* $IAS_ORACLE_HOME/Apache/Jserv/servlets/


Please double test before implementing in your live environment.
# 3  
Old 12-01-2011
Hi Anchal khare

First thanks for replying with this great command.
but still it does not have "cp" in first column.
and i dont understand this command can it be more simple
so that i can easily use it.

your help is very very valuable.

Regards
Kaleem.
# 4  
Old 12-01-2011
I was targeting for your actual requirement.
printing "cp" is not difficult.
Code:
awk  '/^cp/ { n= split($2,A,"/"); s=A[n];  printf ("cp %s/%s ",$3,s); for (i=1;i<n;i++) {printf ("%s/",A[i])} print j}' abc.sh

---------- Post updated at 18:12 ---------- Previous update was at 18:09 ----------

Quote:
Originally Posted by javeedkaleem
i dont understand this command can it be more simple
so that i can easily use it.
Code:
awk  '/^cp/ { 
n= split($2,A,"/");
s=A[n];
printf ("cp %s/%s ",$3,s);
for (i=1;i<n;i++) {
printf ("%s/",A[i])
} 
print j
}' abc.sh


Just go though any basic tutorial of awk.
# 5  
Old 12-01-2011
Slightly off topic. The backup process is flawed:
Quote:
cp $APPL_TOP/*.env $BKPDIR/appl
cp $APPL_TOP/admin/*.env $BKPDIR/appl

The directory context "admin" is lost. Therefore you cannot do a sensible restore.

Similarly the lines which copy files to:
$BKPDIR/8.0.6
$BKPDIR/comn
$BKPDIR/iAS
Also there is no attempt to preserve file permissions. Each "backup" file will be owned by the user making the copy and with default permissions according to the current umask.
As it stands, if you attempt a restore you will corrupt your Oracle intallation.
This User Gave Thanks to methyl For This Post:
# 6  
Old 12-02-2011
Hi Anchal Khare

its really very good very very impressing.
at last with anchal help i finally created my script.


My scritp looks like this:
------------------------

echo "
################################################################


" > ~/RestoreImpfile_appl_comn.sh

echo "export APPL_TOP=$APPL_TOP" >> ~/RestoreImpfile_appl_comn.sh
echo "export FND_TOP=$FND_TOP" >> ~/RestoreImpfile_appl_comn.sh
echo "export MSC_TOP=$MSC_TOP" >> ~/RestoreImpfile_appl_comn.sh
echo "export ORACLE_HOME=$ORACLE_HOME" >> ~/RestoreImpfile_appl_comn.sh
echo "export TNS_ADMIN=$TNS_ADMIN" >> ~/RestoreImpfile_appl_comn.sh
echo "export COMMON_TOP=$COMMON_TOP" >> ~/RestoreImpfile_appl_comn.sh
echo "export CONTEXT_NAME=$CONTEXT_NAME" >> ~/RestoreImpfile_appl_comn.sh
echo "export OA_HTML=$OA_HTML" >> ~/RestoreImpfile_appl_comn.sh
echo "export IAS_ORACLE_HOME=$IAS_ORACLE_HOME" >> ~/RestoreImpfile_appl_comn.sh
echo "

################################################################

" >> ~/RestoreImpfile_appl_comn.sh


awk '/^cp/ {
n= split($2,A,"/");
s=A[n];
printf ("cp %s/%s ",$3,s);
for (i=1;i<n;i++) {
printf ("%s/",A[i])
}
print j
}' abc.sh >> ~/RestoreImpfile_appl_comn.sh


echo "


Restore file : ~/RestoreImpfile_appl_comn.sh

"







################

Finally my script output i got which i want.


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@




[appxdb72@pks19jkp]/fsaixxdb72/applmgr/pgbcxdb72> cat RestoreImpfile_appl_comn.sh

################################################################



export APPL_TOP=/fsaixxdb72/applmgr/pgbcxdb72/appl

export FND_TOP=/fsaixxdb72/applmgr/pgbcxdb72/appl/fnd/11.5.0

export MSC_TOP=/fsaixxdb72/applmgr/pgbcxdb72/appl/msc/11.5.0

export ORACLE_HOME=/fsaixxdb72/applmgr/pgbcxdb72/8.0.6

export TNS_ADMIN=/fsaixxdb72/applmgr/pgbcxdb72/8.0.6/network/admin/gpsogu72_rs19edp

export COMMON_TOP=/fsaixxdb72/applmgr/pgbcxdb72/comn

export CONTEXT_NAME=pgbcxdb72_pks19jkp

export OA_HTML=/fsaixxdb72/applmgr/pgbcxdb72/comn/html

export IAS_ORACLE_HOME=/fsaixxdb72/applmgr/pgbcxdb72/iAS



################################################################

cp $BKPDIR/appl/*.env $APPL_TOP/
cp $BKPDIR/appl/*.env $APPL_TOP/admin/
cp $BKPDIR/appl/*.xml $APPL_TOP/admin/
cp $BKPDIR/appl/topfile* $APPL_TOP/admin/
cp $BKPDIR/appl/*def* $APPL_TOP/admin/
cp $BKPDIR/appl/pasta* $FND_TOP/resource/
cp $BKPDIR/appl/ixlib* $FND_TOP/resource/
cp $BKPDIR/appl/MSCPLD.sh $MSC_TOP/bin/
cp $BKPDIR/8.0.6/*.env $ORACLE_HOME/
cp $BKPDIR/8.0.6/listener.ora $TNS_ADMIN/
cp $BKPDIR/8.0.6/tnsnames.ora $TNS_ADMIN/
cp $BKPDIR/8.0.6/uifont.ali $ORACLE_HOME/guicommon6/tk60/admin/
cp $BKPDIR/comn/adautocfg.sh $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/
cp $BKPDIR/comn/adcmctl.sh $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/
cp $BKPDIR/comn/oai_x_ftp.sh $COMMON_TOP/admin/scripts/${CONTEXT_NAME}/
cp $BKPDIR/comn/appsweb*.cfg $OA_HTML/bin/
cp $BKPDIR/iAS/*.env $IAS_ORACLE_HOME/
cp $BKPDIR/iAS/*.ora $IAS_ORACLE_HOME/network/admin/${CONTEXT_NAME}/
cp $BKPDIR/iAS/buildFileMoverServlet.sh $IAS_ORACLE_HOME/Apache/Jserv/servlets/
cp $BKPDIR/iAS/FileMoverServlet* $IAS_ORACLE_HOME/Apache/Jserv/servlets/
[appxdb72@pks19jkp]/fsaixxdb72/applmgr/pgbcxdb72>



Again Anchal i would like to thanks your for this awsome command.



Regards
Kaleem.
# 7  
Old 12-02-2011
You are welcome. I would still suggest to have a look at the points mentioned in methyl's post.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Need help in creating script for disk mirror and backup

Hi, I am very new to scripting. I need to create a script which does following. Scenario: First get the format command output echo | format Insert the new disk to Solaris Server Get Zpool status format the new disk ( Here I need to select the new disk which have been inserted, I do... (1 Reply)
Discussion started by: praveensharma21
1 Replies

2. Shell Programming and Scripting

Shell script to call Oracle archive backup script when file system reaches threshold value

Hello All, I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60% Need to identify the unique file system that reaches threshold value. ex: capacity ... (4 Replies)
Discussion started by: sasikanthdba
4 Replies

3. Shell Programming and Scripting

MySQL Restoration Backup Script

Hi there, Alright I have this line that I'm working with (bash programming): mysql -u username -pHASH ${args} < /home/site/backups/site.${args}.sql I get this error on that line: ./restore.sh: line 51: syntax error near unexpected token `newline' ./restore.sh: line 51: `mysql -u... (5 Replies)
Discussion started by: Pandoula
5 Replies

4. UNIX for Dummies Questions & Answers

BackUp Home/Creating User from File

Hi! I want to test something to learn Shell scripting better. 1) How can I make a BackUp from all users and groups homedirectory? I want to save that backup in an archiv. Can I choose how to name the backUp archiv? 2) Ok I want to make a file like csv, in this file are listed Users.... (3 Replies)
Discussion started by: CommanderLinux
3 Replies

5. Solaris

question about restoration from backup tape (solaris 10)

I am trying to restore opt on my server. my issue is, all the partitions are saved into the same back up tape. what is the exact command to just restore /opt for example, supposing c0t0d0s7 is the partition for /opt ---------- Post updated at 01:16 PM ---------- Previous update was at... (7 Replies)
Discussion started by: feg
7 Replies

6. Shell Programming and Scripting

creating a parameter file in the script

Here is my code which i am using wright now: CODE #!/bin/bash awk ' BEGIN { FS="|"; while ( getline <"file1.txt" > 0) a=$2 } { if($1 in a) printf("%s %s Specialty Mapped\n", $1, a) > "mapped.txt" else printf("%s %s Specialty Not mapped\n", $1, $2) > "notmapped.txt" ... (2 Replies)
Discussion started by: dsh007
2 Replies

7. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

8. Shell Programming and Scripting

Shell Script backup a file ?

could you please find a solution for this script that backup a file. The file name to backup should be provided as input parameter, the backup file should have the same file name with the extension ".bak". If the user provides no input parameter, the script should display an error message. If... (1 Reply)
Discussion started by: anything
1 Replies

9. Solaris

creating log files for a backup script on solaris

I have a simple backup script that I am running to back up drives across the network. However I need to have detailed log files for this script such as time backup started, what was backed up, if there were any errors and the time that the backup was complete. I would also like the script to... (3 Replies)
Discussion started by: valicon
3 Replies
Login or Register to Ask a Question