From 38a6437bbc4629e44658786860e8d09c54d55ee2 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sat, 5 Nov 2022 01:56:48 -0400 Subject: [PATCH] Add Ceph monitor backup --- roles/base/tasks/main.yml | 9 ++++--- .../templates/etc/cron.daily/mon-backup.j2 | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100755 roles/base/templates/etc/cron.daily/mon-backup.j2 diff --git a/roles/base/tasks/main.yml b/roles/base/tasks/main.yml index 3cb517b..8a661d1 100644 --- a/roles/base/tasks/main.yml +++ b/roles/base/tasks/main.yml @@ -638,11 +638,14 @@ state: directory tags: base-backups -- name: install daily backup script +- name: install daily backup scripts template: - src: etc/cron.daily/pvc-backup.j2 - dest: /etc/cron.daily/pvc-backup + src: "etc/cron.daily/{{ item }}.j2" + dest: "/etc/cron.daily/{{ item }}" mode: 0755 + with_items: + - pvc-backup + - mon-backup tags: base-backups - name: install IPMI network interfaces fragment diff --git a/roles/base/templates/etc/cron.daily/mon-backup.j2 b/roles/base/templates/etc/cron.daily/mon-backup.j2 new file mode 100755 index 0000000..fdf540a --- /dev/null +++ b/roles/base/templates/etc/cron.daily/mon-backup.j2 @@ -0,0 +1,24 @@ +#!/bin/bash + +# Backup the Ceph monitor data +# {{ ansible_managed }} + +set -o errexit + +BACKUP_DIR="/srv/backups" +DATE="$( date +%Y%m%d )" +HOSTNAME="$( hostname -s )" + +if [[ ! -d ${BACKUP_DIR} ]]; then + mkdir -p ${BACKUP_DIR} +fi + +pushd ${BACKUP_DIR} &>/dev/null + +MON_BACKUP_FILENAME_BASE="ceph-mon-backup" +MON_BACKUP_FILENAME="${BACKUP_DIR}/${MON_BACKUP_FILENAME_BASE}.${DATE}.tar.xz" + +tar -cJf ${MON_BACKUP_FILENAME} /var/lib/ceph/mon +find ${BACKUP_DIR} -type f -name "${MON_BACKUP_FILENAME_BASE}*" -mtime +7 -exec rm {} \; + +popd &>/dev/null