Statistics
| Branch: | Tag: | Revision:

root / doc / examples / gnt-config-backup.in @ 752a8ca8

History | View | Annotate | Download (2.1 kB)

1 679008e7 Iustin Pop
#!/bin/bash
2 679008e7 Iustin Pop
3 679008e7 Iustin Pop
# Copyright (C) 2009 Google Inc.
4 679008e7 Iustin Pop
#
5 679008e7 Iustin Pop
# This program is free software; you can redistribute it and/or modify
6 679008e7 Iustin Pop
# it under the terms of the GNU General Public License as published by
7 679008e7 Iustin Pop
# the Free Software Foundation; either version 2 of the License, or
8 679008e7 Iustin Pop
# (at your option) any later version.
9 679008e7 Iustin Pop
#
10 679008e7 Iustin Pop
# This program is distributed in the hope that it will be useful, but
11 679008e7 Iustin Pop
# WITHOUT ANY WARRANTY; without even the implied warranty of
12 679008e7 Iustin Pop
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 679008e7 Iustin Pop
# General Public License for more details.
14 679008e7 Iustin Pop
#
15 679008e7 Iustin Pop
# You should have received a copy of the GNU General Public License
16 679008e7 Iustin Pop
# along with this program; if not, write to the Free Software
17 679008e7 Iustin Pop
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 679008e7 Iustin Pop
# 02110-1301, USA.
19 679008e7 Iustin Pop
20 679008e7 Iustin Pop
21 679008e7 Iustin Pop
# This is an example ganeti script that should be run from cron on all
22 679008e7 Iustin Pop
# nodes; it will archive the ganeti configuration into a separate
23 679008e7 Iustin Pop
# directory tree via GIT, so that it is possible to restore the
24 679008e7 Iustin Pop
# history of cluster configuration changes if needed
25 679008e7 Iustin Pop
26 679008e7 Iustin Pop
# The script requires the lockfile-progs package and the git software
27 679008e7 Iustin Pop
28 679008e7 Iustin Pop
# Note that since Ganeti 2.0, config.data is the authoritative source
29 679008e7 Iustin Pop
# of configuration; as such, we don't need to backup the ssconf files,
30 679008e7 Iustin Pop
# and the other files (server.pem, rapi.pem, hmac.key, known_hosts,
31 679008e7 Iustin Pop
# etc.) do no hold critical data (they can be regenerated at will, as
32 679008e7 Iustin Pop
# long as they are synchronised).
33 679008e7 Iustin Pop
34 679008e7 Iustin Pop
set -e
35 679008e7 Iustin Pop
36 679008e7 Iustin Pop
LOCALSTATEDIR=@LOCALSTATEDIR@
37 679008e7 Iustin Pop
SYSCONFDIR=@SYSCONFDIR@
38 679008e7 Iustin Pop
39 679008e7 Iustin Pop
GANETIDIR=${LOCALSTATEDIR}/lib/ganeti
40 679008e7 Iustin Pop
CONFIGDATA=${GANETIDIR}/config.data
41 679008e7 Iustin Pop
42 679008e7 Iustin Pop
GNTBKDIR=${LOCALSTATEDIR}/lib/gnt-config-backup
43 679008e7 Iustin Pop
LOCKFILE=${LOCALSTATEDIR}/lock/gnt-config-backup
44 679008e7 Iustin Pop
45 679008e7 Iustin Pop
# exit if no ganeti config file (no cluster configured, or not M/MC)
46 679008e7 Iustin Pop
test -f $CONFIGDATA || exit 0
47 679008e7 Iustin Pop
48 679008e7 Iustin Pop
# We use a simple lock method, since our script should be fast enough
49 679008e7 Iustin Pop
# (no network, not talking to ganeti-masterd) that we don't expect to
50 679008e7 Iustin Pop
# run over 5 minutes if the system is healthy
51 679008e7 Iustin Pop
lockfile-create "$LOCKFILE" || exit 1
52 679008e7 Iustin Pop
trap 'lockfile-remove $LOCKFILE' EXIT
53 679008e7 Iustin Pop
54 679008e7 Iustin Pop
test -d $GNTBKDIR || mkdir $GNTBKDIR
55 679008e7 Iustin Pop
56 679008e7 Iustin Pop
cd $GNTBKDIR
57 679008e7 Iustin Pop
58 679008e7 Iustin Pop
test -d .git || git init
59 679008e7 Iustin Pop
60 679008e7 Iustin Pop
cp -f $CONFIGDATA config.data
61 679008e7 Iustin Pop
git add config.data
62 679008e7 Iustin Pop
git commit -q -m "Automatic commit by gnt-config-backup"
63 679008e7 Iustin Pop
64 679008e7 Iustin Pop
touch last_run