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