1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
sub backup_dir {
local ($path_from,$path_to,$mode) = @_;
$path_from =~ s$//$/$g;
$path_to =~ s$//$/$g;
local (*DIR);
if ($mode ne "test") {
print "<UL><LI>backup de $path_from";
}
opendir( DIR, "$path_from" ) || &web_error("Impossible d'ouvrir le répertoire $path_from<BR>Erreur: $!","$cgiurl");
while ( $entry = readdir( DIR ) ) {
$type = ( -d "$path_from/$entry" ) ? "dir" : "file";
if ( ($type eq "dir") && ($entry ne "..") && ($entry ne ".") ) {
if (!-d "$path_to/$entry") {
if ($mode ne "test") {
&web_error("Impossible de se placer sur le répertoire $path_to <BR>Erreur: $!\n","$cgiurl") unless chdir ("$path_to");
&web_error("Impossible de créer le sous répertoire $entry dans $path_to <BR>Erreur: $!\n","$cgiurl") unless mkdir "$entry" , 0777;
print "<BR><b>Création de $path_to/$entry</b>\n";
}
}
&backup_dir("$path_from/$entry","$path_to/$entry","$mode");
}
if ( ( $type eq "file" ) && ($entry ne "..") && (compress($entry) ne "") ) {
($dev_source,
$ino_source,
$mode_source,
$nlink_source,
$uid_source,
$gid_source,
$rdev_source,
$size_source,
$atime_source,
$mtime_source,
$ctime_source,
$blksize_source,
$blocks_source) = stat("$path_from/$entry");
($dev_dest,
$ino_dest,
$mode_dest,
$nlink_dest,
$uid_dest,
$gid_dest,
$rdev_dest,
$size_dest,
$atime_dest,
$mtime_dest,
$ctime_dest,
$blksize_dest,$blocks_dest) = stat("$path_to/$entry");
if ( ($atime_source != $atime_dest) && ($mtime_source != $mtime_dest) ) {
if ($mode ne "test") {
$perms1 = $mode_source & 07777;
$oct_perms1 = sprintf "%lo", $perms1;
print "<table border><tr><td colspan=5>$entry ($size_source bytes)</td></tr>\n";
print "<tr><td></td><td>A</td><td>M</td><td>C</td><td>Mode</td></tr>\n";
print "<tr><td>source</td><td>$atime_source</td><td>$mtime_source</td><td>$ctime_source</td><td>$mode_source : $oct_perms1</td></tr>\n";
if (-e "$path_to/$entry") {
$perms2 = $mode_dest & 07777;
$oct_perms2 = sprintf "%lo", $perms2;
print "<tr><td>destination</td><td>$atime_dest</td><td>$mtime_dest</td><td>$ctime_dest</td><td>$mode_dest : $oct_perms2</td></tr>\n";
} else {
print "<tr><td>destination</td><td colspan=4><font color=red>Création</font></td></tr>\n";
}
print "</table>\n";
©_file("$path_from/$entry","$path_to/$entry");
$perm = "0"."$oct_perms1";
chmod 0666 , "$path_to/$entry";
print "<br><font color=blue><b>Copie ok</b></font>";
($atime, $mtime) = (stat("$path_from/$entry"))[8,9];
utime $atime, $mtime, "$path_to/$entry";
}
$nbfilebck +=1;
}
}
}
if ($mode ne "test") {
print "</LI></UL>";
}
closedir( DIR );
return;
} |
Partager