blob: 3d07aa3488be999390b1578ee571cf9796164ab8 (
plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#! /bin/bash
date=$(date -u "+%Y%m%d_%H%M%S")
hostname=$(hostname)
volume_path="/mnt/provision"
host_path="/mnt/provision/backup/${hostname}"
backup_path="${host_path}/${date}"
borg_path="/mnt/provision/borg"
borg_args="-C zlib,6 -x"
borg_prune_args="--keep-daily=7 --keep-weekly=4 --keep-monthly=6 --keep-within 1w"
etcdctl3 () {
ETCDCTL_API=3 /usr/bin/etcdctl --cert /etc/etcd/peer.crt --key /etc/etcd/peer.key --cacert /etc/etcd/ca.crt --endpoints "https://${hostname}:2379" ${@}
}
#check=$(df | awk '{ print $6 }' | grep -P "^${volume_path}$")
#if [ $? -ne 0 -o -z "$check" ]; then
if [ ! -d "$borg_path" ]; then
echo "Mounting $volume_path"
mount "$volume_path"
# check=$(df | awk '{ print $6 }' | grep -P "^${volume_path}$")
# [ $? -ne 0 -o -z "$check" ] && { echo "The volume $volume_path is not mounted. Skipping..." ; exit 1 ; }
fi
[ -d "$backup_path" ] && { echo "Something wrong, path $backup_path already exists..." ; exit 1 ; }
# Check the provision volume is mounted
mkdir -p "$backup_path" || { echo "Can't create ${backup_path}" ; exit 1 ; }
# etcd
mkdir -p "$backup_path/etcd" || { echo "Can't create ${backup_path}/etcd" ; exit 1 ; }
etcdctl3 --endpoints="192.168.213.1:2379" snapshot save "$backup_path/etcd/snapshot.db" > /dev/null
# heketi
mkdir -p "$backup_path/heketi" || { echo "Can't create ${backup_path}/heketi" ; exit 1 ; }
heketi-cli -s http://heketi-storage.glusterfs.svc.cluster.local:8080 --user admin --secret "$(oc get secret heketi-storage-admin-secret -n glusterfs -o jsonpath='{.data.key}' | base64 -d)" topology info > "$backup_path/heketi/heketi_topology.json"
heketi-cli -s http://heketi-storage.glusterfs.svc.cluster.local:8080 --user admin --secret "$(oc get secret heketi-storage-admin-secret -n glusterfs -o jsonpath='{.data.key}' | base64 -d)" db dump > "$backup_path/heketi/heketi_db.json"
gluster --xml volume info > "$backup_path/heketi/gluster-info.xml"
gluster --xml volume status > "$backup_path/heketi/gluster-status.xml"
gluster volume status > "$backup_path/heketi/gluster.txt"
mkdir -p "$backup_path/lvm" || { echo "Can't create ${backup_path}/lvm" ; exit 1 ; }
lvs > "$backup_path/lvm/lvs.txt" 2>/dev/null
lvm fullreport --reportformat json > "$backup_path/lvm/lvm.json" 2>/dev/null
dmsetup ls --tree > "$backup_path/lvm/dmesetup.txt" 2>/dev/null
vglist=$(vgdisplay | grep -oP "VG Name\s+\K.*")
for vg in $vglist; do
vgcfgbackup -f "$backup_path/lvm/vg-$vg.backup" "$vg" &>/dev/null
done
# Gluster
#mkdir -p "$backup_path/gluster" || { echo "Can't create ${backup_path}/gluster" ; exit 1 ; }
#(
# cd /var/lib/
# tar cjf $backup_path/gluster/var_lib_glusterd.tar.bz2 glusterd
#)
# etc
#mkdir -p "$backup_path/etc" || { echo "Can't create ${backup_path}/etc" ; exit 1 ; }
#(
# cd /
# tar cjf $backup_path/etc/etc.tar.bz2 etc --exclude=selinux --exclude=udev --exclude=bash_completion.d --exclude=etc/pki --exclude=etc/services --exclude=postfix --exclude=mc
#)
if [ -d "$borg_path" ]; then
borg_glusterd="/var/lib/glusterd"
borg_etc="/etc -e */etc/selinux -e */etc/udev -e */etc/bash_completion.d -e */etc/pki -e */etc/services -e */etc/postfix -e */etc/mc"
borg_list="* ${borg_glusterd} ${borg_etc}"
(
cd ${backup_path}
borg create ${borg_args} "$borg_path::${hostname}-${date}" $borg_list
borg prune ${borg_prune_args} --prefix "${hostname}-" "$borg_path"
)
find "$host_path" -maxdepth 1 -type d -mmin +720 -print0 | xargs -0 rm -rf
fi
|