1 2 3 4 5 | .d..t...... t1/a/ *deleting t1/a/3 .d..t...... t1/b/ >f.st...... t1/b/1 >f+++++++++ t1/b/6 |
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 82 | #!/usr/bin/perl use warnings; use strict; use File::Basename; use File:ath; my $source = shift; my $dest = shift; my $encdest = shift; if (!defined($source) || !defined($dest) || !defined($encdest)) { print "Error: Not enough arguments!\n"; print "Usage: $0 source destination encrypteddest\n"; exit(1); } print STDERR "Running rsync between $source and $dest ($encdest)\n"; system("rsync --delete --recursive --times -og --links --perms " . "--hard-links --itemize-changes $source $dest " . ">/tmp/$$.rsynclog 2>&1"); open(DATA,"/tmp/$$.rsynclog") or die "Couldn't open the rsynclog\n"; my @changedfiles; my @delfiles; while(<DATA>) { next if (m/sending incremental file list/); chomp; last if (length($_) == 0); my ($changes,$filename) = split; push @changedfiles,$filename if ($changes =~ m/^>f/); push @delfiles,$filename if ($changes =~ m/^\*del/); } close(DATA); my $counter = 0; foreach my $file (@changedfiles) { if (-f "$dest/$file") { my $sourcename = encode_filename("$dest/$file"); my $destname = encode_filename("$encdest/$file"); my $dirname = dirname("$encdest/$file"); mkpath($dirname); system(sprintf('cat "%s" |openssl enc -des3 ' . '-pass file:/var/lib/passphrase -a >"%s"', $sourcename,$destname)); $counter++; } } my $delcounter = 0; foreach my $file (@delfiles) { unlink("$encdest/$file"); $delcounter++; } print STDERR "Finished (changed: $counter, deleted: $delcounter)\n"; unlink("/tmp/$$.rsynclog"); sub encode_filename { my ($filename) = @_; $filename =~ s/ /\\ /g; $filename =~ s/'/\\'/g; $filename =~ s/"/\\"/g; $filename =~ s/\(/\\(/g; $filename =~ s/\)/\\)/g; $filename =~ s/&/\\&/g; $filename =~ s/#/\\#/g; return($filename); } |
1 2 3 | system("rsync --delete --recursive --times -og --links --perms " . "--hard-links --itemize-changes $source $dest " . ">/tmp/$$.rsynclog 2>&1"); |
1 2 3 4 5 6 7 8 9 | while(<DATA>) { next if (m/sending incremental file list/); chomp; last if (length($_) == 0); my ($changes,$filename) = split; push @changedfiles,$filename if ($changes =~ m/^>f/); push @delfiles,$filename if ($changes =~ m/^\*del/); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | foreach my $file (@changedfiles) { if (-f "$dest/$file") { my $sourcename = encode_filename("$dest/$file"); my $destname = encode_filename("$encdest/$file"); my $dirname = dirname("$encdest/$file"); mkpath($dirname); system(sprintf('cat "%s" |openssl enc -des3 ' . '-pass file:/var/lib/passphrase -a >"%s"', $sourcename,$destname)); $counter++; } } |
1 2 3 4 5 | foreach my $file (@delfiles) { unlink("$encdest/$file"); $delcounter++; } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |