-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrestore-replicas
executable file
·62 lines (53 loc) · 2.02 KB
/
restore-replicas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# This is intended to be called from puppet on both the master and the
# primary machine. Its purpose is to restore repository configurations
# when a backup machine is installed from scratch.
# IMPORTANT NOTE: this will restore all the repositories from the primary
# machine, but if any repositories were added by hand (that is, outside
# of manage-replicas), then the source URL will be left pointing to the
# primary machine rather than the real stratum 0 it is supposed to come
# from. Those would need to be separately restored with add-repository -H
# before calling this function.
VARLIB=/var/lib/cvmfs-hastratum1
SHARE=/usr/share/cvmfs-hastratum1
DONEFILE=$VARLIB/restoration-date
if [ -f $DONEFILE ]; then
exit
fi
if cvmfsha-is-master; then
exit
fi
if [ ! -f /etc/cvmfs/manage-replicas.conf ]; then
# not safe to use if there's no manage-replicas.conf
exit
fi
. /etc/cvmfs/hastratum1.conf
THISHOST="`uname -n`"
case $THISHOST in
$HOST1) OTHERHOST=$HOST2;;
$HOST2) OTHERHOST=$HOST1;;
*) echo "Not running on $HOST1 or $HOST2" >&2; exit 1;;
esac
PATH=$PATH:/usr/sbin
echo "Output is directed to $VARLIB/restore-replicas.out"
sed "s/@otherhost@/$OTHERHOST/" $SHARE/restore-replicas.conf.in >$VARLIB/restore-replicas.conf
if ! manage-replicas -f $VARLIB/restore-replicas.conf >>$VARLIB/restore-replicas.out 2>&1; then
echo "Restoration of replicas failed" >&2
exit 1
fi
rm $VARLIB/restore-replicas.conf
# fix the incorrect source URLs
(
# override addcmd/remcmd because we only want to fix URLs, not add or remove
# add new defaults in case there aren't any
echo "addcmd true : @fqrn@"
echo "remcmd true"
# replace any existing addcmd/remcmd in case they're being set
sed 's/^addcmd.*/addcmd true : @fqrn@/;s/^remcmd.*/remcmd true/' /etc/cvmfs/manage-replicas.conf
) > $VARLIB/manage-replicas.conf
if ! manage-replicas -f $VARLIB/manage-replicas.conf >>$VARLIB/restore-replicas.out 2>&1; then
echo "Restoration of replica source URLs failed" >&2
exit 1
fi
rm $VARLIB/manage-replicas.conf
date >$DONEFILE