summaryrefslogtreecommitdiffstats
path: root/roles/ands_backup/templates
diff options
context:
space:
mode:
Diffstat (limited to 'roles/ands_backup/templates')
-rw-r--r--roles/ands_backup/templates/backup.cron.j24
-rwxr-xr-xroles/ands_backup/templates/backup.sh.j272
2 files changed, 76 insertions, 0 deletions
diff --git a/roles/ands_backup/templates/backup.cron.j2 b/roles/ands_backup/templates/backup.cron.j2
new file mode 100644
index 0000000..5c017b8
--- /dev/null
+++ b/roles/ands_backup/templates/backup.cron.j2
@@ -0,0 +1,4 @@
+SHELL=/bin/bash
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+MAILTO=root
+{{ ands_backup_frequency }} root /bin/bash {{ ands_script_path }}/ands_backup.sh
diff --git a/roles/ands_backup/templates/backup.sh.j2 b/roles/ands_backup/templates/backup.sh.j2
new file mode 100755
index 0000000..74fff85
--- /dev/null
+++ b/roles/ands_backup/templates/backup.sh.j2
@@ -0,0 +1,72 @@
+#! /bin/bash
+
+date=$(date -u "+%Y%m%d_%H%M%S")
+hostname=$(hostname)
+
+volume_path="{{ ands_backup_volume }}"
+host_path="{{ ands_backup_path }}/${hostname}"
+backup_path="${host_path}/${date}"
+borg_path="{{ ands_borg_path }}"
+
+borg_args="{{ ands_borg_args }}"
+borg_prune_args="{{ ands_borg_prune }}"
+
+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}$")
+[ $? -ne 0 -o -z "$check" ] && { echo "The volume $volume_path is not mounted. Skipping..." ; exit 1 ; }
+
+[ -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 ; }
+
+{% if 'masters' in group_names %}
+# 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 --json > "$backup_path/heketi/topology.json"
+{% endif %}
+
+
+{% if 'ands_storage_servers' in group_names %}
+# 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
+#)
+{% endif %}
+
+# 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"
+
+{% if 'masters' in group_names %}
+ borg_list="* ${borg_glusterd} ${borg_etc}"
+{% elif 'ands_storage_servers' in group_names %}
+ borg_list="${borg_glusterd} ${borg_etc}"
+{% else %}
+ borg_list="${borg_etc}"
+{% endif %}
+
+ (
+ 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 +{{ands_backup_clean_minutes}} -print0 | xargs -0 rm -rf
+fi