Fedora Linux Support Community & Resources Center
  #1  
Old 31st August 2004, 11:09 AM
ghenry Offline
Retired Community Manager
 
Join Date: Mar 2004
Location: Scotland
Age: 36
Posts: 1,019
Perl rdiff-backup script

Just finished this and thought someone could use it:

Code:
#!/usr/bin/perl

use strict;
use warnings;
use Mail::Sendmail;
use POSIX qw(strftime);

#################################################
#  program:	suretec-backup                  
#  license:	GPL                             
#  author:	Gavin Henry                     
#  company:	Suretec Systems Ltd.            
#  url:		http://www.suretecsystems.com   
#  version:	v1.0                            
#                                               
#  first draft : 30-08-04                       
#  last update : 31-08-04		        
#################################################

# Globals
my $rdiff       = '/usr/bin/rdiff-backup';
#my $options     = '-v5 --print-statistics';
my $localdir    = '/your/localdir';
my $userhost 	= 'you@yourhost';
my $remotedir 	= '/your/remotedir';
my @args        = ( $localdir, "$userhost\:\:$remotedir" );
my $to          = 'Your Name <your.name@you.com>';
my $from        = 'Your Support Service <support@yourservice.com>';
my $sep         =  '-' x 76 . "\n";
my $time        = localtime;  
my $datestamp   =  strftime '%d.%m.%y.%T', localtime;

# Suretec messages
print "\n", $sep, "Brought to you by Your Company Ltd.\n", $sep;
print "\n", $sep, "Initialising remote backup synchronsation on $time.\n", $sep;

# Using system command call to give us a return code, with die in the if{}else{} block.
my $backup = system $rdiff, @args;

# Send e-mail with a few details for success and failures
# Success
if ($backup == 0) {
my %mails = ( 
    To      => "$to",
    From    => "$from",
    Subject => "Remote backup complete from $ENV{HOSTNAME} on $time",
    Message => "The remote backup has been completed on $ENV{HOSTNAME}" 
                . " on $time with the command:\n\n $rdiff @args\n" 
);
sendmail(%mails);
# Success finish message
print "\n", $sep, "Remote backup complete on $time. E-mail sent with details.\n", $sep;


# Create a success logfile
open LOG, ">>$datestamp-rdiff-backup-success.log"
  or die "Cannot create logfile: $!";
print LOG "Remote backup completed on $time, with the command:\n\n$rdiff @args\n\nAn e-mail has been sent.\n";
close LOG;
print "Logfile created on $time.\n\n";

# Failure
} else {
my %mailf = ( 
    To      => "$to",
    From    => "$from",
    Subject => "Remote backup failed from $ENV{HOSTNAME} on $time",
    Message => "The remote backup has failed on $ENV{HOSTNAME}" 
                . " on $time with the command:\n\n$rdiff @args\n" 
);
sendmail(%mailf);
# Failure finish message
print "\n", $sep, "Remote backup failed on $time. E-mail sent with details.\n", $sep;

# Create a failure logfile
open LOG, ">>$datestamp-rdiff-backup-failed.log"
  or die "Cannot create logfile: $!";
print LOG "Remote backup failed on $time, with the command:\n\n$rdiff @args\n\nAn e-mail has been sent.\n";
close LOG;
print "Logfile created on $time.\n\n";
die "Backup exited funny: $?" unless $backup == 0;
}

# Program complete

I will be adding to this regularly, so you can find the latest version at:

http://www.perl.me.uk/downloads
__________________
http://blog.suretecsystems.com
Reply With Quote
  #2  
Old 31st August 2004, 11:15 AM
ghaefb Offline
Retired Community Manager
 
Join Date: Apr 2004
Location: Slovenia
Age: 31
Posts: 1,713
ghenry you are really into perl now are you

Where did you learn perl skills?
And how come you like perl so much?

I'm thinking of learning perl too...
__________________
_ghaefb


blog & sysinfo
Reply With Quote
  #3  
Old 31st August 2004, 11:43 AM
ghenry Offline
Retired Community Manager
 
Join Date: Mar 2004
Location: Scotland
Age: 36
Posts: 1,019
I just bought Learning Perl and bought the Perl CD Bookshelf from ebay.

