-
Notifications
You must be signed in to change notification settings - Fork 2
/
p4_create_checkpoint.pl
117 lines (96 loc) · 3.01 KB
/
p4_create_checkpoint.pl
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use strict;
# core libs
use File::Spec;
use File::Basename;
use lib dirname $0; # add the location of this script to the lib path
# custom libs
use PerforceAdmin;
# the number of backup files to keep on hand
my $count = 3;
# startup (starts logging, etc...)
PerforceAdmin::Startup();
# the name of the primary server to restore from
my $primaryServer = $ENV{ PERFORCE_PRIMARY_SERVER };
# check to see which server we are
if ( defined $primaryServer )
{
print "PERFORCE_PRIMARY_SERVER is defined in the environment, aborting\n";
PerforceAdmin::Exit( 1 );
}
# the signal file that our checkpoint is complete
my $completionFile = File::Spec->catfile( PerforceAdmin::NetworkStorage(), "checkpoint.txt" );
# delete the signal file (signalling the starting of our checkpoint generation)
unlink $completionFile;
# if the completion file has been successfully deleted
if ( -e $completionFile )
{
print ("Unable to delete '$completionFile'\n");
PerforceAdmin::Exit( 1 );
}
# stop perforce service
PerforceAdmin::Execute("net stop perforce");
# the newly created files
my $checkpoint = undef;
my $journal = undef;
# generate the checkpoint file
my @result = PerforceAdmin::Trace("p4d -z -jc");
if ( defined @result )
{
# Checkpointing to checkpoint.####.gz...
if ( @result[0] =~ /Checkpointing to (.*)\.\.\./ )
{
# get the journal file
$checkpoint = $1;
}
# Rotating journal to journal.####.gz...
if ( @result[1] =~ /Rotating journal to (.*)\.\.\./ )
{
# get the journal file
$journal = $1;
}
}
# start perforce service
PerforceAdmin::Execute("net start perforce");
# publish the checkpoint if we succeeded
if ( defined $checkpoint && -e $checkpoint && defined $journal && -e $journal )
{
# publish to the network
PerforceAdmin::Publish( $checkpoint );
PerforceAdmin::Publish( $journal );
# cleanup old files
PerforceAdmin::Execute( File::Spec->catfile( PerforceAdmin::ScriptDir(), "limit_numerically_named_files.pl" ) . " " . File::Spec->catfile( PerforceAdmin::NetworkStorage(), "checkpoint" ) . " " . $count );
PerforceAdmin::Execute( File::Spec->catfile( PerforceAdmin::ScriptDir(), "limit_numerically_named_files.pl" ) . " " . File::Spec->catfile( PerforceAdmin::NetworkStorage(), "journal" ) . " " . ( $count * 7 ) );
# rotate server log
PerforceAdmin::Execute( File::Spec->catfile( PerforceAdmin::ScriptDir(), "rotate_log.pl" ) . " " . "log" . " " . $count );
# update the checkpoint file
if ( open (FILE, ">$completionFile") )
{
print FILE "$checkpoint\n";
close FILE;
}
else
{
print ("Unable to open $completionFile for write\n");
}
}
else
{
if ( !defined $checkpoint )
{
print ("Unable to detect checkpoint file from p4d output\n");
}
elsif ( !-e $checkpoint )
{
print ("Checkpoint file '$checkpoint' does not exist\n");
}
if ( !defined $journal )
{
print ("Unable to detect journal file from p4d output\n");
}
elsif ( !-e $journal )
{
print ("Journal file '$journal' does not exist\n");
}
}
# close and send log
PerforceAdmin::Shutdown();