Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net:::FTP interrupted

Status
Not open for further replies.

mwpclark

Programmer
Mar 14, 2005
59
US
Hello

I have been using Net::FTP in a script to backup server data with a cron run at night. It was working, then I bumped my head and ran out of allocated space on the backup server. I contracted for additional space but it [green]*seems*[/green] like the process [green]*may*[/green] still be hanging..... that is, transferring some data but not all. I have figured the script doesn't complete, because it has not been stopping the FTP server (proftpd) like it did at first, and the data transferred shows one file incomplete, and the other not transferred.

I have looked at /var/log/messages but that only lists logins. The config file /etc/proftpd.conf does not seem suited to writing error messages.

I am testing the following cron statement to send output to a log file.... I will know if it worked tomorrow:

[blue]01 1 * * 2,4,6 /backup/serverbackup.pl >>/backup/backup.log[/blue]

I will be grateful for any suggestions to write results to a log file when the ftp->put procedure is completed, or if it is interrupted, stalled or shut down prematurely.

Thanks, Mike

Code:
#!/usr/bin/perl

# START FTP
system "/backup/startftp.pl"; 

$dateStamp = `/bin/date +"%w%a"`; chop ($dateStamp);

$HostingbackupPath = "/htdocs";
$HostingtarPath = "/backup/hostingfiles";
$HostingtarName = "HOSTING.$dateStamp.tar";
$HostinggzName = "$HostingtarPath/$HostingtarName.gz";
$MysqltarPath = "/backup/mysqlfiles";
$MysqltarName = "MYSQL.$dateStamp.tar";
$MysqlgzName = "$MysqltarPath/$MysqltarName.gz";
$EtctarPath = "/backup/etcfiles";
$EtcbackupPath = "/etc";
$EtctarName = "ETC.$dateStamp.tar";
$EtcgzName = "$EtctarPath/$EtctarName.gz";

@db = `cat /backup/dblist`;

foreach $db (@db) {
        chomp $db;
        {
                $dbase = "$db.$dateStamp";
                `/usr/bin/mysqldump -u root -pPASS $db > $MysqltarPath/$dbase`;
        }
}
system "tar cvfp $MysqltarPath/$MysqltarName $MysqltarPath/*.$dateStamp ";
system "gzip -f $MysqltarPath/$MysqltarName";



system "tar cvfp $HostingtarPath/$HostingtarName $HostingbackupPath/*";
system "gzip -f $HostingtarPath/$HostingtarName";



use Net::FTP;

$ftp = Net::FTP->new("111.222.333.444") or die "Couldn't connect to 111.222.333.444 $@\n";
$ftp->login("USER", "PASS") or die "Couldn't login\n";
$ftp->put("$HostinggzName") or die "Couldn't upload $HostinggzName\n";
$ftp->put("$MysqlgzName") or die "Couldn't upload $MysqlgzName\n";
$ftp->quit();

# STOP FTP
system "/backup/stopftp.pl";
 
Why chop vs chomp?
$dateStamp = `/bin/date +"%w%a"`; chop ($dateStamp);

You can explore the following two options of Net::Ftp to get some ideas

Timeout - Set a timeout value (defaults to 120)
Debug - debug level (see the debug method in Net::Cmd)
 
I would also wrap the whole think in a alarm, and when the alarm hits you could issue your stopftp command.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Depends on the FTP package you're using and if anonymous login vs an acct login. A couple of FTP packages will not write to the log file until the transfer has completed successfully - if you are anonymous user.

Monitor the log file, look for changes in size. If there has been no change to the file in some defined time period then that is an indication. Or a small change over a length of time, ...

Can you include the hash switch in the FTP command? Direct the STDOUT & STDERR to a log file and that way you can see something moving.
Generally you will get better performance using rsync. And if you use the --progress switch with STDOUT & STDERR to a log file, you will be able to read its progress. The security enhancement of rsync over FTP is a given - you have rsync transferring encrypted data, FTP does not. (Up to date rsync connects using port 22 by default.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top