Operating System - HP-UX
1820136 Members
3197 Online
109619 Solutions
New Discussion юеВ

Help with script to FTP Oracle Archive files to another host

 
MAD_2
Super Advisor

Help with script to FTP Oracle Archive files to another host

As part of our recovery plan, we are sending updates of the Oracle arch files to another host for safekeeping. I need to know if someone can help me complete the portion that does the FTPing, since it would have to read the contents of a file that contains the latest arch* files (past hour or past two hours, depending on how we configure the archiving process) to FTP to the other host, but I am not sure how to build that part.

Attached you will find portion of the script and the missing part is of course the FTP. I am not sure of how to make it read each indivual line of the file resulting which contains the names of the files to be sent.

This script would run by cron, start one minute before change of hour, get the current hour value, and then sleep for a few seconds until the change of time to give enough time for generation of the last file in the current hour before it starts collecting the names of the all of the files for the current hour.

I hope I was able to explain my intent understandably.

Thanks gurus!
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
11 REPLIES 11
Tomek Gryszkiewicz
Trusted Contributor

Re: Help with script to FTP Oracle Archive files to another host

It can help you, it is a part of script i am using to ftp files from host $HOST to the localhost:

TARGET='target_sid'; export TARGET;
SOURCE='source_sid'; export SOURCE;
HOST='source_host';export HOST
USER='user';export USER
PASSWD="target_user_password";export PASSWD
ORACLE_SID=$TARGET;export ORACLE_SID

ftp_cd01=`echo cd /u01/oradata/$SOURCE/`;export ftp_cd01
ftp_lcd01=`echo lcd /u07/oradata/$TARGET`;export ftp_lcd01

ftp_cd02=`echo cd /u02/oradata/$SOURCE/`;export ftp_cd02
ftp_lcd02=`echo lcd /u02/oradata/$TARGET`;export ftp_lcd02

#FTP
ftp -i -n $HOST >ftp_log.out <quote USER $USER
quote PASS $PASSWD
binary
hash
$ftp_lcd01
$ftp_cd01
mget *.*
$ftp_lcd02
$ftp_cd02
mget *.*

... etc

-Tomek
Steven E. Protter
Exalted Contributor

Re: Help with script to FTP Oracle Archive files to another host


########################
ftp -nv ${SERVER} << FTPEOF > /tmp/temp_log.$$
user ${USERNAME} ${PASSWORD}
#Get file
get $1
quit
FTPEOF


braket variables must be set in advance. change get to put.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Tomek Gryszkiewicz
Trusted Contributor

Re: Help with script to FTP Oracle Archive files to another host

Sorry, i've forgot about the end - after FTPing of course you need to close the connection:

bye
EOF1


-Tomek
MAD_2
Super Advisor

Re: Help with script to FTP Oracle Archive files to another host

Sorry, I think I did not explain well enough:

1. I can't simply use mput because I do not want to send all of the archives (unless I copied the specific archives to a directory that will contain only those and then do the mput from there, but I am trying to avoid doing that). I will only be sending a few at a time, depending on the hour of the day. Example:

The directory contains the following archives:
1025024 Dec 15 12:00 arch_1_2473506.arc
1025024 Dec 15 12:00 arch_1_2473505.arc
1025024 Dec 15 12:00 arch_1_2473504.arc
1025024 Dec 15 11:58 arch_1_2473503.arc
1025024 Dec 15 11:57 arch_1_2473502.arc
1025024 Dec 15 11:56 arch_1_2473501.arc
1025024 Dec 15 11:55 arch_1_2473500.arc
1025024 Dec 15 11:53 arch_1_2473499.arc
1025024 Dec 15 11:51 arch_1_2473498.arc
1025024 Dec 15 11:51 arch_1_2473497.arc
1025024 Dec 15 11:51 arch_1_2473496.arc

If the script starts running at 11:59, it will only put in the currenthrarchives.txt file files created between 11:00 and 11:59, the following:
arch_1_2473503.arc
arch_1_2473502.arc
arch_1_2473501.arc
arch_1_2473500.arc
arch_1_2473499.arc
arch_1_2473498.arc
arch_1_2473497.arc
arch_1_2473496.arc

