jicao
07/09/2012, 05h22
Voila j'ai modifié le script et ajouté quelques modifications au HOW-TO.
Merci starouille pour la suggestion.
Merci starouille pour la suggestion.
# Run the pre-backup command, if any my $err; my $premsg = ""; if ($backup->{'pre'} =~ /\S/) { my $preout = &backquote_command("($backup->{'pre'}) 2>&1 {'pre'})."\n". $preout."\n"; if ($?) { $err = $text{'email_prefailed'}; } } # Do it my @mods = split(/\s+/, $backup->{'mods'}); my $size; if (!$err) { $err = &execute_backup(\@mods, $backup->{'dest'}, \$size, undef, $backup->{'configfile'}, $backup->{'nofiles'}, [ split(/\t+/, $backup->{'others'}) ]); } # Run the post-backup command, if any my $postmsg = ""; if (!$err && $backup->{'post'} =~ /\S/) { my $postout = &backquote_command("($backup->{'post'}) 2>&1 {'post'})."\n". $postout."\n"; }
Command to run after backup
Any shell command that you enter into this field will be run as root just after the backup is finished, either manually or on schedule. Output from the command will be included in the dump report.
# nano delete_old_backup.pl
#!/usr/bin/perl use strict; use Net::FTP; my $host = "host"; # ip du serveur ftp my $user = "user"; # user ftp my $passwd = "pass"; # mot de passe du ftp my $dir = "/"; # dossier des fichiers a verifier my $day = 1; # nombre de jours souhaités #my $interval = 3600*24*$day; my $passive = 1; my $DEBUG = 1; my $ftp = Net::FTP->new($host, Debug => $DEBUG, Passive => $passive) or die "Can't open $host\n"; $ftp->login($user, $passwd) or die "Can't log in as $user\n"; $ftp->cwd($dir) or die "Can't chdir to $dir\n"; my @files = $ftp->ls("*$ARGV[0]*"); foreach my $file (@files) { if ($file != "." || $file != ".." || $file != ".banner" || $file != ".ftpquota") { my $file_mdtm = $ftp->mdtm($file) or die "Can't find $file in $dir\n"; if (time - $file_mdtm >= $interval) { print "File $file is older than $interval secs: deleted\n"; $ftp->delete($file) unless $DEBUG; } } }
# chmod +x delete_old_backup.pl
# ./delete_old_backup.pl file1
... Net::FTP=GLOB(0x8f5ef0)>>> MDTM 2012_09_04_file1_backup.tar Net::FTP=GLOB(0x8f5ef0)<<< 213 20120904081624 File 2012_09_04_file1_backup.tar is older than 18000 secs: deleted ...
my $DEBUG = 1;
my $DEBUG = 0;
if(backup = ok) exec(/chemin/vers/votre/script/./delete_old_backup.pl NOM_DU_BACKUP)
/chemin/vers/votre/script/./delete_old_backup.pl NOM_DU_BACKUP
@monthly /chemin/vers/votre/script/./delete_old_backup.pl NOM_DU_BACKUP
./delete_old_backup.pl site1
./delete_old_backup.pl site1_files
./delete_old_backup.pl backup_site1_files.tar