]> git.etc.gen.nz Git - etc-obnam.git/commitdiff
Customise, add run-backup for driving obnam. v0.1
authorAndrew Ruthven <andrew@etc.gen.nz>
Wed, 25 Apr 2012 23:38:14 +0000 (11:38 +1200)
committerAndrew Ruthven <andrew@etc.gen.nz>
Wed, 25 Apr 2012 23:38:14 +0000 (11:38 +1200)
12 files changed:
debian/.gitignore [new file with mode: 0644]
debian/config [new file with mode: 0644]
debian/control
debian/copyright
debian/etc-obnam.cron.d.ex [deleted file]
debian/install [new file with mode: 0644]
debian/logrotate [new file with mode: 0644]
debian/manpage.1.ex [deleted file]
debian/postinst
debian/templates [new file with mode: 0644]
obnam.list [new file with mode: 0644]
run-backup [new file with mode: 0755]

diff --git a/debian/.gitignore b/debian/.gitignore
new file mode 100644 (file)
index 0000000..e4f2dba
--- /dev/null
@@ -0,0 +1,5 @@
+etc-obnam.debhelper.log
+etc-obnam.postrm.debhelper
+etc-obnam.substvars
+etc-obnam/
+files
diff --git a/debian/config b/debian/config
new file mode 100644 (file)
index 0000000..392c500
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -e
+PACKAGE=etc-obnam
+CONFIGFILE=/etc/default/$PACKAGE
+
+. /usr/share/debconf/confmodule
+
+# Load config file, if it exists.
+if [ -e $CONFIGFILE ]; then
+  . $CONFIGFILE || true
+
+  # Store values from config file into
+  # debconf db.
+  db_set $PACKAGE/host_name $HOST_NAME
+  db_set $PACKAGE/host_mac $HOST_MAC
+  db_set $PACKAGE/source $SOURCE
+fi
+
+# Ask questions.
+db_input high $PACKAGE/repository || true
+db_input high $PACKAGE/host_name || true
+db_input high $PACKAGE/host_mac || true
+db_input high $PACKAGE/source || true
+db_input low $PACKAGE/scheduled_time || true
+db_input low $PACKAGE/exclude || true
+db_go
index 7bf12fa14dff2fd8ef29d4811c57bad80eb7bff9..4d64ce85b786e34ed5a536388769d591396c0f4c 100644 (file)
@@ -11,5 +11,6 @@ Homepage: <insert the upstream URL, if relevant>
 Package: etc-obnam
 Architecture: all
 Depends: ${misc:Depends}
+Recommends: obnam
 Description: <insert up to 60 chars description>
  <insert long description, indented with spaces>
index 3f348e4ea4a9fc28176a9b1a2ad822e3a51501a8..682ab367d6d7b7f05ec091c4e5492ce252cb9fb8 100644 (file)
@@ -2,19 +2,9 @@ This work was packaged for Debian by:
 
     Andrew Ruthven <andrew@etc.gen.nz> on Wed, 18 Apr 2012 21:46:19 +1200
 
-It was downloaded from:
-
-    <url://example.com>
-
-Upstream Author(s):
-
-    <put author's name and email here>
-    <likewise for another author>
-
 Copyright:
 
-    <Copyright (C) YYYY Firstname Lastname>
-    <likewise for another author>
+    Copyright (C) 2012 Andrew Ruthven
 
 License:
 
@@ -38,13 +28,4 @@ The Debian packaging is:
 
     Copyright (C) 2012 Andrew Ruthven <andrew@etc.gen.nz>
 
-# Please chose a license for your packaging work. If the program you package
-# uses a mainstream license, using the same license is the safest choice.
-# Please avoid to pick license terms that are more restrictive than the
-# packaged work, as it may make Debian's contributions unacceptable upstream.
-# If you just want it to be GPL version 3, leave the following line in.
-
 and is licensed under the GPL version 3, see above.
