| 49 | 1 package Deployment::Batch::Backup; | 
|  | 2 use base qw(Deployment::Batch::Generic); | 
|  | 3 use Common; | 
|  | 4 use File::Copy; | 
|  | 5 | 
|  | 6 BEGIN { | 
|  | 7     DeclareProperty Action => ACCESS_READ; | 
|  | 8 } | 
|  | 9 | 
|  | 10 sub CTOR { | 
|  | 11     my ($this,$actionName,$actionArg) = @_; | 
|  | 12 | 
|  | 13     $this->{$Action} = { Name => $actionName, Arg => $actionArg }; | 
|  | 14 } | 
|  | 15 | 
|  | 16 sub Run { | 
|  | 17     my ($this) = @_; | 
|  | 18 | 
|  | 19     my $tmpObj; | 
|  | 20 | 
|  | 21     # we are in the immediate mode | 
|  | 22     if ($this->{$Action}{Name} eq 'File') { | 
|  | 23         $this->Log("Backup file: $this->{$Action}{Arg}"); | 
|  | 24         if (-e $this->{$Action}{Arg}) { | 
|  | 25 | 
|  | 26             Deployment::Batch->Temp( File => \$tmpObj ) or die "Failed to create temp file" ; | 
|  | 27 | 
|  | 28             copy ($this->{$Action}{Arg}, $tmpObj->filename) or die "Failed to backup"; | 
|  | 29             $this->{$Action}{Result} = $tmpObj->filename; | 
|  | 30         } | 
|  | 31     } else { | 
|  | 32         die "Don't know how to backup the $this->{$Action}{Name}"; | 
|  | 33     } | 
|  | 34 } | 
|  | 35 | 
|  | 36 sub Rollback { | 
|  | 37     my ($this) = @_; | 
|  | 38     if ($this->{$Action}{Name} eq 'File') { | 
|  | 39         $this->Log("Revert file: $this->{$Action}{Arg}"); | 
|  | 40         if ($this->{$Action}{Result}) { | 
|  | 41             copy ($this->{$Action}{Result}, $this->{$Action}{Arg}) or die "Failed to backup"; | 
|  | 42         } else { | 
|  | 43             unlink $this->{$Action}{Arg} if -f $this->{$Action}{Arg}; | 
|  | 44         } | 
|  | 45     } | 
|  | 46 } | 
|  | 47 | 
|  | 48 1; |