/[BackupPC]/upstream/2.1.0/bin/BackupPC_archiveHost
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/2.1.0/bin/BackupPC_archiveHost

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Wed Jun 22 19:12:04 2005 UTC (16 years, 11 months ago) by dpavlin
File size: 4357 byte(s)
import of version 2.1.0

1 #!/bin/perl
2 #=============================================================
3 #
4 # BackupPC_archiveHost: Archive files for a single host
5 #
6 # DESCRIPTION
7 #
8 # Usage: BackupPC_archiveHost tarCreatePath splitPath parPath host bkupNum \
9 # compPath fileExt splitSize outLoc parFile share
10 #
11 # This script is run for each host to create an archive.
12 #
13 # This script is executed by BackupPC_archive, based on the setting
14 # of $Conf{ArchiveClientCmd}. This script can be copied and modified
15 # for site-specific behavior. Update $Conf{ArchiveClientCmd} to point
16 # at your customized archive script.
17 #
18 # AUTHOR
19 # Craig Barratt <cbarratt@users.sourceforge.net>
20 # Josh Marshall
21 #
22 # COPYRIGHT
23 # Copyright (C) 2001-2004 Craig Barratt
24 #
25 # This program is free software; you can redistribute it and/or modify
26 # it under the terms of the GNU General Public License as published by
27 # the Free Software Foundation; either version 2 of the License, or
28 # (at your option) any later version.
29 #
30 # This program is distributed in the hope that it will be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 # GNU General Public License for more details.
34 #
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write to the Free Software
37 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #
39 #========================================================================
40 #
41 # Version 2.1.0, released 20 Jun 2004.
42 #
43 # See http://backuppc.sourceforge.net.
44 #
45 #========================================================================
46
47 use strict;
48 use File::Path;
49 use lib "__INSTALLDIR__/lib";
50 use BackupPC::Lib;
51
52 #
53 # Pick up the command-line arguments
54 #
55 if ( @ARGV != 11 ) {
56 print <<EOF;
57 Usage: $0 tarCreatePath splitPath parPath host bkupNum \\
58 compPath fileExt splitSize outLoc parFile share
59 EOF
60 exit(1);
61 }
62 my $tarCreate = $ARGV[0];
63 my $splitPath = $ARGV[1];
64 my $parPath = $ARGV[2];
65 my $host = $ARGV[3];
66 my $bkupNum = $ARGV[4];
67 my $compPath = $ARGV[5];
68 my $fileExt = $ARGV[6];
69 my $splitSize = $ARGV[7];
70 my $outLoc = $ARGV[8];
71 my $parfile = $ARGV[9];
72 my $share = $ARGV[10];
73
74 die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
75
76 #
77 # Make sure the specified programs are executable
78 #
79 foreach my $prog ( ($tarCreate, $compPath, $splitPath, $parPath) ) {
80 next if ( $prog eq "" || -x $prog );
81 print("Error: $prog is not an executable program\n");
82 exit(1);
83 }
84 my $mesg = "Writing tar archive for host $host, backup #$bkupNum";
85
86 #
87 # Build the command we will run
88 #
89 $share = $bpc->shellEscape($share);
90 $host = $bpc->shellEscape($host);
91 my $cmd = "$tarCreate -t -h $host -n $bkupNum -s $share . ";
92 $cmd .= "| $compPath " if ( $compPath ne "cat" && $compPath ne "" );
93 if ( -b $outLoc || -c $outLoc || -f $outLoc ) {
94 #
95 # Output file is a device or a regular file, so don't use split
96 #
97 $cmd .= ">> $outLoc";
98 $mesg .= " to $outLoc";
99 } else {
100 mkpath($outLoc) if ( !-d $outLoc );
101 if ( !-d $outLoc ) {
102 print("Error: unable to create output directory $outLoc\n");
103 exit(1);
104 }
105 if ( $splitSize > 0 && -x $splitPath ) {
106 $cmd .= "| $splitPath -b $splitSize - $outLoc/$host.$bkupNum.tar$fileExt.";
107 $mesg .= ", split to output files $outLoc/$host.$bkupNum.tar$fileExt.*";
108 } else {
109 $cmd .= "> $outLoc/$host.$bkupNum.tar$fileExt";
110 $mesg .= " to output file $outLoc/$host.$bkupNum.tar$fileExt";
111 }
112 }
113 print("$mesg\n");
114
115 #
116 # Run the command
117 #
118 my $ret = system($cmd);
119 if ( $ret ) {
120 print("Executing: $cmd\n");
121 print("Error: $tarCreate, compress or split failed\n");
122 exit(1);
123 }
124
125 #
126 # Run optional parity file generation (only if the output is a directory,
127 # ie: not a tape device).
128 #
129 if ( -d $outLoc && -x $parPath ) {
130 if ( $parfile != 0 ) {
131 print("Running $parPath to create parity files\n");
132 my $parCmd = "$parPath c -r$parfile $outLoc/$host.$bkupNum.tar$fileExt.par2 $outLoc/$host.$bkupNum.tar$fileExt.*";
133 $ret = system($parCmd);
134 if ( $ret ) {
135 print("Executing: $parCmd\n");
136 print("Error: $parPath failed\n");
137 exit(1);
138 }
139 }
140 }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26