This one used to backup our database and application. Its prepared for ftp. Later i'll put in the outo backup and ftp.
#File Name: makebackup.pl #Author : Kumar Arjunan #Nick : amyarjun #E-Mail: amyarjun@yahoo.com --------------------------------- #!/usr/bin/perl -w use Time::localtime; #----------------GET TIME -------------------------- $| = 1; sub now { $tm = localtime; ($smin, $shour, $sday, $smon, $syear) = ($tm->min, $tm->hour, $tm->mda +y, $tm->mon, $tm->year); $f = sprintf ("%02d-%02d-%04d", $smon+1, $sday, $syear+1900, $shour, $ +smin); return $f; } $g = &now; print "\nThe Time NOW:\t $g\n"; print "\n-------ZIPPING DATABASE-------\n"; #----------------GET TIME -------------------------- $zipdbname = 'dbbackup'.$g; $zipexnname = 'ExnCorp'.$g; system "zip -r $zipdbname /var/lib/mysql/*"; print "\n-------DATABASE ZIPPED-------\n"; print "\n-------ZIPPING EXN-------\n"; system "zip -r $zipexnname /var/www/html/ExnCorp/*"; print "\n-------EXN ZIPPED-------\n"; $zipdbname = $zipdbname.'.zip'; $zipexnname = $zipexnname.'.zip'; system "chown dev:dev $zipdbname"; system "chown devftp:devftp $zipexnname";

Edited by Chady -- added missing code tags.

Replies are listed 'Best First'.
Re: makebackup
by polettix (Vicar) on Mar 29, 2005 at 17:08 UTC
    Hi amyarjun! Could you please put <code>...<code> tags around your code? This way, we'll be able to read it comfortably. Compare:

    sub quite_unreadable {
    $this = ! "readable";
    }

    to this:

    sub aaaah { $this = "readable!"; }
    Note the constant spacing font as well. Latter was obtained by actually writing

    <code>
    sub aaaah {
       $this = "readable!";
    }
    </code>

    You'll learn other useful things on how to write your posts here, please spend a minute in reading it or you'll have someone complain about your code in each snippet you propose. Happy posting!

    Flavio

    Don't fool yourself.
Re: makebackup
by Jaap (Curate) on Mar 29, 2005 at 14:21 UTC
    Allow me to clean it up a bit:
    • use strict
    • use multi-argument system calls for safety
    • don't rely on $ENV{'PATH'}
    • Why use Time::localtime?
    #!/usr/bin/perl use strict; use warnings; $ENV{'PATH'} = ''; my $zipExec = '/usr/bin/zip'; my $chownExec = '/bin/chown'; #----------------GET TIME -------------------------- sub now { my @time = (localtime())[3 .. 5]; return sprintf ("%02d-%02d-%04d", $time[0], $time[1] + 1, $time[2] + + 1900); } my $g = now(); print "\nThe Time NOW:\t $g\n"; print "\n-------ZIPPING DATABASE-------\n"; my $zipdbname = "dbbackup$g"; my $zipexnname = "ExnCorp$g"; system($zipExec, '-r', $zipdbname, '/var/lib/mysql/*'); print "\n-------DATABASE ZIPPED-------\n"; print "\n-------ZIPPING EXN-------\n"; system($zipExec, '-r', $zipexnname, '/var/www/html/ExnCorp/*'); print "\n-------EXN ZIPPED-------\n"; $zipdbname .= '.zip'; $zipexnname .= '.zip'; system($chownExec, 'dev:dev', $zipdbname"; system($chownExec, 'devftp:devftp', $zipexnname";
    Warning: code is untested.
Re: makebackup
by amyarjun (Novice) on Apr 05, 2005 at 11:27 UTC
    Hi guys thanks for the alteration.
    And your ideas - i welcome it.
    I'm sharpening my programming knowledge with your guys help.