-
-# Please also look if there are files or directories which have a
-# different copyright/license attached and list them here.
diff --git a/debian/etc-obnam.cron.d.ex b/debian/etc-obnam.cron.d.ex
deleted file mode 100644 (file)
index f7e6ce6..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#
-# Regular cron jobs for the etc-obnam package
-#
-0 4    * * *   root    [ -x /usr/bin/etc-obnam_maintenance ] && /usr/bin/etc-obnam_maintenance
diff --git a/debian/install b/debian/install
new file mode 100644 (file)
index 0000000..5db8b39
--- /dev/null
@@ -0,0 +1,2 @@
+obnam.list /etc/apt/sources.list.d/
+run-backup /usr/lib/etc-obnam/
diff --git a/debian/logrotate b/debian/logrotate
new file mode 100644 (file)
index 0000000..9e2f58e
--- /dev/null
@@ -0,0 +1,10 @@
+/var/log/obnam.log
+{
+  weekly
+  missingok
+  rotate 4
+  compress
+  delaycompress
+  notifempty
+  create 640 root adm
+}
diff --git a/debian/manpage.1.ex b/debian/manpage.1.ex
deleted file mode 100644 (file)
index 67fe773..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-.\"                                      Hey, EMACS: -*- nroff -*-
-.\" First parameter, NAME, should be all caps
-.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
-.\" other parameters are allowed: see man(7), man(1)
-.TH ETC-OBNAM SECTION "April 18, 2012"
-.\" Please adjust this date whenever revising the manpage.
-.\"
-.\" Some roff macros, for reference:
-.\" .nh        disable hyphenation
-.\" .hy        enable hyphenation
-.\" .ad l      left justify
-.\" .ad b      justify to both left and right margins
-.\" .nf        disable filling
-.\" .fi        enable filling
-.\" .br        insert line break
-.\" .sp <n>    insert n+1 empty lines
-.\" for manpage-specific macros, see man(7)
-.SH NAME
-etc-obnam \- program to do something
-.SH SYNOPSIS
-.B etc-obnam
-.RI [ options ] " files" ...
-.br
-.B bar
-.RI [ options ] " files" ...
-.SH DESCRIPTION
-This manual page documents briefly the
-.B etc-obnam
-and
-.B bar
-commands.
-.PP
-.\" TeX users may be more comfortable with the \fB<whatever>\fP and
-.\" \fI<whatever>\fP escape sequences to invode bold face and italics,
-.\" respectively.
-\fBetc-obnam\fP is a program that...
-.SH OPTIONS
-These programs follow the usual GNU command line syntax, with long
-options starting with two dashes (`-').
-A summary of options is included below.
-For a complete description, see the Info files.
-.TP
-.B \-h, \-\-help
-Show summary of options.
-.TP
-.B \-v, \-\-version
-Show version of program.
-.SH SEE ALSO
-.BR bar (1),
-.BR baz (1).
-.br
-The programs are documented fully by
-.IR "The Rise and Fall of a Fooish Bar" ,
-available via the Info system.
-.SH AUTHOR
-etc-obnam was written by <upstream author>.
-.PP
-This manual page was written by Andrew Ruthven <andrew@etc.gen.nz>,
-for the Debian project (and may be used by others).
index f67d20eb4b316c6481d12b61fcb873f0fd792397..b8d69b2e82efd768abf901b39cee1ebdd44c8cd9 100644 (file)
 
 set -e
 
-# summary of how this script can be called:
-#        * <postinst> `configure' <most-recently-configured-version>
-#        * <old-postinst> `abort-upgrade' <new version>
-#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
-#          <new-version>
-#        * <postinst> `abort-remove'
-#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
-#          <failed-install-package> <version> `removing'
-#          <conflicting-package> <version>
-# for details, see http://www.debian.org/doc/debian-policy/ or
-# the debian-policy package
+[ -n "${DEBUG}" ] && set -o xtrace
+PACKAGE=etc-obnam
+[ -n "${DEBUG}" ] && echo "PostInst Parameters: $@" 1>&2
 
+if [ -e /usr/share/debconf/confmodule ]; then
+  . /usr/share/debconf/confmodule
+  db_version 2.0
+fi
+
+generate_crontab() {
+  echo "# Crontab to run the obnam backup on a regular schedule"
+  echo "#"
+  echo "# * * * AUTOMATICALLY MAINTAINED - DO NOT EDIT * * *"
+  echo "#"
+  echo "# To modify the schedule for this job you should:"
+  echo "#     dpkg-reconfigure -plow $PACKAGE"
+  echo "#"
+  echo ""
+  echo "$SCHEDULED_TIME root /usr/lib/$PACKAGE/run-backup"
+}
+
+generate_debian_config() {
+  echo "# Shell fragment to configure the $PACKAGE package"
+  echo "#"
+  echo "# You can run 'dpkg-reconfigure $PACKAGE' to modify the values in this"
+  echo "# file if you want. You can also change the values here and changes"
+  echo "# will be preserved.  But other changes will not be preserved."
+  echo ""
+  echo "# Which host do we backup to?"
+  echo "HOST_NAME='$HOST_NAME'"
+  echo ""
+  echo "# What is the MAC address of the host we backup to?"
+  echo "# (Used to determine if we're on the right network, useful for generic names."
+  echo "# If this is unset, then just being able to ping the above host is sufficient.)"
+  echo "HOST_MAC='$HOST_MAC'"
+  echo ""
+  echo "# Which directories do we backup to?"
+  echo "SOURCE='$SOURCE'"
+}
+
+generate_ssh_key() {
+  ssh-keygen -q -t rsa -C "obnam@$(hostname) - $(date +%F)" -N "" -f /etc/obnam/id_rsa
+}
+
+generate_obnam_config() {
+  echo "# Configuration file for obnam."
+  echo "#"
+  echo "# This file is generated automatically.  You can override these settings by"
+  echo "# creating a file which is sorted alphabetically after this one and inserting"
+  echo "# the updated settings in that file."
+  echo "#"
+  echo "[config]"
+  echo "log = /var/log/obnam.log"
+  echo "ssh-key = /etc/obnam/id_rsa"
+  echo "log-level = info"
+  echo "#"
+  echo "# To reconfigure the following settings run:"
+  echo "#    dpkg-reconfigure $PACKAGE"
+  echo "repository = $REPOSITORY"
+  echo "exclude = $EXCLUDE"
+}
 
 case "$1" in
-    configure)
+    configure|reconfigure)
+    DEBIANCONFIG="/etc/default/$PACKAGE"
+    OBNAMCONFIG="/etc/obnam/${PACKAGE}.conf"
+    CRONTAB="/etc/cron.d/${PACKAGE}"
+
+    # Load current settings, most of which will be overwritten.
+    [ -f $DEBIANCONFIG ] && . $DEBIANCONFIG
+
+    db_get ${PACKAGE}/repository
+    REPOSITORY="${RET}"
+
+    db_get ${PACKAGE}/scheduled_time
+    SCHEDULED_TIME="${RET}"
+
+    db_get ${PACKAGE}/host_name
+    HOST_NAME="${RET}"
+
+    db_get ${PACKAGE}/host_mac || true
+    HOST_MAC="${RET}"
+
+    db_get ${PACKAGE}/source
+    SOURCE="${RET}"
+
+    db_get ${PACKAGE}/exclude || true
+    EXCLUDE="${RET}"
+
+    generate_crontab > $CRONTAB
+    generate_debian_config > $DEBIANCONFIG
+    generate_obnam_config > $OBNAMCONFIG
+
+    if [ ! -f /etc/obnam/id_rsa ]; then
+      generate_ssh_key
+
+      echo New ssh key generated for this host, please add it to the backup host.
+    fi
     ;;
 
     abort-upgrade|abort-remove|abort-deconfigure)
