Ce script a pour but de récupérer un dossier ftp et tous ses sous dossiers puis de le compresser.
- Instalation :
Copier les lignes de script dans un fichier backup.pl.
Le script :
- #!/usr/bin/perl
- use strict;
- use Net::FTP;
- use Net::FTP::Recursive;
- use Socket;
- #use warnings;
-
- ##################################
- # #
- # Debut definition des variables #
- # #
- ##################################
-
- my $rep_bck = "/var/backup/"; # dossier local pour deposer la sauvegarde
-
-
- ##################################
- # #
- # Fin definition des variables #
- # #
- ##################################
-
- print("*********** Windows Backup ************");
- if ( ! @ARGV)
- {
- die(print("*********** FATAL ERROR - No IP server ************"));
- }
- else
- {
- my $Vargv = $ARGV[0];
- my @IP = split(/./, $Vargv);
- # print "$ARGV[0] n";
- my $nbBlockIP = @IP;
- # print "$nbBlockIP n";
-
- if ( $nbBlockIP != 4)
- {
- die(print("*********** FATAL ERROR - No IP server or incomplet IP ************"));
- }
- while (@IP)
- {
- my $bloqueIP = (shift @IP);
- # print "$bloqueIPn";
- if ($bloqueIP !~ m/^d+$/)
- {
- die(print("*********** FATAL ERROR - No IP server or not valid IP ************"));
- }
- elsif ($bloqueIP >= 255)
- {
- die(print("*********** FATAL ERROR - not valid IP ************"));
- }
-
- }
- }
- my @IP = split(/./, @ARGV[0]);
- my $ts = int(((time()/60)/60)/24);
- #print "$ARGV[0] n";
- #print "$ARGV[1] n";
- #print "$ARGV[2] n";
- #print "n$rep_bckn";
- #print "$tsn";
- #print "@IP[0]-@IP[1]-@IP[2]-@IP[3]n";
- `/bin/mkdir -p "$rep_bck"` if ( ! -d $rep_bck );
- `/bin/mkdir -p "$rep_bck/@ARGV[0]"` if ( ! -d $rep_bck."/".@ARGV[0] );
-
- if ( -d $rep_bck."/".@ARGV[0] ) {
-
- print "recuperation de tous les fichiersn";
- chdir $rep_bck."/".@ARGV[0];
-
- my $ftp = Net::FTP::Recursive->new(@ARGV[0], Timeout => 120, Debug => 0);
- $ftp->login(@ARGV[1],@ARGV[2]);
- $ftp->pasv ();
- $ftp->binary();
- $ftp->rget( "/*" ) or warn "impossible de telecharger ", $ftp->message;
- $ftp->quit;
- }
-
- print "creation de l'archive";
-
- `tar -cvzf $rep_bck/fichier_backup.@ARGV[1].$ts.tar.gz $rep_bck/@ARGV[0] --remove-files`;
- Configuration :
Ajustez le dossier dans le quel la sauvegarde sera faites en modifiant la ligne 14 du script.
- Utilisation :
L'utilisation du script est très simple, vous passez en paramètre l'ip du serveur, le login et le mot de passe.
exemple : ./backup.pl 127.0.0.1 mon_login mon_pass
|