From: Andrew Ruthven Date: Wed, 25 Apr 2012 23:38:14 +0000 (+1200) Subject: Customise, add run-backup for driving obnam. X-Git-Tag: v0.1^0 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eccf7bcd83c19c4d5655a57459ce587354d59e03;p=etc-obnam.git Customise, add run-backup for driving obnam. --- diff --git a/debian/.gitignore b/debian/.gitignore new file mode 100644 index 0000000..e4f2dba --- /dev/null +++ b/debian/.gitignore @@ -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 index 0000000..392c500 --- /dev/null +++ b/debian/config @@ -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 diff --git a/debian/control b/debian/control index 7bf12fa..4d64ce8 100644 --- a/debian/control +++ b/debian/control @@ -11,5 +11,6 @@ Homepage: Package: etc-obnam Architecture: all Depends: ${misc:Depends} +Recommends: obnam Description: diff --git a/debian/copyright b/debian/copyright index 3f348e4..682ab36 100644 --- a/debian/copyright +++ b/debian/copyright @@ -2,19 +2,9 @@ This work was packaged for Debian by: Andrew Ruthven on Wed, 18 Apr 2012 21:46:19 +1200 -It was downloaded from: - - - -Upstream Author(s): - - - - Copyright: - - + Copyright (C) 2012 Andrew Ruthven License: @@ -38,13 +28,4 @@ The Debian packaging is: Copyright (C) 2012 Andrew Ruthven -# 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 index f7e6ce6..0000000 --- a/debian/etc-obnam.cron.d.ex +++ /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 index 0000000..5db8b39 --- /dev/null +++ b/debian/install @@ -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 index 0000000..9e2f58e --- /dev/null +++ b/debian/logrotate @@ -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 index 67fe773..0000000 --- a/debian/manpage.1.ex +++ /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 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\fP and -.\" \fI\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 . -.PP -This manual page was written by Andrew Ruthven , -for the Debian project (and may be used by others). diff --git a/debian/postinst b/debian/postinst index f67d20e..b8d69b2 100644 --- a/debian/postinst +++ b/debian/postinst @@ -5,21 +5,104 @@ set -e -# summary of how this script can be called: -# * `configure' -# * `abort-upgrade' -# * `abort-remove' `in-favour' -# -# * `abort-remove' -# * `abort-deconfigure' `in-favour' -# `removing' -# -# 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 index 0000000..b1955e4 --- /dev/null +++ b/debian/templates @@ -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 index 0000000..15c8a15 --- /dev/null +++ b/obnam.list @@ -0,0 +1 @@ +deb http://code.liw.fi/debian squeeze main diff --git a/run-backup b/run-backup new file mode 100755 index 0000000..0db7712 --- /dev/null +++ b/run-backup @@ -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