Those are the only files to be sent. So I cannot use the following (which I have also used in some of mi scripts):

ftp -n ${HOST1} <<-EOF
user ${USER} ${PASS}
cd ${RMTARCHDIR}
binary
verbose
put $file
bye
EOF

Any other ideas?
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Tomek Gryszkiewicz
Trusted Contributor

Re: Help with script to FTP Oracle Archive files to another host

My idea is to create two files witch touch with given time, eg. file1 is 11:00, file2 is 11:59. Then user find -newer file1 ! -newer file2 to get a list of files which are between 11:00 and 11:59. Thats only and idea, i've never tried it, but should work :)

-Tomek
Michael Schulte zur Sur
Honored Contributor

Re: Help with script to FTP Oracle Archive files to another host

Hi,

just in case, that rcp is also an option. I have attached a script, we use for transfering archive logs to a standby database. We zip the files, hence the extension .gz. At the remote location we try to unzip and recover the files into the standby database.

greetings,

Michael
MAD_2
Super Advisor

Re: Help with script to FTP Oracle Archive files to another host

Michael, thanks for bringing into the plate the compressing portion, that's something I need to do at the receiving end, I have to compress them because they are only archived in there "just in case" something goes majorly wrong with our primary system. In that case they would need to be uncompressed and then used.

The script does collect the names of all of the files for the prescribed time, i.e.:

1. By cron it starts at the 59th minute of the hour, collects the current HR time (let's say it is 11:59, it gets 11 for the hour) and then sleeps for 90 seconds. This is to allot some time for a possible last file creating in that one last minute of the h hour.
2. After the 90 seconds sleep, it starts looking for all files which have a creation hour of 11, and places a list of all of the file names in an "txt" file.

Now, what I really need is to be able to FTP all of the files within that resulting "txt" file. That's where I am encountering a wall.

Like I said, I could avoid the issue by reading the file and creating a compressed copy of them into another directory before I do an mput, but what I am trying to avoid is to copy them within the same system at all.
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
MAD_2
Super Advisor

Re: Help with script to FTP Oracle Archive files to another host

So, any more ideas?
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Michael Schulte zur Sur
Honored Contributor

Re: Help with script to FTP Oracle Archive files to another host

Hi,

I dont understand, why you dont use compression on both sides. It has the advantage of reducing the amount to copy to the remote system considerably but also gives you the chance to do a little consistency check on the remote site.

So here my suggestion:

#!/bin/ksh
cd /path/to/archive
ls -l *.arc | awk '{printf("%12d %s\n",$5,$9)}' > loclist
ftp -n remhost << EOT
user ftpuser passwd
cd /path/to/archive
dir *.arc remlist.tmp
EOT
awk '{printf("%12d %s\n",$5,$9)}' remlist.tmp > remlist
echo
comm -23 loclist remlist | awk '{print "put "$2}' > ftp.bat
ftp -nv remhost << EOT
user ftpuser passwd
cd /path/to/archive
`cat ftp.bat`
EOT
rm loclist remlist remlist.tmp ftp.bat
Graham Cameron_1
Honored Contributor

Re: Help with script to FTP Oracle Archive files to another host

Why don't you look at dataguard?

It's an Oracle tool (free with 9i) which does just this for you.

http://otn.oracle.com/products/oracle9i/daily/mar25.html

- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Jean-Louis Phelix
Honored Contributor

Re: Help with script to FTP Oracle Archive files to another host

Hi,

TMPSH=/tmp/ftp$$
cat > $TMPSH << ++END++
ftp -n $HOST1 << EOF
user $USER $PASS
bin
cd $TARGETDIR
++END++
for VAR in ($cat ${THISHRARCHFILES})
do
echo put $VAR
done >> $TMPSH
echo "quit\nEOF" >> $TMPSH
sh $TMPSH
rm $TMPSH



Regards.
It works for me (┬й Bill McNAMARA ...)