Gossamer Forum
Home : General : Perl Programming :

Simple backup script....

(Page 2 of 2)
> >
Quote Reply
Re: [dan] Simple backup script.... In reply to
Mmm..I get a number (i.e 12342) returned when a MySQLdump is not successful. Is there a list or something that corolates with this?

Thanks

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Simple backup script.... In reply to
It's late and I'm signing for the night (can barely see straight), but have a look here:



http://www.perldoc.com/...tml#Error-Indicators

http://www.perldoc.com/...1/pod/func/wait.html



Cheers - Dan Cool

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [Andy] Simple backup script.... In reply to
Just a quick note on your code, Andy. I notice that you use a Time module to calculate the time your script took to do it's job. Your method is in fact incorrect.

By just subtracting start and stop times, all you get is time passed between the beginning and the end of your script. That's not the time it took for your program to run - your program has to compute with other programs for the CPU. You'd better off using the times function - or just use the Benchmark module which is part of the standard distribution.

- wil
Quote Reply
Re: [Wil] Simple backup script.... In reply to
Wil..my code IS right. Trust me! As for CPU...why bother? Its probably only the case of 1 second MAX. All it needs to do is open the script, and a couple of other things. Nothing thats gonna take long at all. I don't see your problem with the code Wink

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Simple backup script.... In reply to
Well, what are you in fact computing with your "Time taken:" statement?

If it's 'time taken to do "the job" (i.e. backup your MySQL database)' then your code is incorrect and you should look into the two methods provided by me above. My methods actually calculate the time taken to backup the database, and not time taken by your script.

- wil
Post deleted by Andy In reply to
Quote Reply
Re: [Andy] Simple backup script.... In reply to
That's neat, I like the mysqldump part, I haven't gotten around to using that, it'd be nice to make sure my database structures don't get wasted.

Myself, some time ago, I lost an entire month's work due to a minor mistake. So I whipped up alittle backup script awhile back. The only thing it does different from yours is that it backs up my work to 2 other servers.

Incidentally, yes, I use a local cvs repository for my personnal code (then when I finish my work, commit to the company repository). I love the versioning and cvsweb is soooo purdy!

Code:
#!/usr/bin/perl
# makes a backup of local repository and then ftps it to
# another server for cold storage
#

# get today's date
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
#!/usr/bin/perl
# makes a backup of local repository and then ftps it to
# another server for cold storage
#

# get today's date
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
my $datestr = sprintf( "%4i-%02i-%02i", $year + 1900, $mon + 1, $mday );

# first backup the file
my $fname = "$datestr-repository.tar.bz";
my $new_fpath = "/tmp/$fname";
system( "tar cyvvf $new_fpath /home/cvs/repository" ) and die "Couldn't tar up file. Reason: $?";

# now ftp the contents to a usable location
use Net::FTP;

my $conn;

$conn = Net::FTP->new( 'somedomain.com', Debug => 1 ) or die "damn couldn't connect to the ftp server";
$conn->login( 'user', 'pass' );
$conn->binary();
$conn->put( $new_fpath, "backups/$fname" );
$conn->quit();

$conn = Net::FTP->new( '192.168.1.6', Debug => 1 ) or die "damn couldn't connect to the ftp server";
$conn->login( 'user', 'pass' );
$conn->binary();
$conn->put( $new_fpath, "backups/$fname" );
$conn->quit();
Quote Reply
Re: [Aki] Simple backup script.... In reply to
>>
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
my $datestr = sprintf( "%4i-%02i-%02i", $year + 1900, $mon + 1, $mday );
<<

Awwww you could use the cool posix module :)

use POSIX qw/strftime/;

my $datestr = POSIX::strftime("%Y:%m:%d", localtime() );

Thats the coolest module for date manipulation (apart from GT::Date of course Cool).

Last edited by:

Paul: Jun 22, 2002, 2:51 AM
Quote Reply
Re: [Paul] Simple backup script.... In reply to
No way... Date::Manip. :-)

- wil
Quote Reply
Re: [Paul] Simple backup script.... In reply to
That's cool, should of used that. But of course, as whipped it up I really didn't spend any time doing research on the proper modules.

Date::Manip looks quite promising too, it's very complete! I'm going to have to take a look at how recurrence comparisons are done. I'd like to implement a calendar at some point.

If this backup script were to be done fully, It'd probably be good to make the system do incremental tarballs and scp the encrypted (some sort of public key based) diffs to the remote hosts. But who needs all that eh?
Quote Reply
Re: [Aki] Simple backup script.... In reply to
>>But who needs all that eh? <<

Someone who realised they didn't make a proper backup after a server crash Angelic
Quote Reply
Re: [Paul] Simple backup script.... In reply to
In Reply To:
>>But who needs all that eh? <<

Someone who realised they didn't make a proper backup after a server crash Angelic

Yes..and quite rightly too! I will NEVER make that mistake again. Took me 2 months to get back to where I was before Frown

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Simple backup script.... In reply to
One more reason to get managed hosting! :-)

- wil
Quote Reply
Re: [Wil] Simple backup script.... In reply to
Yup.the guy who is looking at my server for me, gave me a deal. I write a few small scripts a month, and he will manage my server for me Tongue

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Wil] Simple backup script.... In reply to
In Reply To:
In Reply To:
Modules are great, however there is no point in using one when you can do the same task yourself without the module with a relatively small amount of code...(the mkpath thing springs to mind).....remember every "use" at the top of your script is compiled right at the beginning so if you "use" 5 modules then you have to wait for them all to compile before anything useful starts happening....then if you have "use" within a module being "use"d ...well you get the picture.

Heh. Code I am working on now... the first few lines look like this:

Code:
use strict;
use Carp;
use XML::Twig;
use LWP::Simple;
use Text::CSV_XS;
use MIME::Lite;
use DBI;
use IO::File;
use Getopt::Std;

:-)

And this code I am updating today has the following as it's first few lines!! :-)

Code:
use strict;
use Carp;
use Net::IRC;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Cookies;
use URI::Escape;
use XML::Parser;
use XML::Simple;
use XML::Writer;
use XMLParser;
use POSIX;
use Data::Dumper;
use Date::Calc qw(Delta_DHMS);
use Time::Local;
use Getopt::Std;
use Config::IniFiles;
use File::Basename;
use Hash::Merge qw(merge);
use Proc::Daemon;

- wil
> >