2019-07-22 11:43:59 +02:00
|
|
|
|
#!/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)
|
2019-07-22 13:26:04 +02:00
|
|
|
|
CEPH_VERSION=$(ceph version | cut -d" " -f3)
|
2019-07-22 11:43:59 +02:00
|
|
|
|
|
|
|
|
|
BKP_DIR="/srv/ceph"
|
|
|
|
|
BKP_TAR_PATH="${BKP_DIR}/ceph-deb_${CEPH_VERSION}-$(date +%Y%m%d).tar"
|
2019-07-22 13:26:04 +02:00
|
|
|
|
|
|
|
|
|
EXISTENT_BACKUP_TAR="$(find "${BKP_DIR}" -type f -iname "ceph-deb_${CEPH_VERSION}*")"
|
2019-07-22 11:43:59 +02:00
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
# Test if a "ceph" package is available
|
|
|
|
|
if [ "${CEPH_DEB_PKG_FILE}" ]; then
|
|
|
|
|
|
|
|
|
|
mkdir -p -- "${BKP_DIR}"
|
|
|
|
|
|
2019-07-22 11:58:43 +02:00
|
|
|
|
# If no backup of this version already exists, create a new one
|
|
|
|
|
if [ "${EXISTENT_BACKUP_TAR}" ]; then
|
|
|
|
|
printf '%b\n' "A backup of this version already exists : ${EXISTENT_BACKUP_TAR}"
|
|
|
|
|
else
|
2019-07-22 11:43:59 +02:00
|
|
|
|
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
|