LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I need to tar a directory and then copy it to another directory locally (https://www.linuxquestions.org/questions/linux-newbie-8/i-need-to-tar-a-directory-and-then-copy-it-to-another-directory-locally-928096/)

wdsmith45 02-07-2012 09:03 AM

I need to tar a directory and then copy it to another directory locally
 
I am trying to tar a directory, and then copy the tar file to another directory locally on the same machine. In the script I am also calling another script to shutdownt eh database prior to tar'ing the files.

Here is what I have for the first job to tar the files and copy them locally

# cron script to shutdown database backup files and startup database
#!bin/sh

echo "SHUTTING DOWN THE DATABASE AND BACKING UP THE FILES COLD "

# connect to sqlplus and shutdown database with coldshutdown.sql script
cd /mnt/backups/scripts

UID_PWD`cat concsub_id`

slqplus -u $UID_PWD @coldshutdown.sql

if $? = 0

cd /mnt/test/oracle/TEST/db/apps_st

!tar -cvzf data.tar.gz data

cp data.tar.gz /mnt/backups

cd /mnt/apps1/oracle/TEST

!tar -cvzf apps.tar.gz apps
!tar -cvzf inst.tar.gz inst
!tar -cvzf db.tar.gz db

cp apps.tar.gz /mnt/backups
cp inst.tar.gz /mnt/backups
cp db.tar.gz /mnt/backups


#connect to sqlplus and startup the database with coldstartup.sql script
cd /mnt/backups/scripts

UID_PWD 'cat concsub_id'

sqlplus -u $UID_PWD @coldstartup.sql

if $? = 0

echo "the database has started succesffuly"

tizzef 02-07-2012 10:09 AM

and so ?
:-)

wdsmith45 02-07-2012 10:13 AM

I don't follow you.......I guess I need to close my if with an fi

tizzef 02-07-2012 10:18 AM

Hmm, I mean, what is your problem ??

wdsmith45 02-07-2012 10:29 AM

I was just asking if anyone see any syntax errors or logical errors, this is my first script in LINUX .....DOS and Windows is where I'm coming from.

tizzef 02-07-2012 10:36 AM

Hmm, ok, get it, have you run your scrip right now ?
Quickly, you need to close your if sentences by fi (as you said), remove the ! by the full path to your executable (ie tar) and review how a shell handle the if sentence too :)
Cheers.

wdsmith45 02-07-2012 11:12 AM

I have not ran it yet.... updated script below... i was told I needed the ! to run tar commands in shell

# cron script to shutdown database backup files and startup database
#!bin/sh

echo "SHUTTING DOWN THE DATABASE AND BACKING UP THE FILES COLD "

# connect to sqlplus and shutdown database with coldshutdown.sql script
cd /mnt/backups/scripts

UID_PWD=`cat concsub_id`

sqlplus -u $UID_PWD @coldshutdown.sql

if $? = 0

cd /mnt/test/oracle/TEST/db/apps_st

!tar -cvzf data.tar.gz data

cp data.tar.gz /mnt/backups

cd /mnt/apps1/oracle/TEST

!tar -cvzf apps.tar.gz apps
!tar -cvzf inst.tar.gz inst
!tar -cvzf db.tar.gz db

cp apps.tar.gz /mnt/backups
cp inst.tar.gz /mnt/backups
cp db.tar.gz /mnt/backups


#connect to sqlplus and startup the database with coldstartup.sql script
cd /mnt/backups/scripts

UID_PWD='cat concsub_id'

sqlplus -u $UID_PWD @coldstartup.sql

if $? = 0

echo "the database has started successfully"

fi

echo "shutdown was not successful"

fi

unSpawn 02-07-2012 11:49 AM

Best use BB code tags:
Code:

#!bin/bash
# Comment out "set" line below after testing:
set -vxe
WHOAMI=${0//*\//}; WHOAMI=${WHOAMI//.*/}
_msg() { logger -t ${WHOAMI} "\"$1\" failure, exiting."; exit 1; }

cd /mnt/backups/scripts || _msg cd
UID_PWD=$(cat concsub_id); [ -z "${UID_PWD}" ] && _msg UID_PWD
sqlplus -u $UID_PWD @coldshutdown.sql || _msg coldshutdown.sql

cd /mnt/test/oracle/TEST/db/apps_st || _msg cd
tar -czf /mnt/backups/data.tar.gz data || _msg tar

cd /mnt/apps1/oracle/TEST
for TARBALL in apps inst db; do
 tar -czf /mnt/backups/${TARBALL}.tar.gz ${TARBALL} || _msg tar
done

cd /mnt/backups/scripts; UID_PWD='cat concsub_id'
sqlplus -u $UID_PWD @coldstartup.sql && echo "the database has started successfully"
exit 0



All times are GMT -5. The time now is 11:58 PM.