Joined the beginners perl mailing list and went from there.

I love it because you can do so much with it and as it is quite hard it really makes you think about your filesystem etc. and things can easily be applied to php and others.

It is the swiss army knife, as there are so many modules.

My next project is going to be using http://axkit.org/, like www.gentoo.org as I love the structure of xml and like docbook xml too.

Also, at my day job I have some graduate engineer things to write up, so I am writing a script to pull things from google and write them to openoffice writer, so I don't have to keep copying and pasting :-)

Gavin.
__________________
http://blog.suretecsystems.com
Reply With Quote
  #4  
Old 31st August 2004, 11:45 AM
ghenry Offline
Retired Community Manager
 
Join Date: Mar 2004
Location: Scotland
Age: 36
Posts: 1,019
Would you like a free copy of Perl CD bookshelf as a favour? You can have my official backup copy :-)

No copyright infringement then :-)
__________________
http://blog.suretecsystems.com
Reply With Quote
  #5  
Old 31st August 2004, 11:54 AM
ghaefb Offline
Retired Community Manager
 
Join Date: Apr 2004
Location: Slovenia
Age: 31
Posts: 1,713
Quote:
Originally Posted by ghenry
Would you like a free copy of Perl CD bookshelf as a favour? You can have my official backup copy :-)

No copyright infringement then :-)
You would do that?
I'd really like to learn more about perl...

This is a CD right? How would I get it?
__________________
_ghaefb


blog & sysinfo
Reply With Quote
  #6  
Old 31st August 2004, 12:06 PM
ghenry Offline
Retired Community Manager
 
Join Date: Mar 2004
Location: Scotland
Age: 36
Posts: 1,019
I have made a bzip2 tarball of the CD, it's basically, 7 O'reilly Perl books in HTML with a java search feature:

http://www.oreilly.com/catalog/perlcdbs4/
It's version 3 I have. I didn't even know there was version 4, damn!!!!

http://www.oreilly.com/catalog/perlcdbs3/ I what I have, which I actually think is better now I have had a look at it as it has perl & XML and LWP & perl = 7 books, whereas V4.0 has 6. I was going to buy mastering regluar expressions anyway, so I think I haven't lost out.


PM me or I'll give a link in the staff forum.
__________________
http://blog.suretecsystems.com
Reply With Quote
  #7  
Old 20th February 2006, 03:34 PM
fedorabobblue Offline
Registered User
 
Join Date: Jan 2006
Posts: 95
Help

Quote:
Originally Posted by ghenry
Just finished this and thought someone could use it:

Code:
#!/usr/bin/perl

use strict;
use warnings;
use Mail::Sendmail;
use POSIX qw(strftime);

#################################################
#  program:	suretec-backup                  
#  license:	GPL                             
#  author:	Gavin Henry                     
#  company:	Suretec Systems Ltd.            
#  url:		http://www.suretecsystems.com   
#  version:	v1.0                            
#                                               
#  first draft : 30-08-04                       
#  last update : 31-08-04		        
#################################################

# Globals
my $rdiff       = '/usr/bin/rdiff-backup';
#my $options     = '-v5 --print-statistics';
my $localdir    = '/your/localdir';
my $userhost 	= 'you@yourhost';
my $remotedir 	= '/your/remotedir';
my @args        = ( $localdir, "$userhost\:\:$remotedir" );
my $to          = 'Your Name <your.name@you.com>';
my $from        = 'Your Support Service <support@yourservice.com>';
my $sep         =  '-' x 76 . "\n";
my $time        = localtime;  
my $datestamp   =  strftime '%d.%m.%y.%T', localtime;

# Suretec messages
print "\n", $sep, "Brought to you by Your Company Ltd.\n", $sep;
print "\n", $sep, "Initialising remote backup synchronsation on $time.\n", $sep;

# Using system command call to give us a return code, with die in the if{}else{} block.
my $backup = system $rdiff, @args;

