WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: rbackup  (Read 2581 times)

Offline gallaccicom

  • Newbie
  • *
  • Posts: 1
rbackup
« on: May 03, 2011, 11:13:06 AM »
hello,
 I have built a script to perform backup and restore via rsync to a remote server;
 the use of rsync allow a greater perfomance between the two updates

 I hope you can improve this and use in standard boot codes...

 if you need I have a compiled version, without the need of perl binary

---- follow the source ---


#!/usr/bin/perl
#
# (c) GALLACCI COMMUNICATIONS 2011
# http://www.gallacci.com - info@gallacci.com
#
# simple program to backup tc mydata to remote server
# using differential rsync alghoritm
#

my ($opt,$srv,$user,$pass) = @ARGV;
&help if ($opt eq '-h');

my $hostname=`hostname`; chomp $hostname;

if ($opt eq '-b'){
 $ENV{'RSYNC_PASSWORD'}=$pass;
 $ENV{'USER'}=           $user;
 my $cmd="
 rsync --recursive --delete-after -az \\
  --files-from=/opt/.filetool.lst \\
  --exclude-from=/opt/.xfiletool.lst \\
   / ${srv}::hostBackup/${hostname}/";
 my $r=system($cmd);
 &result($r);   
}

if ($opt eq '-r'){                                   
 $ENV{'RSYNC_PASSWORD'}=$pass;                       
 $ENV{'USER'}=          $user;                       
 my $cmd="rsync -az  ${srv}::hostBackup/${hostname}/ /";                         
 my $r=system($cmd);                               
 &result($r);                                       
}



   
sub result {
 my $r=shift;
 if ($r>0) { print "KO: Error during operation";}
 else       { print "OK: Operation done"; }
 print "\n";
}

sub help {
 print <<"EOF";
Usage:
 rbackup opt server (user) (pass)
 
Where opt is :
 -b to backup to a remote server
 -r to restore from a remote server
EOF
}