diff --git a/debian/templates b/debian/templates
new file mode 100644 (file)
index 0000000..b1955e4
--- /dev/null
@@ -0,0 +1,36 @@
+Template: etc-obnam/repository
+Type: string
+Default: sftp://backups@backup/private/obnam/backups/
+Description: URL for where to backup to, including the destination path.
+ An obnam supported URL for where to backup to.
+
+Template: etc-obnam/host_name
+Type: string
+Default: backup
+Description: The server to backup to
+ The server that we're to submit our backups to.  Can be a hostname or an IP
+ address.
+
+Template: etc-obnam/host_mac
+Type: string
+Default: 00:0d:88:6b:b2:68
+Description: MAC address of the server we're backing up to.
+ The MAC address that we're submitting our backups to.  Used to determine
+ if the configured hostname is accessible on the local network.
+
+Template: etc-obnam/scheduled_time
+Type: string
+Default: 10 * * * *
+Description: Adjust the cron schedule for running the backup.
+
+Template: etc-obnam/source
+Type: string
+Default: /home /etc
+Description: Directories to be included in the backup.
+ A space separated list of the directories to be backed up.
+
+Template: etc-obnam/exclude
+Type: string
+Default: \.xchat2, .*/\.cache/.*, \.thumbnails/.*, \.mozilla/firefox/.*\.default/Cache, \.local/share/Trash, /home/andrew/data/reference, /home/.*/scratch, .xbmc/temp, /home/.*/Network, .*/[Cc]ache/.*, \.evolution/mail/imap
+Description: List of regexes to be excluded from the backup.
+ A list of regexes to be excluded from the backup.
diff --git a/obnam.list b/obnam.list
new file mode 100644 (file)
index 0000000..15c8a15
--- /dev/null
@@ -0,0 +1 @@
+deb http://code.liw.fi/debian squeeze main
diff --git a/run-backup b/run-backup
new file mode 100755 (executable)
index 0000000..0db7712
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+. /etc/default/etc-obnam
+
+CLIENT=$(hostname)
+SOURCE=${SOURCE:-/home /etc}
+
+function check_host() {
+  local type=$1
+  if [ "x$type" != "xA" -a "x$type" != "xAAAA" ]
+  then
+    echo Sorry, unknown type to check for.
+    exit 1
+  fi
+
+  # If no host is defined to check for, assume we should just run.
+  if [ "x$HOST_NAME" = "x" ]
+  then
+    return 0
+  fi
+
+  local ip=$(host -t $type $HOST_NAME | grep address | awk '{ print $NF }' | head -1)
+  if [ "x$ip" = "x" ]
+  then
+    return 1
+  fi
+
+  local cmd=ping
+  if [ $type = "AAAA" ]
+  then
+    cmd=ping6
+  fi
+
+  if ! $cmd -n -c3 $HOST_NAME &> /dev/null
+  then
+    return 1
+  fi
+
+  local mac=$(ip neigh | egrep "^$ip " | grep REACHABLE | awk '{ print $5 }' )
+  if [ $(echo $mac | wc -l ) -ne 1 ]
+  then
+    return 1
+  fi
+
+  if [ "x$HOST_MAC" != "x" -a "x$mac" != "x$HOST_MAC" ]
+  then
+    return 1
+  fi
+
+  return 0
+}
+
+if ( check_host 'AAAA' -o check_host 'A'  )
+then
+  obnam --quiet --client-name=$CLIENT backup $SOURCE
+  exit 0
+else
+  echo huh, where is it?
+  exit 1
+fi