LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-07-2012, 10:03 AM   #1
wdsmith45
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Rep: Reputation: Disabled
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"
 
Old 02-07-2012, 11:09 AM   #2
tizzef
Member
 
Registered: Jan 2005
Location: Nice, France
Distribution: Ubuntu,RHES, Mandriva, RHAS, AIX 4.3.3, 5.2 & 5.3, Debian,Solaris8/10
Posts: 119

Rep: Reputation: 20
and so ?
:-)
 
Old 02-07-2012, 11:13 AM   #3
wdsmith45
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
I don't follow you.......I guess I need to close my if with an fi
 
Old 02-07-2012, 11:18 AM   #4
tizzef
Member
 
Registered: Jan 2005
Location: Nice, France
Distribution: Ubuntu,RHES, Mandriva, RHAS, AIX 4.3.3, 5.2 & 5.3, Debian,Solaris8/10
Posts: 119

Rep: Reputation: 20
Hmm, I mean, what is your problem ??
 
Old 02-07-2012, 11:29 AM   #5
wdsmith45
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
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.
 
Old 02-07-2012, 11:36 AM   #6
tizzef
Member
 
Registered: Jan 2005
Location: Nice, France
Distribution: Ubuntu,RHES, Mandriva, RHAS, AIX 4.3.3, 5.2 & 5.3, Debian,Solaris8/10
Posts: 119

Rep: Reputation: 20
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.
 
Old 02-07-2012, 12:12 PM   #7
wdsmith45
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
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
 
Old 02-07-2012, 12:49 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Copy files from local directory to a particular directory using alias dynamics Linux - Newbie 7 09-11-2009 05:19 PM
How to copy files after search in array from this directory to another directory! phanvinhgiap Programming 4 01-04-2009 07:48 PM
Redundant Directory Copy w/ Tar carlosinfl Linux - General 3 03-20-2008 01:30 PM
How to copy one directory to another directory thru PHP? green_njk Programming 1 01-06-2006 07:55 AM
copy files from directory to directory without subfile ALInux Linux - General 2 06-03-2005 12:51 PM


All times are GMT -5. The time now is 10:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration