Operating System - HP-UX
1753803 Members
7508 Online
108805 Solutions
New Discussion юеВ

FTP Script for Backups in Bourne Shell - Script

 
SOLVED
Go to solution
Laurie A. Krumrey
Regular Advisor

FTP Script for Backups in Bourne Shell - Script

Hi All,

I need to have a script run from Server A to
Server B every night at 4am.

I wasn't sure if it was possible to script ftp commands on UNIX. I want to use a script to mounts Server A file system and then copies the data to Server B and then dismounts when done until all the files are copied over.

Server A is our production server and Server
B is our test server at another physical location.

The files look like this:

/db01/syb115/backup/*.gz
/db02/syb115/backup/*.gz
/db03/syb115/backup/*.gz

This would enable us to have live backups
at another site. I need a script and a cron
job update. You guys are great for helping me.. Thank You So Much...

TIA,
Laurie
Happiness is a choice
11 REPLIES 11
James R. Ferguson
Acclaimed Contributor
Solution

Re: FTP Script for Backups in Bourne Shell - Script

Hi Laurie:

Here are two scripts:

#!/usr/bin/sh
ftp -n << EOF
verbose
open thehost
user uuu ppp
get /tmp/stuff
close
EOF

...

#!/usr/bin/sh
{ echo "open thehost
user uuu ppp
hash
mput *
close"
} | ftp -i -n -v 2>&1 | tee /tmp/ftplog.$$

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: FTP Script for Backups in Bourne Shell - Script

Hi Laurie:
If it were me I would avoid ftp simply because of the need for plaintext passwords unless you use anonymous ftp which defeats the whole purpose. I think I would do something like this using rcp:
FILES="/xxx/file1.gz /yyy/file2.gz"
REMOTE_HOME=elvis
for X in ${FILES}
do
rcp -p ${X} ${REMOTE_HOST}:${X}
done

Clay
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: FTP Script for Backups in Bourne Shell - Script

Hi Laurie:

Two more points for questions I suspect you will ask as soon as you read the above posts:

1. Embedding a password in a script isn't the most desirable thing to do from a security perspective. A "better" approach may be to use a '.netrc' file ['man 4 netrc'] in which you can isolate the password (in one place).

2. In order to ascertain the success or failure of a scripted ftp, parse the messages logged from the session. I use the second script to capture the server/client dialog. Note that the '-v' [verbose] option is set and both stdout & stderr are redirected to a file. The messages from the session contain numbered text. From the 'ftpd (1m)' man pages you can note that "Every command produces at least one reply, although there may be more than one. A reply consists of a three-digit number, a space, some text...The number must conform to this standard, but the text can vary...The first digit of the message indicates whether the reply is good, bad, or incomplete." Thus, use the numbers associated with the text of the messages to discern the success or failure of the process.

...JRF...
Stefan Schulz
Honored Contributor

Re: FTP Script for Backups in Bourne Shell - Script

You said somthing about mounting. If you can mount the drive you could do something as simple as:

/etc/mount serverA:/db01 /backupsource
/usr/bin/cp -rp /backupsource/syb115/backup/*.gz /backupdir/db01
/etc/umount /backupsource
(same for db02 and db03)

Use full pathnames if you set this up as a script run by cron. Of course you can do this copies in a while- or for-loop.

Hope this helps. Stefan
No Mouse found. System halted. Press Mousebutton to continue.
Vincenzo Restuccia
Honored Contributor

Re: FTP Script for Backups in Bourne Shell - Script

Laurie A. Krumrey
Regular Advisor

Re: FTP Script for Backups in Bourne Shell - Script

Hi All,

When I try to do the rcp just in the shell
I get this error below..what does this mean?
I am excuting this as root and the file is
own by syb115 (sybase database) and group
is syb115 for the files.

remshd: Login incorrect.

I can do nslookup on the target host, we are
all on the same network.

Also what would be my cron entry to execute
this every day at 4am and send me email?

THANK YOU
Laurie
Happiness is a choice
A. Clay Stephenson
Acclaimed Contributor

Re: FTP Script for Backups in Bourne Shell - Script

Hi Laurie,

No problem - this is normal. We have to tell machine A that machine B is trustworthy. You have permission problems.
I would do this on all machines that wish to execute the 'r' commands (rlogin,remsh,rcp,etc.):

1)Make sure there is an /etc/hosts.equiv file;
the format is:
machineA
machineB
machineC

(you can man hosts.equiv for more details and options). I would set the permissions to 644 and owned by root:root.

2) You also need to create a .rhosts file in the user's home directory (in this case root so I'll assume '/.rhosts'. I would do this on all the machines in question as well.
The format should be something like this:
machineA root
machineB root
machineC root

You can man .rhosts for details and other options for this file. I would also man remshd - you need to know the details of the remote executions and how they work.

Regards, Clay



If it ain't broke, I can fix that.
Jim Moffitt_1
Valued Contributor

Re: FTP Script for Backups in Bourne Shell - Script

you need to put the file .rhosts with the host names in the file. example:

hosta root
A. Clay Stephenson
Acclaimed Contributor

Re: FTP Script for Backups in Bourne Shell - Script

Hi Laurie,
I forgot, set the permissions of the .rhosts
file to 600. Owner should be root:root.

If you like (and it's a bit more secure), you
can also set the hosts.equiv permissions to 600.

Again, I urge you to read the man pages on these files so that you understand the permissions implications.

Clay
If it ain't broke, I can fix that.