added dirvish-setup
authorMichael Prokop <mika@grml.org>
Fri, 23 Feb 2007 22:54:49 +0000 (23:54 +0100)
committerMichael Prokop <mika@grml.org>
Fri, 23 Feb 2007 22:54:49 +0000 (23:54 +0100)
debian/changelog
debian/rules
manpages/dirvish-setup.8 [new file with mode: 0644]
usr_sbin/dirvish-setup [new file with mode: 0755]

index f371dfc..09148a6 100644 (file)
@@ -1,3 +1,10 @@
+grml-scripts (0.9.19) unstable; urgency=low
+
+  * Add dirvish-setup, a simple script for setting up a basic
+    configuration for backup software dirvish.
+
+ -- Michael Prokop <mika@grml.org>  Fri, 23 Feb 2007 23:54:12 +0100
+
 grml-scripts (0.9.18) unstable; urgency=low
 
   * Remove unicode stuff from zsh-login. 
index f6d88a1..9a496a3 100755 (executable)
@@ -55,7 +55,7 @@ binary-arch: build install
        dh_installdocs
        dh_installman manpages/grml-scripts.1 manpages/reread_partition_table.8 manpages/gtf.1 manpages/random-hostname.1 \
        manpages/grml-setkeyboard.8 manpages/grml-setlang.8 manpages/getsf.1 manpages/grml-iptstate.8 manpages/qma.1 manpages/grml-swapon.8 \
-       manpages/grml2ram.8 manpages/gsuggest.1
+       manpages/grml2ram.8 manpages/gsuggest.1 manpages/dirvish-setup.8
 #      cp --no-dereference man/*.1.gz debian/grml-scripts/usr/share/man/man1/
        dh_link /usr/sbin/blacklist /usr/sbin/unblacklist \
                /usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/align.1.gz \
