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