# Send e-mail with a few details for success and failures
# Success
if ($backup == 0) {
my %mails = ( 
    To      => "$to",
    From    => "$from",
    Subject => "Remote backup complete from $ENV{HOSTNAME} on $time",
    Message => "The remote backup has been completed on $ENV{HOSTNAME}" 
                . " on $time with the command:\n\n $rdiff @args\n" 
);
sendmail(%mails);
# Success finish message
print "\n", $sep, "Remote backup complete on $time. E-mail sent with details.\n", $sep;


# Create a success logfile
open LOG, ">>$datestamp-rdiff-backup-success.log"
  or die "Cannot create logfile: $!";
print LOG "Remote backup completed on $time, with the command:\n\n$rdiff @args\n\nAn e-mail has been sent.\n";
close LOG;
print "Logfile created on $time.\n\n";

# Failure
} else {
my %mailf = ( 
    To      => "$to",
    From    => "$from",
    Subject => "Remote backup failed from $ENV{HOSTNAME} on $time",
    Message => "The remote backup has failed on $ENV{HOSTNAME}" 
                . " on $time with the command:\n\n$rdiff @args\n" 
);
sendmail(%mailf);
# Failure finish message
print "\n", $sep, "Remote backup failed on $time. E-mail sent with details.\n", $sep;

# Create a failure logfile
open LOG, ">>$datestamp-rdiff-backup-failed.log"
  or die "Cannot create logfile: $!";
print LOG "Remote backup failed on $time, with the command:\n\n$rdiff @args\n\nAn e-mail has been sent.\n";
close LOG;
print "Logfile created on $time.\n\n";
die "Backup exited funny: $?" unless $backup == 0;
}

# Program complete

I will be adding to this regularly, so you can find the latest version at:

http://www.perl.me.uk/downloads
================================================== ======
hey man just wondering about a few things in your backup script

i dont suppose you could explaine to me what a few things in your backup script is doing ?


like $rdiff = /usr/bin/rdiff-backup

whats this actually doing because isint $localdir = /your/localdir where u set the source for the backup ?

and remote dir where it backups to ? .

the other commands i do not understand are.

$sep and $options and $userhost (you@yourhost) is thi my hostname ?

if you could explaine this to me i would extremly greatful
Reply With Quote
  #8  
Old 21st February 2006, 03:25 PM
ghenry Offline
Retired Community Manager
 
Join Date: Mar 2004
Location: Scotland
Age: 36
Posts: 1,019
Quote:
Originally Posted by fedorabobblue
================================================== ======
hey man just wondering about a few things in your backup script

i dont suppose you could explaine to me what a few things in your backup script is doing ?


like $rdiff = /usr/bin/rdiff-backup

whats this actually doing because isint $localdir = /your/localdir where u set the source for the backup ?

and remote dir where it backups to ? .

the other commands i do not understand are.

$sep and $options and $userhost (you@yourhost) is thi my hostname ?

if you could explaine this to me i would extremly greatful
$rdiff sets where the rdiff binary is located, in case you installed it somewhere else.

$sep is what goes before the print statement for print on the console.
lots of ------------------------

$options are the option for the rdiff command

$userhost is how you would log into where the backups are being saved to via SSH.

HTH.
__________________
http://blog.suretecsystems.com
Reply With Quote
  #9  
Old 21st February 2006, 03:36 PM
fedorabobblue Offline
Registered User
 
Join Date: Jan 2006
Posts: 95
ok thanks alot man i thought u had wrote the entier backyup script urself.

I got a bit stuck and started writing my own

Do u think this is gona be easy for a brand new begginer of perl

i just wana make a simple backup script
Reply With Quote
Reply

Tags
perl, rdiffbackup, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to rdiff-backup fedora to windows? hanpedro Using Fedora 2 16th December 2007 04:39 AM
Perl script to backup /home folder to external harddrive linuxted Guides & Solutions (No Questions) 0 7th July 2005 12:54 AM
rdiff-backup owakroeger Reviews, Rants & Things That Make You Scream 0 30th December 2004 02:55 AM
rdiff-backup frontend johnnyq Using Fedora 1 29th October 2004 09:59 PM
HOWTO: Automate remote backups using rdiff-backup and perl ghenry Links 7 6th September 2004 07:35 AM


Current GMT-time: 23:30 (Friday, 19-12-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
...Creek Side - Stockholm-Arlanda Airport (ARN) Travel Photos on Instagram - Marina of Koper Travel Photos - Te Whiti Park Instagram Photos - Texas State Fair Photos on Instagram