diff --git a/manpages/dirvish-setup.8 b/manpages/dirvish-setup.8
new file mode 100644 (file)
index 0000000..4fd3b9d
--- /dev/null
@@ -0,0 +1,21 @@
+.TH dirvish-setup 8
+.SH "NAME"
+dirvish-setup \- create basic setup for dirvish(8)
+.SH SYNOPSIS
+.B dirvish-setup
+.SH DESCRIPTION
+dirvish-setup is a simple, console (dialog) based script for setting up
+a basic configuration for the backup software named dirvish.
+.SH OPTIONS
+dirvish-setup does not support any options.
+.SH USAGE EXAMPLE
+.TP
+.B dirvish-setup
+Start console based dirvish-setup.
+.SH BUGS
+Probably. Please report bugs, feature requests and patches to the author.
+.SH AUTHOR
+dirvish-setup was written by Michael Prokop <mika@grml.org>.
+.PP
+This manual page was written by Michael Prokop
+<mika@grml.org> for the grml project (but may be used by others).
diff --git a/usr_sbin/dirvish-setup b/usr_sbin/dirvish-setup
new file mode 100755 (executable)
index 0000000..51b7a11
--- /dev/null
@@ -0,0 +1,179 @@
+#!/bin/sh
+# Filename:      dirvish-setup
+# Purpose:       create basic setup for dirvish(8)
+# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
+# Bug-Reports:   see http://grml.org/bugs/
+# License:       This file is licensed under the GPL v2.
+# Latest change: Fre Feb 23 23:49:58 CET 2007 [mika]
+################################################################################
+# Ressources:
+#   http://apt-get.dk/howto/backup/
+#   http://edseek.com/~jasonb/articles/dirvish_backup/advanced.html
+#   http://www.dirvish.org/svn/contrib/admin/DailyEmailScript/dirvish-status.sh
+################################################################################
+
+set -e
+
+. /etc/grml/script-functions
+. /etc/grml/lsb-functions
+
+check4root
+check4progs dirvish rsync ssh-keygen ssh-copy-id
+
+PN="$0"
+CONFFILE=/etc/dirvish/master.conf
+
+# make sure we don't lose any files
+if [ -f "$CONFFILE" ] ; then
+   mv $CONFFILE $CONFFILE.$(date +%Y%m%d).$$
+fi
+
+set +e
+
+write_conffile() {
+  cat > $CONFFILE << EOF
+# Configuration file for dirvish, created by $PN on $(date)
+
+bank:
+     $BACKUP_DIR
+
+exclude:
+      lost+found/
+#      core
+#      *~
+#      .nfs*
+#      var/cache/apt/archives
+#      var/cache/man
+#      tmp
+#      var/tmp
+#       /var/lib/nfs/*tab
+#       .kde/share/cache/*
+#       .firefox/default/*/Cache/*
+
+Runall:
+     $CLIENT 22:00
+
+# See http://www.dirvish.org/debian.howto.html for further details:
+expire-default: +30 days
+expire-rule:
+#       MIN HR    DOM MON       DOW  STRFTIME_FMT
+        *   *     *   *         1    +3 months
+        *   *     1-7 *         1    +1 year
+        *   *     1-7 1,4,7,10  1
+        *   10-20 *   *         *    +4 days
+#       *   *     *   *         2-7  +15 days
+
+EOF
+}
+
+# TODO / integrate?
+cronsetup() {
+  test -f ~/.keychain/`uname -n`-sh && source ~/.keychain/`uname -n`-sh
+}
+
+get_backup_dir() {
+  # prompt user for directory which should be used
+  BACKUP_DIR="$(dialog --stdout --inputbox 'Please choose the directory where backups should be placed' 0 0 /backups)"
+
+  if ! [ -d "$BACKUP_DIR" ] ; then
+    dialog --stdout --title "${PN}" --yesno "The directory $BACKUP_DIR does not yet exist. Do you want me to create it for you? " 0 0
+
+    if [ $? -eq 0 ]; then
+       echo "mkdir $BACKUP_DIR"
+       echo "chmod 700 $BACKUP_DIR"
+    else
+       echo "warning: $BACKUP_DIR does not exist, skipped creation as requested"
+    fi
+  fi
+}
+
+client_name() {
+  CLIENT="$(dialog --stdout --inputbox 'Please choose the name for your client instance, also known as vault' 0 0 client1)"
+}
+
+create_client_conf() {
+  mkdir -p "${BACKUP_DIR}/${CLIENT}/dirvish"
+  if [ -f "${BACKUP_DIR}/${CLIENT}/dirvish/default.conf" ] ; then
+     ewarn "Warning: ${BACKUP_DIR}/${CLIENT}/dirvish/default.conf exists already, ignoring creation." ; eend 0
+  else
+     cat > "${BACKUP_DIR}/${CLIENT}/dirvish/default.conf" << EOF
+# Configuration file of client-side for dirvish created by $PN on $(date)
+client: $CLIENTNAME
+tree: /home
+xdev: true
+index: gzip
+image-default: %Y-%m-%d
+exclude:
+        var/cache/apt/archives/*
+        var/cache/man/*
+        tmp/*
+        var/tmp/*
+rsh: ssh -i $HOME/.ssh/id_rsa_dirvish_${CLIENT}
+EOF
+  fi
+}
+
+sshkey_setup() {
+  CLIENTNAME="$(dialog --stdout --inputbox 'Please choose user login and hostname for the client you want to backup. Syntax: user@host' 0 0 root@$(hostname))"
+
+  dialog --stdout --title "${PN}" --yesno "Do you want me to create ssh setup for client ${CLIENTNAME} using ssh-keygen and ssh-copy-id?" 0 0
+
+  if [ $? -eq 0 ]; then
+     [ -d "$HOME/.ssh" ] || mkdir "$HOME/.ssh"
+     einfo "Creating $HOME/.ssh/id_rsa_dirvish_${CLIENT} using ssh-keygen:"
+     ssh-keygen -t rsa -f "$HOME/.ssh/id_rsa_dirvish_${CLIENT}" ; eend $?
+     einfo "Running ssh-copy-id to copy ssh key to $CLIENTNAME:"
+     ssh-copy-id -i "$HOME/.ssh/id_rsa_dirvish_${CLIENT}.pub" $CLIENTNAME ; eend $?
+  fi
+}
+
+client_setup() {
+  dialog --stdout --title "${PN}" --yesno "Do you want to backup $CLIENT via network? Answering with no will use localhost [$(hostname)] as client." 0 0
+
+  if [ $? -eq 0 ]; then
+     sshkey_setup
+  else
+     CLIENTNAME=$(hostname) # use localhost only
+  fi
+}
+
+display_info() {
+  einfo "Running $PN was successful. Enjoy using dirvish!" ; eend 0
+  echo
+  einfo "Please adjust ${BACKUP_DIR}/${CLIENT}/dirvish/default.conf according to your needs.
+Then run the following command to create an initial backup:
+
+  dirvish --summary long --vault $CLIENT --init
+
+Find the backup inside $BACKUP_DIR/$CLIENT/$(date +%Y-%m-%d)/tree/ then.
+
+Documentation available at:
+
+    man dirvish-locate.1 dirvish.conf.5 dirvish.8 dirvish-runall.8 dirvish-expire.8
+    /usr/share/doc/dirvish/HOWTO.upstream /usr/share/doc/dirvish/FAQ.html
+    /usr/share/doc/dirvish/HOWTO.Debian.gz
+
+    http://www.dirvish.org/
+    http://wiki.dirvish.org/
+
+Please report bugs regarding ${PN}: http://grml.org/bugs/
+" ; eend 0
+}
+
+case "$1" in
+    -h | --help | --h* )
+      echo "Usage: $PN" 1>&2
+      exit 1
+     ;;
+esac
+
+# now run the funtions:
+get_backup_dir     && \
+client_name        && \
+client_setup       && \
+create_client_conf && \
+write_conffile     && \
+display_info
+
+## END OF FILE #################################################################
+# vim: ft=sh ai tw=80 expandtab