annotate Lib/Deployment/Batch/Backup.pm @ 21:fafe56cfcd69

temp commit
author Sergey
date Wed, 30 Sep 2009 10:25:41 +0400
parents 03e58a454b20
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 package Deployment::Batch::Backup;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 use base qw(Deployment::Batch::Generic);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 use Common;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4 use File::Copy;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 DeclareProperty Action => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 sub CTOR {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11 my ($this,$actionName,$actionArg) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13 $this->{$Action} = { Name => $actionName, Arg => $actionArg };
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16 sub Run {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19 my $tmpObj;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21 # we are in the immediate mode
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22 if ($this->{$Action}{Name} eq 'File') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23 $this->Log("Backup file: $this->{$Action}{Arg}");
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24 if (-e $this->{$Action}{Arg}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26 Deployment::Batch->Temp( File => \$tmpObj ) or die "Failed to create temp file" ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28 copy ($this->{$Action}{Arg}, $tmpObj->filename) or die "Failed to backup";
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29 $this->{$Action}{Result} = $tmpObj->filename;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 die "Don't know how to backup the $this->{$Action}{Name}";
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36 sub Rollback {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38 if ($this->{$Action}{Name} eq 'File') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 $this->Log("Revert file: $this->{$Action}{Arg}");
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40 if ($this->{$Action}{Result}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41 copy ($this->{$Action}{Result}, $this->{$Action}{Arg}) or die "Failed to backup";
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43 unlink $this->{$Action}{Arg} if -f $this->{$Action}{Arg};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
46 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48 1;