LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need a script for daily backup of oracle archive file (https://www.linuxquestions.org/questions/linux-newbie-8/need-a-script-for-daily-backup-of-oracle-archive-file-513761/)

sathyguy 12-26-2006 08:00 AM

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

Kristijan 12-26-2006 03:27 PM

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

sathyguy 01-17-2007 07:36 AM

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

sathyguy 01-20-2007 02:10 AM

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

Tinkster 01-20-2007 01:26 PM

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


Cheers,
Tink

sathyguy 01-21-2007 02:30 AM

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

tredegar 01-21-2007 05:34 AM

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

unSpawn 01-21-2007 05:48 AM

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.

sathyguy 01-21-2007 05:49 AM

tredegar,

i have edited my post before you reply....
please see my previous post.

tredegar 01-21-2007 06:25 AM

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.

sathyguy 01-21-2007 06:54 AM

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

unSpawn 01-21-2007 07:49 AM

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!

sathyguy 01-21-2007 11:14 PM

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

sathyguy 01-22-2007 03:37 AM

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

sathyguy 01-22-2007 05:31 AM

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


All times are GMT -5. The time now is 05:38 PM.