Add an example script for backing up the config
authorIustin Pop <iustin@google.com>
Tue, 3 Nov 2009 12:54:06 +0000 (13:54 +0100)
committerIustin Pop <iustin@google.com>
Tue, 3 Nov 2009 13:20:14 +0000 (14:20 +0100)
This requires git and lockfile-progs, and only backs up config.data (see
the comments why).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

Makefile.am
doc/examples/gnt-config-backup.in [new file with mode: 0644]

index 87af4e6..20c7504 100644 (file)
@@ -58,6 +58,7 @@ CLEANFILES = \
        doc/examples/bash_completion \
        doc/examples/ganeti.initd \
        doc/examples/ganeti.cron \
+       doc/examples/gnt-config-backup \
        doc/examples/hooks/ipsec \
        lib/*.py[co] \
        lib/build/*.py[co] \
@@ -189,6 +190,7 @@ noinst_DATA = \
        doc/examples/bash_completion \
        doc/examples/ganeti.cron \
        doc/examples/ganeti.initd \
+       doc/examples/gnt-config-backup \
        doc/examples/hooks/ipsec \
        $(manhtml)
 
@@ -234,6 +236,7 @@ EXTRA_DIST = \
        doc/html \
        doc/examples/ganeti.initd.in \
        doc/examples/ganeti.cron.in \
+       doc/examples/gnt-config-backup.in \
        doc/examples/dumb-allocator \
        doc/examples/hooks/ethers \
        doc/examples/hooks/ipsec.in \
diff --git a/doc/examples/gnt-config-backup.in b/doc/examples/gnt-config-backup.in
new file mode 100644 (file)
index 0000000..d620c2e
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+# Copyright (C) 2009 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+
+# This is an example ganeti script that should be run from cron on all
+# nodes; it will archive the ganeti configuration into a separate
+# directory tree via GIT, so that it is possible to restore the
+# history of cluster configuration changes if needed
+
+# The script requires the lockfile-progs package and the git software
+
+# Note that since Ganeti 2.0, config.data is the authoritative source
+# of configuration; as such, we don't need to backup the ssconf files,
+# and the other files (server.pem, rapi.pem, hmac.key, known_hosts,
+# etc.) do no hold critical data (they can be regenerated at will, as
+# long as they are synchronised).
+
+set -e
+
+LOCALSTATEDIR=@LOCALSTATEDIR@
+SYSCONFDIR=@SYSCONFDIR@
+
+GANETIDIR=${LOCALSTATEDIR}/lib/ganeti
+CONFIGDATA=${GANETIDIR}/config.data
+
+GNTBKDIR=${LOCALSTATEDIR}/lib/gnt-config-backup
+LOCKFILE=${LOCALSTATEDIR}/lock/gnt-config-backup
+
+# exit if no ganeti config file (no cluster configured, or not M/MC)
+test -f $CONFIGDATA || exit 0
+
+# We use a simple lock method, since our script should be fast enough
+# (no network, not talking to ganeti-masterd) that we don't expect to
+# run over 5 minutes if the system is healthy
+lockfile-create "$LOCKFILE" || exit 1
+trap 'lockfile-remove $LOCKFILE' EXIT
+
+test -d $GNTBKDIR || mkdir $GNTBKDIR
+
+cd $GNTBKDIR
+
+test -d .git || git init
+
+cp -f $CONFIGDATA config.data
+git add config.data
+git commit -q -m "Automatic commit by gnt-config-backup"
+
+touch last_run