Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1252 → Rev 1253

/fsbackup/trunk/fsbackup.pl
493,98 → 493,105
 
 
########################################
sub add_to_backup{
my($file_name, $file_dir, $md5_checksum_stat, $checksum_stat);
sub add_to_backup
{
my($file_name, $file_dir, $md5_checksum_stat, $checksum_stat, $file_fullpath_esc);
my($tmp, $stat_mode, $stat_uid, $stat_gid, $stat_size, $stat_mtime, $stat_time, $stat_flags);
$file_name = $_;
$file_fullpath = $File::Find::name;
$file_dir = $File::Find::dir;
my $file_fullpath_esc = $file_fullpath;
$file_name = $_;
$file_fullpath = $File::Find::name;
$file_dir = $File::Find::dir;
$file_fullpath_esc = $file_fullpath;
$file_fullpath_esc =~ s/\'/\'\\\'\'/g;
 
# Создаем список директорий
if ((-d $file_fullpath) && (! -l $file_fullpath)){
if (check_path($file_dir, $file_name) == 1){
if ($cfg_backup_style ne "hash"){
($tmp, $tmp, $stat_mode, $tmp, $stat_uid, $stat_gid, $tmp, $stat_size, $tmp, $stat_mtime, $stat_time, $tmp, $tmp, $tmp, $tmp, $tmp, $stat_flags, $tmp) = lstat($file_fullpath);
$stat_mode = sprintf ("%04o", $stat_mode & 07777);
$file_fullpath_esc =~ s/^\/(.*)$/$1/;
my ($sec,$min,$hour,$mday,$mon,$year) = localtime($stat_time);
$stat_time = sprintf ("%4.4d%2.2d%2.2d%2.2d%2.2d.%2.2d",
$year+1900,$mon+1,$mday,$hour,$min,$sec);
print DIRS "mkdir -p '$file_fullpath_esc'\n";
print DIRS "chmod $stat_mode '$file_fullpath_esc'\n";
print DIRS "chown $stat_uid:$stat_gid '$file_fullpath_esc'\n";
print DIRS "touch -t $stat_time '$file_fullpath_esc'\n";
if($stat_flags) {
print DIRS "chflags "
. ($stat_flags & UF_NODUMP ? "nodump," : "")
. ($stat_flags & UF_IMMUTABLE ? "uchg," : "")
. ($stat_flags & UF_APPEND ? "uappnd," : "")
. ($stat_flags & UF_OPAQUE ? "opaque," : "")
. ($stat_flags & UF_NOUNLINK ? "uunlnk," : "")
. ($stat_flags & SF_ARCHIVED ? "arch," : "")
. ($stat_flags & SF_IMMUTABLE ? "schg," : "")
. ($stat_flags & SF_APPEND ? "sappnd," : "")
. ($stat_flags & SF_NOUNLINK ? "sunlnk," : "")
. " '$file_fullpath_esc'\n";
}
if((-d $file_fullpath) && (! -l $file_fullpath)) {
if(check_path($file_dir, $file_name) == 1) {
if($cfg_backup_style ne "hash") {
($tmp, $tmp, $stat_mode, $tmp, $stat_uid, $stat_gid, $tmp, $stat_size, $tmp, $stat_mtime,
$stat_time, $tmp, $tmp, $tmp, $tmp, $tmp, $stat_flags, $tmp) = lstat($file_fullpath);
$stat_mode = sprintf ("%04o", $stat_mode & 07777);
$file_fullpath_esc =~ s/^\/(.*)$/$1/;
my ($sec,$min,$hour,$mday,$mon,$year) = localtime($stat_time);
$stat_time = sprintf("%4.4d%2.2d%2.2d%2.2d%2.2d.%2.2d",
$year+1900, $mon+1, $mday, $hour, $min, $sec);
print DIRS "mkdir -p '$file_fullpath_esc'\n";
print DIRS "chmod $stat_mode '$file_fullpath_esc'\n";
print DIRS "chown $stat_uid:$stat_gid '$file_fullpath_esc'\n";
print DIRS "touch -t $stat_time '$file_fullpath_esc'\n";
if($stat_flags) {
print DIRS "chflags "
. ($stat_flags & UF_NODUMP ? "nodump," : "")
. ($stat_flags & UF_IMMUTABLE ? "uchg," : "")
. ($stat_flags & UF_APPEND ? "uappnd," : "")
. ($stat_flags & UF_OPAQUE ? "opaque," : "")
. ($stat_flags & UF_NOUNLINK ? "uunlnk," : "")
. ($stat_flags & SF_ARCHIVED ? "arch," : "")
. ($stat_flags & SF_IMMUTABLE ? "schg," : "")
. ($stat_flags & SF_APPEND ? "sappnd," : "")
. ($stat_flags & SF_NOUNLINK ? "sunlnk," : "")
. " '$file_fullpath_esc'\n";
}
 
unless($stat_flags & UF_NODUMP) {
$cur_backup_size += int(length($file_fullpath)/100.0 + 1)*512;
if ($cfg_maximum_archive_size > 0 && $cur_backup_size + 10240 >= $cfg_maximum_archive_size){
my $old_val = $cur_backup_size - $stat_size - int(length($file_fullpath)/100.0 + 1)*512;
my $tmp_pos= $#volume_position+1;
print "Volume $tmp_pos Done. Size: $old_val\n" if ($cfg_verbose == &VERB_ALL);
$cur_backup_size = $stat_size + int(length($file_fullpath)/100.0 + 1)*512 + 1536;
push @volume_position, $list_lines_cnt;
}
$active_hash_new{$file_fullpath} = "D";
check_update($file_fullpath, "D", $file_fullpath, $stat_size);
}
else {
push @fs_notpath, "$file_dir/$file_name"; # if nodump - skip all subitems
if ($cfg_stopdir_prune == 1){
$File::Find::prune = 1;
return;
}
}
}
} else {
if ($cfg_stopdir_prune == 1){
$File::Find::prune = 1;
return;
}
unless($stat_flags & UF_NODUMP) {
$cur_backup_size += int(length($file_fullpath)/100.0 + 1) * 512;
if($cfg_maximum_archive_size > 0 && $cur_backup_size + 10240 >= $cfg_maximum_archive_size) {
my $old_val = $cur_backup_size - $stat_size - int(length($file_fullpath)/100.0 + 1) * 512;
my $tmp_pos = $#volume_position+1;
print "Volume $tmp_pos Done. Size: $old_val\n" if($cfg_verbose == &VERB_ALL);
$cur_backup_size = $stat_size + int(length($file_fullpath)/100.0 + 1) * 512 + 1536;
push @volume_position, $list_lines_cnt;
}
$active_hash_new{$file_fullpath} = "D";
check_update($file_fullpath, "D", $file_fullpath, $stat_size);
}
else {
push @fs_notpath, "$file_dir/$file_name"; # if nodump - skip all subitems
if($cfg_stopdir_prune == 1) {
$File::Find::prune = 1;
return;
}
}
}
# Работаем с файлами
} elsif ((-f $file_fullpath) || (-l $file_fullpath)){
if (check_path($file_dir, $file_name) == 1){
($tmp, $tmp, $stat_mode, $tmp, $stat_uid, $stat_gid, $tmp, $stat_size, $tmp, $stat_mtime, $stat_time, $tmp, $tmp, $tmp, $tmp, $tmp, $stat_flags, $tmp) = lstat($file_fullpath);
unless($stat_flags & UF_NODUMP) {
$checksum_stat= md5_base64("$stat_mtime/$stat_size/$stat_mode/$stat_uid/$stat_gid");
# $file_fullpath_md5 = md5_base64($file_fullpath);
$file_fullpath_md5 = $file_fullpath;
if ($cfg_time_limit != 0 && $cur_time - $cfg_time_limit > $stat_mtime){
print "Time limit: $cur_time - $cfg_time_limit > $stat_mtime, file $file_fullpath ignored.\n" if ($cfg_verbose == &VERB_ALL);
next;
}
if ($cfg_size_limit != 0 && $cfg_size_limit < $stat_size){
print "Size limit: $cfg_size_limit < $stat_size, file $file_fullpath ignored.\n" if ($cfg_verbose == &VERB_ALL);
next;
}
}
else {
if($cfg_stopdir_prune == 1) {
$File::Find::prune = 1;
return;
}
}
}
# Работаем с файлами
elsif((-f $file_fullpath) || (-l $file_fullpath)) {
if(check_path($file_dir, $file_name) == 1) {
($tmp, $tmp, $stat_mode, $tmp, $stat_uid, $stat_gid, $tmp, $stat_size, $tmp, $stat_mtime,
$stat_time, $tmp, $tmp, $tmp, $tmp, $tmp, $stat_flags, $tmp) = lstat($file_fullpath);
unless($stat_flags & UF_NODUMP) {
$checksum_stat= md5_base64("$stat_mtime/$stat_size/$stat_mode/$stat_uid/$stat_gid");
# $file_fullpath_md5 = md5_base64($file_fullpath);
$file_fullpath_md5 = $file_fullpath;
if($cfg_time_limit != 0 && $cur_time - $cfg_time_limit > $stat_mtime) {
print "Time limit: $cur_time - $cfg_time_limit > $stat_mtime, file $file_fullpath ignored.\n"
if($cfg_verbose == &VERB_ALL);
next;
}
if($cfg_size_limit != 0 && $cfg_size_limit < $stat_size) {
print "Size limit: $cfg_size_limit < $stat_size, file $file_fullpath ignored.\n"
if($cfg_verbose == &VERB_ALL);
next;
}
 
if (($cfg_checksum eq "md5") && (! -l $file_fullpath)){
($md5_checksum_stat, $tmp) = split(/\s+/, `$prog_md5sum '$file_fullpath_esc'`);
$active_hash_new{$file_fullpath_md5} = "$checksum_stat/$md5_checksum_stat";
check_update($file_fullpath, "$checksum_stat/$md5_checksum_stat", $file_fullpath_md5, $stat_size);
} else {
$active_hash_new{$file_fullpath} = $checksum_stat;
check_update($file_fullpath, $checksum_stat, $file_fullpath, $stat_size);
}
}
if(($cfg_checksum eq "md5") && (! -l $file_fullpath)) {
($md5_checksum_stat, $tmp) = split(/\s+/, `$prog_md5sum '$file_fullpath_esc'`);
$active_hash_new{$file_fullpath_md5} = "$checksum_stat/$md5_checksum_stat";
check_update($file_fullpath, "$checksum_stat/$md5_checksum_stat", $file_fullpath_md5, $stat_size);
} else {
$active_hash_new{$file_fullpath} = $checksum_stat;
check_update($file_fullpath, $checksum_stat, $file_fullpath, $stat_size);
}
}
}
}
}
 
###############################################