3 ### Functions for backup clients.
5 ### (c) 2011 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This program is free software; you can redistribute it and/or modify
11 ### it under the terms of the GNU General Public License as published by
12 ### the Free Software Foundation; either version 2 of the License, or
13 ### (at your option) any later version.
15 ### This program is distributed in the hope that it will be useful,
16 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ### GNU General Public License for more details.
20 ### You should have received a copy of the GNU General Public License
21 ### along with this program; if not, write to the Free Software Foundation,
22 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 ###--------------------------------------------------------------------------
30 fail () { echo >&2 "$QUIS: $*"; exit 1; }
33 for i in TMPDIR HOST RMT LEVEL LASTDATE ASSET TARGET; do
35 case "$p" in t) ;; *) fail "environment not correctly configured" ;; esac
45 ## bkpadmin COMMAND ARGUMENT ...
46 ssh $BKP_HOST userv root bkpadmin "$@"
51 ## Convert the DATE (in ISO8601-ish format, with an optional numeric
52 ## timezone offset) according to the strftime(3) format FMT.
54 ## We have Perl available, so you'd think this would be fairly easy. Alas,
55 ## not. The obvious thing to do would be use the Date::Format module, but
56 ## that's unusably broken. Consider:
58 ## $t0 = 1319934600; $t1 = $t0 + 3600; # obviously different
59 ## for my $i ($t0, $t1) # print identically
60 ## { print time2str "%a %b %e %H:%M:%S %Y %z\n", $i; }
62 ## The Date::Parse module seems to work correctly, but isn't installed by
63 ## default on some of our target platforms. So we end up doing a lot of
69 my ($fmt, $date) = @ARGV;
71 ## Parse the input date.
72 my ($yr, $mo, $dy, $hr, $mi, $s, $tz) = $date =~
73 /^\s*(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)(?:\s+)?([-+]\d+)?\s*$/
74 or die "bad input date `$date'\''";
76 ## Convert the input date into a time_t. This is annoyingly fiddly. If
77 ## an explicit timezone offset is supplied, do the conversion as UTC, and
78 ## then apply the timezone correction. This means that we must hack
79 ## about with the awful BCD timezone offset.
82 $t = mktime $s, $mi, $hr, $dy, $mo - 1, $yr - 1900, undef, undef, -1;
85 my ($tzsign, $tzabs) = $tz < 0 ? (-1, -$tz) : (+1, $tz);
86 my $tzoff = $tzsign*(60*($tzabs/100) + ($tzabs%100));
87 local $ENV{TZ} = "UTC0"; tzset;
88 $t = mktime $s, $mi, $hr, $dy, $mo - 1, $yr - 1900, undef, undef, 0;
92 ## Now format this as requested.
93 tzset; my @tm = localtime $t;
94 print strftime $fmt, @tm;
99 ###----- That's all, folks --------------------------------------------------