LinuxQuestions.org
Register a domain and help support LQ
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 12-26-2006, 09:00 AM   #1
sathyguy
Member
 
Registered: Sep 2005
Location: Indian Working in Saudi Arabia
Distribution: Redhat Linux AS 3.0
Posts: 93

Rep: Reputation: 15
Need a script for daily backup of oracle archive file


Friends,

Daily i am taking the backup of oracle archive file.From server to local pc using ssh of the local pc.

i want to automate the work which im doing currently.

what i will do is.....

localpc$ ssh 111.12.12.2
serverpc$ cd /oracle/archive/
serverpc$ scp ar0000123.arc ar0000124.arc 111.12.12.2:/backup/archive/

this is the daily work im doing for taking archive file backup.
daily oracle will generate some 10-20 archive files depend upon the usage.
so, how can i write a script to copy the latest files only.

thanks
sathyguy
 
Old 12-26-2006, 04:27 PM   #2
Kristijan
Member
 
Registered: Sep 2003
Location: Melbourne, Australia
Distribution: NetBSD 3.0.1, Slackware 10.1
Posts: 394

Rep: Reputation: 30
Hi sathguy,

What you will first need to do is set up SSH to not prompt you for a password. You can do this using public key authentication.

Jeremy has written a tutorial about it here[1].

Then all you need to do is hack together a quick shell script to copy the files across and make it run everyday.

Code:
#!/bin/bash
scp /oracle/archive/ar0000123.arc ar0000124.arc username@111.12.12.2:/backup/archive/
To make it run daily, you can do this one of two ways.
  1. Edit the user crontab (crontab -e)
  2. Make the script executable (chmod +x script.sh) and place it in /etc/cron.daily

Now I'm not familiar with how Oracle files are backed up, but looking at the files you are copying, it would seem that they increment in value (filename changes). You can either specify *.arc, or use other commands to narrow down which files are copied.

-Kristijan

[1] - http://www.linuxquestions.org/linux/..._Keys_with_SSH
 
Old 01-17-2007, 08:36 AM   #3
sathyguy
Member
 
Registered: Sep 2005
Location: Indian Working in Saudi Arabia
Distribution: Redhat Linux AS 3.0
Posts: 93

Original Poster
Rep: Reputation: 15
thanks...but
if i place the script in /etc/cron.daily at what time it will run the script.
i want to run my script daily 02:00 AM. how can i do that?

Thanks
 
Old 01-20-2007, 03:10 AM   #4
sathyguy
Member
 
Registered: Sep 2005
Location: Indian Working in Saudi Arabia
Distribution: Redhat Linux AS 3.0
Posts: 93

Original Poster
Rep: Reputation: 15
How to pass a variable to a script?

Friends,

here is my script.....

Quote:
exp userid=username/password@realdb file=/u02/logical_backup/abc_+$date+.dmp log=/u02/logical_backup/abc_+$date+.log owner=oraadmin statistics=none
i want the exported file name as abc_2101.dmp and abc_2101.log (2101 is a date and month)

I want to execute this script daily at 02:00 AM.
so that i edited the crontab -e as....

Quote:
00 02 * * * ./u02/script/dailybkp.sh

Now what i want is....

1. is the steps are correct for crontab -e?
2. Is the script of the crontab will execute daily at 02:00 AM?
3. how can i rename the .log filename and .dmp file name daily according to the date. for example abc_2001 is today's date and month.how can i replace with the variable.

thanks
sathyguy

Last edited by sathyguy; 01-20-2007 at 03:45 AM.
 
Old 01-20-2007, 02:26 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I've merged your two threads on the same topic; please re-read
the rules, and keep your discussions in one place.


Cheers,
Tink
 
Old 01-21-2007, 03:30 AM   #6
sathyguy
Member
 
Registered: Sep 2005
Location: Indian Working in Saudi Arabia
Distribution: Redhat Linux AS 3.0
Posts: 93

Original Poster
Rep: Reputation: 15
sorry...i will not repeat it...

i solved half of the problem.....
whey this rename is not working?

# rename file.sh file2.sh

when i run the above command. the file name is not chaning.
please point me where im making mistake

thanks
sathyguy

Last edited by sathyguy; 01-21-2007 at 06:32 AM.
 
Old 01-21-2007, 06:34 AM   #7
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
Quote:
now what to do?
Give the full path to the backup script in your crontab, not a relative path (that begins with a dot, which means start from wherever you currently are), something like this:
00 02 * * * /u02/script/dailybkp.sh
 
Old 01-21-2007, 06:48 AM   #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
i want the exported file name as abc_2101.dmp and abc_2101.log (2101 is a date and month)
However "2101" is not easy to look for, "20070121" is (replace with '+%Y%m%d' below). Anyway, add date like this:
Code:
#!/bin/bash --
date=`/bin/date '+%d%m'`
exp userid=username/password@realdb file=/u02/logical_backup/abc_${date}.dmp log=/u02/logical_backup/abc_${date}.log owner=oraadmin statistics=none
exit 0
# rename file.sh file2.sh
In your case use "mv" instead of "rename". Search LQ or the internet for "Rute": you want help with basic commands.
 
