From 3a48690e4d9e2dcf146c375c717b2a075578c97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Mon, 22 Jul 2019 11:43:59 +0200 Subject: [PATCH] [WIP]: Script to backup deb files related to Ceph --- ceph/ceph.backup.deb.files.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 ceph/ceph.backup.deb.files.sh diff --git a/ceph/ceph.backup.deb.files.sh b/ceph/ceph.backup.deb.files.sh new file mode 100755 index 0000000..251e753 --- /dev/null +++ b/ceph/ceph.backup.deb.files.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# Purpose {{{ +## This script will check if some Ceph related Debian packages are available +## in APT cache. +## And backup all of them (ceph, rados, rbd,…) in tar with version name and date. +# +## You can use this script in a cron (for periodic backup of Ceph packages) or +## directly. +# }}} + +# Vars {{{ +CEPH_DEB_DIR="/var/cache/apt/archives" +CEPH_DEB_PKG_FILE=$(find "${CEPH_DEB_DIR}" -maxdepth 1 -type f -iname "ceph*.deb" -print -quit) +CEPH_VERSION=$(basename "${CEPH_DEB_PKG_FILE}"|cut -d"_" -f2|sed 's/\(.*\)~.*/\1/') + +BKP_DIR="/srv/ceph" +BKP_TAR_PATH="${BKP_DIR}/ceph-deb_${CEPH_VERSION}-$(date +%Y%m%d).tar" +# }}} + +# Test if a "ceph" package is available +if [ "${CEPH_DEB_PKG_FILE}" ]; then + + mkdir -p -- "${BKP_DIR}" + + # If no recent backup of deb files (<7 days), create a new archive + if [ ! "$(find "${BKP_DIR}" -type f -iname "ceph-deb*.tar" -mtime -7)" ]; then + printf '%b\n' "Backup of Ceph deb files in version : ${CEPH_VERSION}" + tar cf "${BKP_TAR_PATH}" "${CEPH_DEB_DIR}"/*"${CEPH_VERSION}"*.deb > /dev/null 2>&1 + fi + +fi + +exit 0