should work now.
--- a/.hgignore Mon Apr 11 13:09:31 2011 +0200
+++ b/.hgignore Mon Apr 11 15:37:28 2011 +0200
@@ -5,3 +5,4 @@
ftbackup.8
debian/files
Makefile
+.version
--- a/Makefile.in Mon Apr 11 13:09:31 2011 +0200
+++ b/Makefile.in Mon Apr 11 15:37:28 2011 +0200
@@ -9,9 +9,10 @@
all:
-install: man all
+install: man .version all
install -d -m 0755 ${DESTDIR}${sbindir}
install -m 0755 ${SCRIPT} ${DESTDIR}${sbindir}
+ perl -i -pe 's/\<VERSION\>/'`cat .version`'/' ${DESTDIR}${sbindir}/${SCRIPT}
install -d -m 0755 ${DESTDIR}${man8dir}
install -m 0644 ${MAN8PAGE} ${DESTDIR}${man8dir}/
@@ -21,10 +22,15 @@
man: ${MAN8PAGE}
clean:
- rm -f ${MAN8PAGE}
+ rm -f ${MAN8PAGE} .version
distclean: clean
rm -f Makefile
+.version:
+ test -f .hg_archival.txt \
+ && { grep ^node: | cut -f2 -d' ' >$@; } \
+ || { hg id | cut -f1 -d' ' >$@; }
+
%.8: %
pod2man --section 8 $< >$@
--- a/ftbackup Mon Apr 11 13:09:31 2011 +0200
+++ b/ftbackup Mon Apr 11 15:37:28 2011 +0200
@@ -2,6 +2,7 @@
use strict;
use warnings;
+use 5.10.0;
use IO::File;
use File::Basename;
use Net::FTP;
@@ -12,16 +13,16 @@
use Pod::Usage;
use POSIX qw(strftime);
use English qw(-no_match_vars);
-use 5.10.0;
use if $ENV{DEBUG} => qw(Smart::Comments);
$ENV{LC_ALL} = "C";
my $ME = basename $0;
+my $VERSION = '<VERSION>';
-my @CONFIGS = ("/etc/$ME", "$ENV{HOME}/.$ME", "$ME.conf");
+my @CONFIGS = ("/etc/$ME.conf", "$ENV{HOME}/.$ME.conf", "$ME.conf");
-my $NODE = hostname;
+my $HOSTNAME = hostname;
my $NOW = time();
my $opt_level = undef;
@@ -43,7 +44,7 @@
$SIG{INT} = sub { warn "Got signal INT\n"; exit 1 };
my %CONFIG = (
- FTP_DIR => "backup/<LABEL>/<NODE>",
+ FTP_DIR => "backup/<LABEL>/<HOSTNAME>",
FTP_PASSIVE => 1,
FULL_CYCLE => 7, # not used yet
);
@@ -60,10 +61,11 @@
"h|help" => sub { pod2usage(-exit => 0, -verbose => 1) },
"m|man" => sub { pod2usage(-exit => 0, -verbose => 3) },
"C|config=s" => sub { @CONFIGS = ($_[1]) },
+ "V|version" => sub { print "$ME: $VERSION\n"; exit 0 },
) or pod2usage;
my %cf = (%CONFIG, get_configs(@CONFIGS));
- $cf{FTP_DIR} =~ s/<NODE>/$NODE/g;
+ $cf{FTP_DIR} =~ s/<HOSTNAME>/$HOSTNAME/g;
$cf{FTP_DIR} =~ s/<LABEL>/$opt_label/g;
my @dev = get_candidates();
### %cf
@@ -72,7 +74,9 @@
my @errors = ();
push @errors, "Need FTP_HOST (see config)." if not defined $cf{FTP_HOST};
push @errors, "Need KEY (see config)." if not defined $cf{KEY};
- die join "\n", @errors, "" if @errors;
+ push @errors, "Command `dump' not found." if system("command -v dump >/dev/null");
+ die "$ME: pre-flight check failed:\n\t",
+ join("\n\t" => @errors), "\n" if @errors;
my $ftp;
@@ -122,7 +126,8 @@
}
my $file = strftime("%F_%R", localtime $NOW) . ".$opt_level";
- my $label = "$NODE:" . basename($dev->{rdev});
+ #my $label = "$HOSTNAME:" . basename($dev->{rdev});
+ my $label = basename($dev->{rdev});
verbose
"\tdumping $dev->{dev} as $dev->{rdev} on $dev->{mountpoint} to $file\n";
next if $opt_dry;
@@ -137,7 +142,8 @@
# we can do a snapshot
# FIXME: calculate the size
- my $snap = "$dev->{lvm}{path}-0";
+ # FIXME: check the snapshot name is not used already
+ my $snap = "$dev->{lvm}{path}-snap.0";
verbose "Creating snapshot $snap\n";
system($_ =
@@ -175,9 +181,9 @@
print <<__HEAD;
#! /bin/bash
LC_ALL=C
-if test -t 1 || test "\$1" ; then
+if test -t 1; then
cat <<___
-NODE : $NODE
+HOSTNAME : $HOSTNAME
DATE : $NOW @{[scalar localtime $NOW]}
LEVEL : $opt_level
DEVICE : $dev->{dev}
@@ -186,10 +192,10 @@
FSTYPE : $dev->{fstype}
# For recovery pass everything following the first
-# ^### START to „recover -rf -“. Or do one of the following
+# ^### START to "recover -rf -". Or do one of the following
# lines:
# sh <THIS SCRIPT> | restore -rf -
-# sh <(ftpipe <URL>) | restore -rf -
+# sh <(ftpipe <URL>) -pass file:/dev/tty | restore -rf -
___
exit 0
fi
@@ -424,8 +430,8 @@
The config files are searched in the following places:
- /etc/ftbackup
- ~/.ftbackup
+ /etc/ftbackup.conf
+ ~/.ftbackup.conf
./ftbackup.conf
If the location is a directory, all (not hidden) files in this directory are
@@ -437,7 +443,7 @@
KEY = <no default>
FTP_HOST = <no default>
- FTP_DIR = "backup/<LABEL>/<NODE>"
+ FTP_DIR = "backup/<LABEL>/<HOSTNAME>"
FTP_PASSIVE = 1
FULL_CYCLE = 7
--- a/ftbackup.conf.example Mon Apr 11 13:09:31 2011 +0200
+++ b/ftbackup.conf.example Mon Apr 11 15:37:28 2011 +0200
@@ -9,8 +9,9 @@
# FTP-Server base directory
# the following expansion work:
-# $NODE
-# FTP_DIR = backups/daily/$NODE
+# <HOSTNAME> - the (full) hostname
+# <LABEL> - label from --label=... oder the default: "daily"
+# FTP_DIR = backups/<LABEL>/<HOSTNAME>
# if we need passive mode for file transfer
# FTP_PASSIVE = 1