Old 01-21-2007, 06:49 AM   #9
sathyguy
Member
 
Registered: Sep 2005
Location: Indian Working in Saudi Arabia
Distribution: Redhat Linux AS 3.0
Posts: 93

Original Poster
Rep: Reputation: 15
tredegar,

i have edited my post before you reply....
please see my previous post.
 
Old 01-21-2007, 07:25 AM   #10
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
Quote:
i have edited my post before you reply....
.. I think you mean you edited your post whilst I was replying. Why on earth would you do that? It makes this thread very difficult to read, understand and follow.
Quote:
please see my previous post.
Which "previous post"? Sheesh.
 
Old 01-21-2007, 07:54 AM   #11
sathyguy
Member
 
Registered: Sep 2005
Location: Indian Working in Saudi Arabia
Distribution: Redhat Linux AS 3.0
Posts: 93

Original Poster
Rep: Reputation: 15
ok forget everything....
i have got a solution....working...but i have few questions to UnSpawn...

Step1:
$crontab -e
Quote:
00 02 * * * /u02/script/dailybkp.sh
Step2:
$vi dailybkp.sh
Quote:
#!/bin/bash
td=`/bin/date +%d%m`
exp userid=username/password@realdb file=/u02/logical_backup/abc_$td.dmp log=/u02/logical_backup/abc_$td.log owner=oraadmin statistics=none
1. what is the purpose of "exit 0"?
2. If im not using "exit 0" anything harm?
3. will the crontab execute daily at 02:00 AM?


Thanks
Sathyguy
 
Old 01-21-2007, 08:49 AM   #12
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
ok forget everything....
i have got a solution....working...but i have few questions to UnSpawn.

Phrasing it like that and addressing one person when asking questions seems a bit inconsiderate towards those that helped you with other solutions. Besides that person may not be around to answer.


1. what is the purpose of "exit 0"?
It sets the exit status of the script to what humans read as "OK".


2. If im not using "exit 0" anything harm?
No harm anything.


3. will the crontab execute daily at 02:00 AM?
You just reposted what you got from Tredegar.
Is there any reason to doubt his reply?
And is there any reason for you not to actually test it yourself? Come on!
 
Old 01-22-2007, 12:14 AM   #13
sathyguy
Member
 
Registered: Sep 2005
Location: Indian Working in Saudi Arabia
Distribution: Redhat Linux AS 3.0
Posts: 93

Original Poster
Rep: Reputation: 15
sorry for the inconvenience which is happened in this thread by me.
I have tested the suggestions , its working fine.
Thank you all.

Last edited by sathyguy; 01-22-2007 at 12:15 AM.
 
Old 01-22-2007, 04:37 AM   #14
sathyguy
Member
 
Registered: Sep 2005
Location: Indian Working in Saudi Arabia
Distribution: Redhat Linux AS 3.0
Posts: 93

Original Poster
Rep: Reputation: 15
once again sorry for reopening this thread....i tested with cp command it was working fine...
so, i thought it should work for exp command also.
but its not working....also its not throwing any error....
the crontab -e is having...

00 02 * * * exp userid=system/password@realdb file=/u02/test/n22.dmp log=/u02/test/n22.log owner=scott statistics=none

also i have tested by calling the script.

#!/bin/bash
00 02 * * * /u03/script/testbkp.sh

it's not working

but the below one is working....

00 02 * * * cp /u02/test.txt /u02/test/test.txt

also this one is also working....
#!/bin/bash
00 02 * * * /u03/script/testbkp.sh (there is a cp command inside this script)


i listed the chkconfig --list crond
crond 0,1,6 = off
2,3,4,5 are on

what might be the reason?

thanks
sathyguy
 
Old 01-22-2007, 06:31 AM   #15
sathyguy
Member
 
Registered: Sep 2005
Location: Indian Working in Saudi Arabia
Distribution: Redhat Linux AS 3.0
Posts: 93

Original Poster
Rep: Reputation: 15
I found the problem in the profile.
i have to add one more line at the beginning of the script.

Quote:
. $HOME/.bash_profile
now the exp command also working....

thanks
 
  


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
Backup script to write to file? ctroyp Linux - Newbie 13 01-10-2006 07:15 PM
Problem With Script in cron.daily fizbang Linux - Newbie 10 03-21-2005 11:23 AM
How to backup/archive evolution emails? subaruwrx Linux - Software 4 10-25-2004 08:25 AM
shell script - add file to archive ? xconspirisist Linux - Software 2 03-20-2004 04:27 PM
Need script to dump database, ftp file to backup server glock19 Linux - Networking 17 05-12-2003 06:56 PM


All times are GMT -5. The time now is 01:58 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