-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsync-ganeti.sh
executable file
·64 lines (49 loc) · 1.67 KB
/
rsync-ganeti.sh
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
63
#!/bin/sh -xe
cluster=$1
instance=$2
disk=$3
today=$( date +%Y-%m-%d )
test -d /zamd/log/rsync/$instance || mkdir -p /zamd/log/rsync/$instance
(
:> /zamd/log/rsync/$instance/$today
snap_tries=0
snap_ok=0
while [ $snap_ok -eq 0 -a $snap_tries -lt 9 ]
do
snap_tries=$( expr $snap_tries + 1 )
echo "## snap try: $snap_tries $instance disk"
ssh root@$cluster.gnt.ffzg.hr /srv/gnt-info/gnt-lv-snap-shell.sh $instance $disk 2>&1 | \
tee /dev/shm/snap.$instance.$disk
if grep rsync-from /dev/shm/snap.$instance.$disk ; then
snap_ok=1
else
sleep 3
fi
done
if [ $snap_ok -eq 0 ] ; then
echo "FATAL: can't create snapshot"
exit 1
fi
rsync_from=$( cat /dev/shm/snap.$instance.$disk| grep ^rsync-from | cut -d' ' -f2 )
rsync_args=$( test -f /zamd/$cluster/$instance/rsync.args && cat /zamd/$cluster/$instance/rsync.args || true )
backup_ok=0
backup_tries=0
while [ $backup_ok -eq 0 -a $backup_tries -lt 9 ]
do
backup_tries=$( expr $backup_tries + 1 )
echo "## backup try: $backup_tries $0 $cluster $instance $disk"
if rsync -raHXAz --numeric-ids --inplace --delete $rsync_args \
--log-file=/zamd/log/rsync/$instance/$today \
--log-file-format="%i %n%L %b %l" \
$rsync_from /zamd/$cluster/$instance/$disk/ 2>&1
then
zfs snap zamd/$cluster/$instance/$disk@$today
backup_ok=1
else
echo $cluster $instance $disk >> /dev/shm/backup.errors
grep rsync: /zamd/log/rsync/$instance/$today | grep 'Permission denied' | sed -e 's/^.*open "//' -e 's/".*$//' | tee /dev/shm/fix-permissions.$instance.files | xargs rm -v
sleep 3
fi
done
cat /dev/shm/snap.$instance.$disk | grep umount | grep ^ssh | sh -xe
2>&1 ) | tee -a /dev/shm/$cluster.log