File: backup.pl - Tab length: 1 2 4 8 - Lines: on off - No wrap: on off

01: #! /usr/bin/perl
02: 
03: use File::Copy;
04: 
05: my  $from = "/var/local/backup/from/";
06: my  $to = "/var/local/backup/to/";
07: 
08: opendir (H1, $from) || die ("error: cannot read input directory");
09: opendir (H2, $to) || die ("error: cannot read output directory");
10: 
11: my  @files1 = readdir (H1);
12: my  %files2 = map { $_ => 1 } readdir (H2);
13: 
14: closedir (H1);
15: closedir (H2);
16: 
17: foreach $file (@files1)
18: {
19:     if ($file != '.' && $file != '..')
20:     {
21:         my  $i = 0;
22: 
23:         while ($files2{"$file.$i"})
24:         {
25:             $i = $i + 1;
26:         }
27: 
28:         if ($i == 0 || -s "$from/$file" != -s ("$to/$file." . ($i - 1)))
29:         {
30:             copy ("$from/$file", "$to/$file.$i");
31:             print "backup $file as $file.$i\n";
32:         }
33:     }
34: }