initial commit of file from CVS for smeserver-BackupPC on Sat Sep 7 20:10:07 AEST 2024
This commit is contained in:
67
root/usr/share/BackupPC/bin/BackupPC_SME_localArchive
Executable file
67
root/usr/share/BackupPC/bin/BackupPC_SME_localArchive
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# Author: Daniel Berteaud (daniel@firewall-services.com)
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
use lib "/usr/share/BackupPC/lib";
|
||||
use BackupPC::SMEarchive;
|
||||
use strict;
|
||||
|
||||
|
||||
my $logFile = '/tmp/'.genRandName ();
|
||||
|
||||
|
||||
# Sortie erreur standard=fichier de log
|
||||
open (STDERR, ">$logFile");
|
||||
|
||||
my $today = `$path{date} +%F-%kh%M`;
|
||||
my $check = 1;
|
||||
# on inscrit la date en haut du fichier log
|
||||
print STDERR "Starting archive: ".`$path{date}`."\n";
|
||||
|
||||
my %opts=();
|
||||
|
||||
my %params=(
|
||||
'destination'=>"/tmp/",
|
||||
'split'=>"0",
|
||||
'compress'=>"gzip",
|
||||
'cipher'=>'off',
|
||||
'key'=>'/etc/BackupPC/archive.key',
|
||||
'backupNum'=>"-1",
|
||||
'share'=>"*",
|
||||
'parity'=>'0',
|
||||
'hosts'=>'localhost',
|
||||
'sendMailTo'=>'admin',
|
||||
'configFile'=>'/etc/BackupPC/localArchive.conf');
|
||||
|
||||
# On lance la récupération des paramètre qui retourne le fichier de config à utiliser
|
||||
$params{configFile} = init($params{configFile});
|
||||
|
||||
%params = readConf(\%params);
|
||||
|
||||
print STDERR "\nYou have requested to archive these hosts: $params{hosts} to this destination: $params{destination}\n\n";
|
||||
|
||||
localArchive($params{hosts},$params{backupNum},$params{share},$params{compress},$params{split},$params{cipher},$params{key},$params{destination});
|
||||
|
||||
print STDERR "\n\nArchive finished: ".`$path{date}`."\n";
|
||||
|
||||
my $log = `$path{cat} $logFile`;
|
||||
sendMail($params{sendMailTo},'localArchive',$log);
|
||||
mvLog('localArchive',$logFile,$today);
|
||||
|
||||
exit(0);
|
||||
|
80
root/usr/share/BackupPC/bin/BackupPC_SME_localCopyPool
Executable file
80
root/usr/share/BackupPC/bin/BackupPC_SME_localCopyPool
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# Author: Daniel Berteaud (daniel@firewall-services.com)
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
use lib "/usr/share/BackupPC/lib";
|
||||
use BackupPC::SMEarchive;
|
||||
use BackupPC::SMEcopyPool;
|
||||
use strict;
|
||||
|
||||
|
||||
my $logFile = '/tmp/'.genRandName ();
|
||||
my $rsyncLog = '/tmp/'.genRandName ();
|
||||
my $check = 1;
|
||||
|
||||
|
||||
# Sortie erreur standard=fichier de log
|
||||
open (STDERR, ">$logFile");
|
||||
|
||||
my $today = `$path{date} +%F-%kh%M`;
|
||||
|
||||
# on inscrit la date en haut du fichier log
|
||||
print STDERR "Starting pool copy: ".`$path{date}`."\n";
|
||||
|
||||
my %opts=();
|
||||
|
||||
my %params=(
|
||||
'destination'=>"/tmp/",
|
||||
'source'=>'/var/lib/BackupPC/',
|
||||
'compress'=>"gzip",
|
||||
'extract'=>"yes",
|
||||
'stop'=>"yes",
|
||||
'sendMailTo'=>'admin',
|
||||
'configFile'=>'/etc/BackupPC/localCopyPool.conf');
|
||||
|
||||
# On lance la récupération des paramètres qui retourne le fichier de config à utiliser
|
||||
$params{configFile} = init($params{configFile});
|
||||
|
||||
%params = readConf(\%params);
|
||||
|
||||
|
||||
print STDERR "You have requested to copy all your backups ($params{source}) to this destination: $params{destination}\n\n";
|
||||
|
||||
$check = verifTree($params{source});
|
||||
|
||||
if ($check eq 1){
|
||||
if ($params{stop} eq 'yes'){
|
||||
stopBackupPC();
|
||||
}
|
||||
copyPool($params{source},$params{destination},$logFile,$rsyncLog);
|
||||
localCopyPC($params{source},$params{destination},$params{compress},$params{extract},$logFile);
|
||||
if ($params{stop} eq 'yes'){
|
||||
startBackupPC();
|
||||
}
|
||||
}
|
||||
else{
|
||||
print STDERR "\naborting, the source directory is probably not the good one\n\n";
|
||||
}
|
||||
|
||||
print STDERR "\n\nCopy finished: ".`$path{date}`."\n";
|
||||
|
||||
my $log = `$path{cat} $logFile`;
|
||||
sendMail($params{sendMailTo},'localCopyPool',$log);
|
||||
mvLog('localCopyPool',$logFile,$today);
|
||||
|
||||
exit(0);
|
||||
|
13
root/usr/share/BackupPC/bin/BackupPC_SME_pre-backup
Normal file
13
root/usr/share/BackupPC/bin/BackupPC_SME_pre-backup
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
HOME=/root
|
||||
PATH=/usr/bin:$PATH
|
||||
|
||||
# Backup config and log on the dedicated hard drive
|
||||
mkdir -p /var/lib/BackupPC/etc
|
||||
rsync -ahq --del /etc/BackupPC/ /var/lib/BackupPC/etc/
|
||||
mkdir -p /var/lib/BackupPC/log
|
||||
rsync -ahq --del /var/log/BackupPC /var/lib/BackupPC/log/
|
||||
|
||||
# Run a standard signal-event pre-backup
|
||||
/sbin/e-smith/signal-event pre-backup
|
||||
|
67
root/usr/share/BackupPC/bin/BackupPC_SME_remoteArchive
Executable file
67
root/usr/share/BackupPC/bin/BackupPC_SME_remoteArchive
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# Author: Daniel Berteaud (daniel@firewall-services.com)
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
use lib "/usr/share/BackupPC/lib";
|
||||
use BackupPC::SMEarchive;
|
||||
use strict;
|
||||
|
||||
|
||||
my $logFile = '/tmp/'.genRandName ();
|
||||
|
||||
|
||||
# Sortie erreur standard=fichier de log
|
||||
open (STDERR, ">$logFile");
|
||||
|
||||
my $today = `$path{date} +%F-%kh%M`;
|
||||
my $check = 1;
|
||||
# on inscrit la date en haut du fichier log
|
||||
print STDERR "Starting archive: ".`$path{date}`."\n";
|
||||
|
||||
my %opts=();
|
||||
|
||||
my %params=(
|
||||
'remoteHost'=>"remote_host.com",
|
||||
'remoteUser'=>"backuppc",
|
||||
'remoteDir'=>"/tmp/",
|
||||
'compress'=>"gzip",
|
||||
'cipher'=>'off',
|
||||
'key'=>'/etc/BackupPC/archive.key',
|
||||
'backupNum'=>"-1",
|
||||
'share'=>"*",
|
||||
'hosts'=>'localhost',
|
||||
'sendMailTo'=>'admin',
|
||||
'configFile'=>'/etc/BackupPC/remoteArchive.conf');
|
||||
|
||||
# On lance la récupération des paramètre qui retourne le fichier de config à utiliser
|
||||
$params{configFile} = init($params{configFile});
|
||||
|
||||
%params = readConf(\%params);
|
||||
|
||||
print STDERR "\nYou have requested to archive these hosts: $params{hosts} to this destination: $params{remoteUser}\@$params{remoteHost}:/$params{remoteDir}\n\n";
|
||||
|
||||
remoteArchive($params{remoteHost},$params{remoteUser},$params{remoteDir},$params{hosts},$params{backupNum},$params{share},$params{compress},$params{cipher},$params{key});
|
||||
|
||||
print STDERR "\n\nArchive finished: ".`$path{date}`."\n";
|
||||
|
||||
my $log = `$path{cat} $logFile`;
|
||||
sendMail($params{sendMailTo},'remoteArchive',$log);
|
||||
mvLog('remoteArchive',$logFile,$today);
|
||||
|
||||
exit(0);
|
||||
|
84
root/usr/share/BackupPC/bin/BackupPC_SME_remoteCopyPool
Executable file
84
root/usr/share/BackupPC/bin/BackupPC_SME_remoteCopyPool
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# Author: Daniel Berteaud (daniel@firewall-services.com)
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
use lib "/usr/share/BackupPC/lib";
|
||||
use BackupPC::SMEarchive;
|
||||
use BackupPC::SMEcopyPool;
|
||||
use strict;
|
||||
|
||||
|
||||
my $logFile = '/tmp/'.genRandName ();
|
||||
my $rsyncLog = '/tmp/'.genRandName ();
|
||||
my $check = 1;
|
||||
|
||||
|
||||
# Sortie erreur standard=fichier de log
|
||||
open (STDERR, ">$logFile");
|
||||
|
||||
my $today = `$path{date} +%F-%kh%M`;
|
||||
|
||||
# on inscrit la date en haut du fichier log
|
||||
print STDERR "Starting pool copy: ".`$path{date}`."\n";
|
||||
|
||||
my %opts=();
|
||||
|
||||
my %params=(
|
||||
'remoteHost'=>"remote_host.com",
|
||||
'remoteUser'=>"backuppc",
|
||||
'remoteDir'=>"/tmp/",
|
||||
'source'=>'/var/lib/BackupPC/',
|
||||
'compress'=>"gzip",
|
||||
'extract'=>"yes",
|
||||
'stop'=>"yes",
|
||||
'sendMailTo'=>'admin',
|
||||
'configFile'=>'/etc/BackupPC/remoteCopyPool.conf');
|
||||
|
||||
# On lance la récupération des paramètres qui retourne le fichier de config à utiliser
|
||||
$params{configFile} = init($params{configFile});
|
||||
|
||||
%params = readConf(\%params);
|
||||
|
||||
|
||||
print STDERR "You have requested to copy all your backups ($params{source}) to this destination: $params{remoteUser}\@$params{remoteHost}:$params{remoteDir}\n\n";
|
||||
|
||||
$check = verifTree($params{source});
|
||||
|
||||
if ($check eq 1){
|
||||
if ($params{stop} eq 'yes'){
|
||||
stopBackupPC();
|
||||
}
|
||||
|
||||
copyPool($params{source},"$params{remoteUser}\@$params{remoteHost}:$params{remoteDir}",$logFile,$rsyncLog);
|
||||
remoteCopyPC($params{source},$params{remoteHost},$params{remoteUser},$params{remoteDir},$params{compress},$params{extract},$logFile);
|
||||
if ($params{stop} eq 'yes'){
|
||||
startBackupPC();
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
print STDERR "\naborting, the source directory is probably not the good one\n\n";
|
||||
}
|
||||
|
||||
print STDERR "\n\nCopy finished: ".`$path{date}`."\n";
|
||||
|
||||
my $log = `$path{cat} $logFile`;
|
||||
sendMail($params{sendMailTo},'remoteCopyPool',$log);
|
||||
mvLog('remoteCopyPool',$logFile,$today);
|
||||
|
||||
exit(0);
|
||||
|
85
root/usr/share/BackupPC/bin/BackupPC_SME_usbArchive
Executable file
85
root/usr/share/BackupPC/bin/BackupPC_SME_usbArchive
Executable file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# Author: Daniel Berteaud (daniel@firewall-services.com)
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
use lib "/usr/share/BackupPC/lib";
|
||||
use BackupPC::SMEarchive;
|
||||
#use Getopt::Std;
|
||||
use strict;
|
||||
|
||||
|
||||
my $logFile = '/tmp/'.genRandName ();
|
||||
|
||||
|
||||
# Sortie erreur standard=fichier de log
|
||||
open (STDERR, ">$logFile");
|
||||
|
||||
my $today = `$path{date} +%F-%kh%M`;
|
||||
my $check = 1;
|
||||
# on inscrit la date en haut du fichier log
|
||||
print STDERR "Starting archive: ".`$path{date}`."\n";
|
||||
|
||||
my %opts=();
|
||||
|
||||
my %params=(
|
||||
'split'=>"0",
|
||||
'compress'=>"/bin/gzip",
|
||||
'cipher'=>'off',
|
||||
'key'=>'/etc/BackupPC/archive.key',
|
||||
'backupNum'=>"-1",
|
||||
'share'=>"*",
|
||||
'hosts'=>'localhost',
|
||||
'sendMailTo'=>'admin',
|
||||
'device'=>'/dev/sdc1',
|
||||
'configFile'=>'/etc/BackupPC/usbArchive.conf');
|
||||
|
||||
# On définit un nom aléatoire pour le point de montage
|
||||
$params{destination} = '/var/lib/BackupPC/'.genRandName();
|
||||
# On lance la récupération des paramètre qui retourne le fichier de config à utiliser
|
||||
$params{configFile} = init($params{configFile});
|
||||
|
||||
%params = readConf(\%params);
|
||||
|
||||
print STDERR "\nYou have requested to archive these hosts: $params{hosts} to this destination: $params{destination}\n\n";
|
||||
|
||||
$check = mountUsb($params{destination},$params{device});
|
||||
|
||||
if ($check eq 1){
|
||||
localArchive($params{hosts},$params{backupNum},$params{share},$params{compress},$params{split},$params{cipher},$params{key},$params{destination});
|
||||
}
|
||||
else{
|
||||
print STDERR "\n\nAborting, an error occured while mounting the removable device $params{device} on $params{destination}\n\n";
|
||||
}
|
||||
|
||||
$check = umountUsb($params{destination},$params{device});
|
||||
|
||||
if ($check = 1){
|
||||
print STDERR "\numounting $params{device}: [ OK ]\n";
|
||||
}
|
||||
else{
|
||||
print STDERR "\nan error occured while unmounting the device $params{device} from $params{destination}\n";
|
||||
}
|
||||
|
||||
print STDERR "\n\nArchive finished: ".`$path{date}`."\n";
|
||||
|
||||
my $log = `$path{cat} $logFile`;
|
||||
sendMail($params{sendMailTo},'usbArchive',$log);
|
||||
mvLog('usbArchive',$logFile,$today);
|
||||
|
||||
exit(0);
|
||||
|
93
root/usr/share/BackupPC/bin/BackupPC_SME_usbCopyPool
Executable file
93
root/usr/share/BackupPC/bin/BackupPC_SME_usbCopyPool
Executable file
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# Author: Daniel Berteaud (daniel@firewall-services.com)
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
use lib "/usr/share/BackupPC/lib";
|
||||
use BackupPC::SMEarchive;
|
||||
use BackupPC::SMEcopyPool;
|
||||
use strict;
|
||||
|
||||
|
||||
my $logFile = '/tmp/'.genRandName ();
|
||||
my $rsyncLog = '/tmp/'.genRandName ();
|
||||
my $check = 1;
|
||||
|
||||
|
||||
# Sortie erreur standard=fichier de log
|
||||
open (STDERR, ">$logFile");
|
||||
|
||||
my $today = `$path{date} +%F-%kh%M`;
|
||||
|
||||
# on inscrit la date en haut du fichier log
|
||||
print STDERR "Starting pool copy: ".`$path{date}`."\n";
|
||||
|
||||
my %opts=();
|
||||
|
||||
my %params=(
|
||||
'device'=>'/dev/sdc1',
|
||||
'source'=>'/var/lib/BackupPC',
|
||||
'compress'=>"none",
|
||||
'extract'=>"yes",
|
||||
'stop'=>"yes",
|
||||
'sendMailTo'=>'admin',
|
||||
'configFile'=>'/etc/BackupPC/usbCopyPool.conf');
|
||||
|
||||
# On définit un nom aléatoire pour le point de montage
|
||||
$params{destination} = '/var/lib/BackupPC/'.genRandName();
|
||||
|
||||
# On lance la récupération des paramètres qui retourne le fichier de config à utiliser
|
||||
$params{configFile} = init($params{configFile});
|
||||
|
||||
%params = readConf(\%params);
|
||||
|
||||
|
||||
print STDERR "You have requested to copy all your backups ($params{source}) to this destination: $params{device}\n\n";
|
||||
|
||||
$check = (verifTree($params{source}) && mountUsb($params{destination},$params{device}));;
|
||||
|
||||
|
||||
if ($check eq 1){
|
||||
if ($params{stop} eq 'yes'){
|
||||
stopBackupPC();
|
||||
}
|
||||
copyPool($params{source},$params{destination},$logFile,$rsyncLog);
|
||||
localCopyPC($params{source},$params{destination},$params{compress},$params{extract},$logFile);
|
||||
if ($params{stop} eq 'yes'){
|
||||
startBackupPC();
|
||||
}
|
||||
}
|
||||
else{
|
||||
print STDERR "\naborting, the source directory is probably not the good one, or an error occured while mounting $params{device} on $params{destination}\n\n";
|
||||
}
|
||||
|
||||
$check = umountUsb($params{destination},$params{device});
|
||||
|
||||
if ($check = 1){
|
||||
print STDERR "\numounting $params{device}: [ OK ]\n";
|
||||
}
|
||||
else{
|
||||
print STDERR "\nan error occured while unmounting the device $params{device} from $params{destination}\n";
|
||||
}
|
||||
|
||||
print STDERR "\n\nCopy finished: ".`$path{date}`."\n";
|
||||
|
||||
my $log = `$path{cat} $logFile`;
|
||||
sendMail($params{sendMailTo},'usbCopyPool',$log);
|
||||
mvLog('usblCopyPool',$logFile,$today);
|
||||
|
||||
exit(0);
|
||||
|
301
root/usr/share/BackupPC/lib/BackupPC/SMEarchive.pm
Normal file
301
root/usr/share/BackupPC/lib/BackupPC/SMEarchive.pm
Normal file
@@ -0,0 +1,301 @@
|
||||
# Author: Daniel Berteaud (daniel@firewall-services.com)
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package BackupPC::SMEarchive;
|
||||
use Exporter;
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(%path %opts &checkExec &checkDest &init &readConf &logAndPerform &sendMail &genRandName &mvLog &localArchive &mountUsb &umountUsb &remoteArchive);
|
||||
|
||||
use strict;
|
||||
use Mail::Send;
|
||||
use Getopt::Std;
|
||||
|
||||
|
||||
our %path=();
|
||||
$path{backuppcBin} = '/usr/share/BackupPC/bin/';
|
||||
$path{split} = '/usr/bin/split';
|
||||
$path{date} = '/bin/date';
|
||||
$path{rm} = '/bin/rm';
|
||||
$path{rmdir} = '/bin/rmdir';
|
||||
$path{cat} = '/bin/cat';
|
||||
$path{mkdir} = '/bin/mkdir';
|
||||
$path{par2} = '/bin/ping';
|
||||
$path{ssh} = '/usr/bin/ssh';
|
||||
$path{mount} = '/bin/mount';
|
||||
$path{umount} = '/bin/umount';
|
||||
$path{grep} = '/bin/grep';
|
||||
$path{wc} = '/usr/bin/wc';
|
||||
$path{sudo} = '/usr/bin/sudo';
|
||||
$path{gzip} = '/bin/gzip';
|
||||
$path{bzip2} = ( -x '/usr/bin/pbzip2' ) ? '/usr/bin/pbzip2' : '/usr/bin/bzip2';
|
||||
$path{rsync} = '/usr/bin/rsync';
|
||||
$path{tar} = '/bin/tar';
|
||||
$path{openssl} = '/usr/bin/openssl';
|
||||
$path{nice} = '/bin/nice';
|
||||
|
||||
sub checkExec{
|
||||
# On vérifie que les executables sont bien executables
|
||||
my $ok = 1;
|
||||
foreach (keys %path){
|
||||
if (!-x $path{$_}){$ok = 0;}
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
sub checkDest{
|
||||
# On vérifie les droits d'écriture sur la destination
|
||||
my ($destination) = @_;
|
||||
my $ok = 0;
|
||||
logAndPerform("$path{mkdir} $destination") if (!-d $destination);
|
||||
if ((-w $destination) && (-d $destination)){$ok = 1;}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
# Fonciton qui récupère les arguments, et remplace le fichier de conf si spécifié
|
||||
sub init{
|
||||
my ($configFile) = @_;
|
||||
my %opts;
|
||||
getopts ("hf:", \%opts) || help();
|
||||
|
||||
$opts{h} = '0' if (! defined $opts{h});
|
||||
if (defined $opts{f}){
|
||||
if (-e $opts{f}){
|
||||
print STDERR "using $opts{f} as config file instead of default\n";
|
||||
$configFile = $opts{f};
|
||||
}
|
||||
else{
|
||||
print STDERR "\nIgnoring specified config file $opts{f} because this file doesn't exist. Using default one\n";
|
||||
}
|
||||
}
|
||||
help () if ($opts{h});
|
||||
return $configFile;
|
||||
}
|
||||
|
||||
sub help(){
|
||||
print <<EOF;
|
||||
usage: $0 [-h] [-f config]
|
||||
|
||||
options:
|
||||
-h print this help
|
||||
-f config use config instead of default one.
|
||||
|
||||
EOF
|
||||
exit(1);
|
||||
}
|
||||
|
||||
# Fonction qui parse le fichier de config
|
||||
sub readConf($){
|
||||
my $hRef = shift;
|
||||
my %params;
|
||||
foreach my $key ( keys %$hRef){
|
||||
$params{$key} = $hRef->{$key};
|
||||
}
|
||||
open (PARAMS,"< $params{configFile}") || die "erreur a l'ouverture de $params{configFile}\n";
|
||||
my @params_lus=<PARAMS>;
|
||||
close PARAMS;
|
||||
print STDERR "Parsing config file\n\n";
|
||||
foreach (@params_lus){
|
||||
foreach my $key (keys(%params)){
|
||||
# valeur = partie droite de la ligne contenant $key dans le fichier
|
||||
if ($_ =~ /\s*$key\s*=\s*(.*)/){
|
||||
$params{$key} = $1;
|
||||
print STDERR "key=\"$key\", value=\"$params{$key}\"\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
print STDERR "\n\n";
|
||||
return (%params);
|
||||
}
|
||||
|
||||
# Fonction qui log les commandes et qui les éxecute
|
||||
sub logAndPerform($){
|
||||
my ($cmd) = @_;
|
||||
print STDERR "\nexecuting command\n$cmd\n\n";
|
||||
system($cmd);
|
||||
}
|
||||
|
||||
# Fonction qui envoie le mail contenant le log
|
||||
sub sendMail($$$){
|
||||
my ($sendMailTo,$about,$content) = @_;
|
||||
my $mail = new Mail::Send;
|
||||
$mail->to("$sendMailTo");
|
||||
$mail->set("From","BackupPC");
|
||||
$mail->subject("$about");
|
||||
my $body = $mail->open;
|
||||
print $body $content;
|
||||
$body->close;
|
||||
}
|
||||
|
||||
# fonction qui génère un nom aléatoire pour les fichiers temporaires
|
||||
sub genRandName (){
|
||||
my @c=("A".."Z","a".."z",0..9);
|
||||
my $randomName = join("",@c[map{rand @c}(1..8)]);
|
||||
return $randomName;
|
||||
}
|
||||
|
||||
# fonction qui déplace le fichier de log au bon endroit
|
||||
sub mvLog($$$){
|
||||
my ($type,$file,$today) = @_;
|
||||
if (! -d "/var/log/BackupPC/$type/"){
|
||||
logAndPerform("$path{mkdir} -p /var/log/BackupPC/$type/");
|
||||
}
|
||||
my $content = `$path{cat} $file`;
|
||||
open(LOGFILE, "> /var/log/BackupPC/$type/$today");
|
||||
print LOGFILE $content;
|
||||
close LOGFILE;
|
||||
system("$path{rm} -f $file");
|
||||
}
|
||||
|
||||
sub localArchive($$$$$$$$){
|
||||
my ($hosts,$backupNum,$share,$compress,$split,$cipher,$key,$destination) = @_;
|
||||
my $check = 1;
|
||||
my $extension = 'tar';
|
||||
# on fixe l'extension de l'archive en fonction de la compression utilisée
|
||||
if ($compress eq 'gzip'){$extension = 'tar.gz';}
|
||||
elsif ($compress eq 'bzip2'){$extension = 'tar.bz2';}
|
||||
else{$extension = 'tar';}
|
||||
|
||||
if (! checkExec()){
|
||||
print STDERR "\nError, one of the needed executable is not executable\n";
|
||||
$check = 0;
|
||||
}
|
||||
if (! checkDest($destination)){
|
||||
print STDERR "\nError, $destination is not writable\n";
|
||||
$check = 0;
|
||||
}
|
||||
#if (! checkHosts($params{checkHosts}){
|
||||
# print STDERR "\nError, $hosts is not a valid list of hosts\n";
|
||||
# $check = 0;
|
||||
#}
|
||||
|
||||
if ($check eq 1){
|
||||
my @hosts = split(/\s/,$hosts);
|
||||
|
||||
# On supprime toutes les archives existantes sur la destination pour éviter la fragmentation
|
||||
logAndPerform("$path{rm} -f $destination/*.$extension");
|
||||
|
||||
foreach my $host (@hosts){
|
||||
my $cmd = "$path{backuppcBin}/BackupPC_tarCreate -t -h $host -n $backupNum -s $share . ";
|
||||
if (($compress eq 'gzip') || ($compress eq 'bzip2')){
|
||||
$cmd .= "| $path{nice} -n 10 $path{$compress} -c ";
|
||||
}
|
||||
if (($cipher ne 'off') && (-e $key)){
|
||||
$cmd .= "| $path{nice} -n 10 $path{openssl} enc -$cipher -salt -pass file:$key";
|
||||
$extension .= '.enc';
|
||||
}
|
||||
if ($split eq '0'){
|
||||
$cmd .= "> $destination/$host.$backupNum.$extension";
|
||||
}
|
||||
else{
|
||||
$cmd .= "| $path{split} - -b $split"."m"."$destination/$host.$backupNum.$extension.";
|
||||
}
|
||||
logAndPerform($cmd);
|
||||
}
|
||||
}
|
||||
else{
|
||||
print STDERR "\nFatal error, aborting\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub mountUsb($$){
|
||||
my ($destination,$device) = @_;
|
||||
my $ok = 0;
|
||||
if (!-e $destination){
|
||||
logAndPerform("$path{mkdir} -p $destination");
|
||||
}
|
||||
if (!-e $destination){
|
||||
print STDERR "\n\n$destination doesn't exist and cannot be created\n\n";
|
||||
}
|
||||
else{
|
||||
logAndPerform("$path{sudo} $path{mount} $device $destination");
|
||||
$ok = `$path{mount} | $path{grep} $destination | $path{wc} -l`;
|
||||
chomp($ok);
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
sub umountUsb($$){
|
||||
my ($destination,$device) = @_;
|
||||
my $ok = 0;
|
||||
my $isMounted = `$path{mount} | $path{grep} $destination | $path{wc} -l`;
|
||||
chomp($isMounted);
|
||||
if ($isMounted eq '1'){
|
||||
print STDERR "\n$device seems to be mounted, lets umount it\n";
|
||||
logAndPerform("$path{sudo} $path{umount} -f $destination");
|
||||
}
|
||||
else{
|
||||
print STDERR "\n\nError: $device seems to be already unmounted\n\n";
|
||||
}
|
||||
$isMounted = `$path{mount} | $path{grep} $destination | $path{wc} -l`;
|
||||
chomp($isMounted);
|
||||
if ($isMounted eq '1'){
|
||||
print STDERR "\nError: $device seems to be buzy, lets try to umount it lazily\n";
|
||||
logAndPerform("$path{sudo} $path{umount} -fl $destination");
|
||||
}
|
||||
$isMounted = `$path{mount} | $path{grep} $destination | $path{wc} -l`;
|
||||
chomp($isMounted);
|
||||
if ($isMounted eq '1'){
|
||||
print STDERR "\nError: $device seems to be buzy, lazy umount has failed\n";
|
||||
}
|
||||
if ($isMounted eq '0'){
|
||||
logAndPerform("$path{rmdir} $destination");
|
||||
}
|
||||
$isMounted = `$path{mount} | $path{grep} $destination | $path{wc} -l`;
|
||||
chomp($isMounted);
|
||||
if ($isMounted eq '0'){
|
||||
$ok = 1;
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
sub remoteArchive($$$$$$$$$){
|
||||
my ($remoteHost,$remoteUser,$remoteDir,$hosts,$backupNum,$share,$compress,$cipher,$key) = @_;
|
||||
my $check = 1;
|
||||
my $extension = 'tar';
|
||||
# on fixe l'extension de l'archive en fonction de la compression utilisée
|
||||
if ($compress eq 'gzip'){$extension = 'tar.gz';}
|
||||
elsif ($compress eq 'bzip2'){$extension = 'tar.bz2';}
|
||||
else{$extension = 'tar';}
|
||||
|
||||
if (! checkExec()){
|
||||
print STDERR "\nError, one of the needed executable is not executable\n";
|
||||
$check = 0;
|
||||
}
|
||||
|
||||
if ($check eq 1){
|
||||
my @hosts = split(/\s/,$hosts);
|
||||
|
||||
foreach my $host (@hosts){
|
||||
my $cmd = "$path{backuppcBin}/BackupPC_tarCreate -t -h $host -n $backupNum -s $share . ";
|
||||
if (($compress eq 'gzip') || ($compress eq 'bzip2')){
|
||||
$cmd .= "| $path{$compress} -c ";
|
||||
}
|
||||
if (($cipher ne 'off') && (-e $key)){
|
||||
$cmd .= "| $path{openssl} enc -$cipher -salt -pass file:$key";
|
||||
$extension .= '.enc';
|
||||
}
|
||||
$cmd .= " | $path{ssh} -l $remoteUser $remoteHost \"(cd $remoteDir && $path{cat} > $remoteDir/$host.$backupNum.$extension)\"";
|
||||
|
||||
logAndPerform($cmd);
|
||||
}
|
||||
}
|
||||
else{
|
||||
print STDERR "\nFatal error, aborting\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
1;
|
176
root/usr/share/BackupPC/lib/BackupPC/SMEcopyPool.pm
Normal file
176
root/usr/share/BackupPC/lib/BackupPC/SMEcopyPool.pm
Normal file
@@ -0,0 +1,176 @@
|
||||
# Author: Daniel Berteaud (daniel@firewall-services.com)
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package BackupPC::SMEcopyPool;
|
||||
use lib "/usr/share/BackupPC/lib";
|
||||
use BackupPC::SMEarchive;
|
||||
use Exporter;
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(&verifTree &stopBackupPC &startBackupPC ©Pool &localCopyPC &remoteCopyPC);
|
||||
|
||||
# Fonction qui vérifie (grossièrement) l'arborescence de la source pour la copie de pool
|
||||
sub verifTree($){
|
||||
my ($source) = @_;
|
||||
print STDERR "\ntesting $source\n";
|
||||
my $ok = 1;
|
||||
foreach ("$source","$source/pc","$source/pool","$source/cpool"){
|
||||
if (!-d "$_"){
|
||||
print STDERR "$_ is not a valid directory, aborting\n";
|
||||
$ok = 0;
|
||||
}
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
# Fonction qui arrête le service BackupPC
|
||||
sub stopBackupPC(){
|
||||
if (-e '/var/log/BackupPC/BackupPC.pid'){
|
||||
$pid = `$path{cat} /var/log/BackupPC/BackupPC.pid`;
|
||||
print STDERR "BackupPC is running (pid=$pid), you have requested to stop it\n";
|
||||
logAndPerform("$path{sudo} /etc/rc.d/init.d/backuppc stop");
|
||||
}
|
||||
elsif ((! -e '/var/log/BackupPC/BackupPC.pid') && ($stop eq 'yes')){
|
||||
print STDERR "\nYou have requested to stop BackupPC daemon but it seems that it's not running\n";
|
||||
}
|
||||
}
|
||||
|
||||
# Fonction qui démarre le service BackupPC
|
||||
sub startBackupPC(){
|
||||
if (! -e '/var/log/BackupPC/BackupPC.pid'){
|
||||
print STDERR "\n\nrestarting BackupPC deamon\n\n";
|
||||
logAndPerform("$path{sudo} /etc/rc.d/init.d/backuppc start");
|
||||
}
|
||||
}
|
||||
# Fonction qui copie les données de backuppc sous forme brut
|
||||
# Ne copie pas le répertoire pc/ (pb de hardlinks, gérés à part)
|
||||
# Peut être utilisée pour une copie local ou distante
|
||||
sub copyPool($$$$){
|
||||
my ($source,$destination,$logFile,$rsyncLog) = @_;
|
||||
|
||||
|
||||
# Si /etc/BackupPC exist, on le sauvegarde dans $params{source}/etc
|
||||
if(-d '/etc/BackupPC'){
|
||||
logAndPerform("$path{mkdir} -p $source/etc") if (!-d "$source/etc");
|
||||
logAndPerform("$path{rsync} -ah --del --stats /etc/BackupPC/ $source/etc/ > $rsyncLog");
|
||||
print STDERR `$path{cat} $rsyncLog`;
|
||||
}
|
||||
# idem pour les logs
|
||||
if(-d '/var/log/BackupPC'){
|
||||
logAndPerform("$path{mkdir} -p $source/log") if (!-d "$source/log");
|
||||
logAndPerform("$path{rsync} -ah --del --stats /var/log/BackupPC/ $source/log/ > $rsyncLog");
|
||||
print STDERR `$path{cat} $rsyncLog`;
|
||||
}
|
||||
|
||||
# commande qui sync en non récursif pour créer les rep nécessaires
|
||||
logAndPerform("$path{rsync} -qlptgoDHhd --stats --del $source/ $destination/ > $rsyncLog");
|
||||
print STDERR `$path{cat} $rsyncLog`;
|
||||
|
||||
# la commande suivante sync tout sauf les rep pc, pool et cpool (pour éviter de saturer la ram)
|
||||
logAndPerform("$path{rsync} -ah --del --stats --exclude=cpool/ --exclude=pool/ --exclude=pc/ $source/ $destination/ > $rsyncLog");
|
||||
print STDERR `$path{cat} $rsyncLog`;
|
||||
|
||||
# Maintenant, on sync le rep pool
|
||||
logAndPerform("$path{rsync} -ah --del --stats $source/pool/ $destination/pool/ > $rsyncLog");
|
||||
print STDERR `$path{cat} $rsyncLog`;
|
||||
|
||||
# Puis le cpool
|
||||
logAndPerform("$path{rsync} -ah --del --stats $source/cpool/ $destination/cpool/ > $rsyncLog");
|
||||
print STDERR `$path{cat} $rsyncLog`;
|
||||
|
||||
}
|
||||
|
||||
# Fonction qui copie le répertoire pc/ vers un rep local (en utilisant BackupPC_tarPCCopy)
|
||||
sub localCopyPC($$$$$){
|
||||
my ($source,$destination,$compress,$extract,$logFile) = @_;
|
||||
my $archName = 'pc.tar';
|
||||
my $cmd = ();
|
||||
my @pipe = ();
|
||||
my $tarOpts = 'xPf';
|
||||
my $main = '';
|
||||
|
||||
# on vide le répertoire "pc"
|
||||
if ($destination ne ''){
|
||||
logAndPerform("$path{rm} -Rf $destination/pc/*");
|
||||
}
|
||||
|
||||
push(@pipe,"$path{backuppcBin}/BackupPC_tarPCCopy $source/pc/ |");
|
||||
|
||||
if ($compress eq 'gzip'){
|
||||
push (@pipe," $path{gzip} -c |");
|
||||
$archName = "pc.tar.gz";
|
||||
$tarOpts = 'xPzf';
|
||||
}
|
||||
elsif ($compress eq 'bzip2'){
|
||||
push (@pipe," $path{bzip2} -c |");
|
||||
$archName = "pc.tar.bz2";
|
||||
$tarOpts = 'xPjf';
|
||||
}
|
||||
if ($extract eq 'yes'){
|
||||
push (@pipe,"(cd $destination/pc/ && $path{tar} $tarOpts -)");
|
||||
}
|
||||
else{
|
||||
push (@pipe,"$path{cat} > $destination/pc/$archName");
|
||||
}
|
||||
|
||||
foreach (@pipe){
|
||||
$main = $main.$_;
|
||||
}
|
||||
|
||||
logAndPerform($main);
|
||||
}
|
||||
|
||||
# Fonciton qui copie le rep pc/ sur une machine distante (toujours en utilisant BackuPPC_tarPCCopy)
|
||||
sub remoteCopyPC($$$$$$$){
|
||||
my ($source,$remoteHost,$remoteUser,$remoteDir,$compress,$extract,$logFile) = @_;
|
||||
my $archName = 'pc.tar';
|
||||
my $cmd = ();
|
||||
my @pipe = ();
|
||||
my $tarOpts = 'xPf';
|
||||
my $main = '';
|
||||
|
||||
# on vide le répertoire "pc"
|
||||
if ($remoteDir ne ''){
|
||||
logAndPerform("$path{ssh} -l $remoteUser $remoteHost \"$path{rm} -Rf $remoteDir/pc/*\"");
|
||||
}
|
||||
|
||||
push(@pipe,"$path{backuppcBin}/BackupPC_tarPCCopy $source/pc/ |");
|
||||
|
||||
if ($compress eq 'gzip'){
|
||||
push (@pipe," $path{gzip} -c |");
|
||||
$archName = "pc.tar.gz";
|
||||
$tarOpts = 'xPzf';
|
||||
}
|
||||
elsif ($compress eq 'bzip2'){
|
||||
push (@pipe," $path{bzip2} -c |");
|
||||
$archName = "pc.tar.bz2";
|
||||
$tarOpts = 'xPjf';
|
||||
}
|
||||
if ($extract eq 'yes'){
|
||||
push (@pipe,"$path{ssh} -l $remoteUser $remoteHost \"(cd $remoteDir/pc/ && $path{tar} $tarOpts -)\"");
|
||||
}
|
||||
else{
|
||||
push (@pipe,"$path{ssh} -l $remoteUser $remoteHost \"$path{cat} > $remoteDir/pc/$archName\"");
|
||||
}
|
||||
|
||||
foreach (@pipe){
|
||||
$main = $main.$_;
|
||||
}
|
||||
|
||||
logAndPerform($main);
|
||||
}
|
||||
|
||||
|
||||
1;
|
Reference in New Issue
Block a user