2019-07-22 11:43:59 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# Purpose {{{
|
2019-07-24 11:12:40 +02:00
|
|
|
|
## This script will check if Ceph is available on the system.
|
|
|
|
|
## And download all deb files of all Ceph related packages installed on the system
|
|
|
|
|
## (eg. ceph, rbd, rados,…).
|
2019-07-22 11:43:59 +02:00
|
|
|
|
#
|
2019-07-24 11:12:40 +02:00
|
|
|
|
## You can use this script in a cron (for periodic backup of Ceph packages) or directly.
|
2019-07-22 11:43:59 +02:00
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
# Vars {{{
|
2019-07-24 11:46:37 +02:00
|
|
|
|
DEBUG=1
|
|
|
|
|
|
2019-07-22 16:25:08 +02:00
|
|
|
|
CEPH_DEB_PKG_DIR=$(mktemp --directory --tmpdir="/tmp" -- ceph-deb-files-XXXXXX.tmp)
|
2019-07-31 15:00:00 +02:00
|
|
|
|
CEPH_DEB_PKG_PATTERN="ceph|Ceph|rados|RADOS|rbd|rgw"
|
2019-07-22 16:25:08 +02:00
|
|
|
|
|
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
|
|
|
|
# }}}
|
|
|
|
|
|
2019-07-22 16:25:08 +02:00
|
|
|
|
# If Ceph is installed on the system
|
|
|
|
|
if [ "$(command -v ceph)" ]; then
|
2019-07-22 11:43:59 +02:00
|
|
|
|
|
2019-07-22 16:25:08 +02:00
|
|
|
|
# and no backup of this version already exists
|
|
|
|
|
if [ ! "${EXISTENT_BACKUP_TAR}" ]; then
|
|
|
|
|
## Ensure to create backup directory
|
|
|
|
|
mkdir -p -- "${BKP_DIR}"
|
2019-07-22 11:43:59 +02:00
|
|
|
|
|
2019-07-22 16:25:08 +02:00
|
|
|
|
## Create and go to a temp directory
|
|
|
|
|
cd -- "${CEPH_DEB_PKG_DIR}" > /dev/null || exit 2
|
|
|
|
|
|
|
|
|
|
## Download deb files of all ceph related packages installed on the system
|
2019-07-24 11:46:37 +02:00
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '%b\n' "Download deb files of all ceph related packages installed on the system."
|
2019-07-30 11:27:04 +02:00
|
|
|
|
## Use aptitude before Debian Stretch because apt doesn't yet know "download" action
|
|
|
|
|
if [ "$(cat /etc/debian_version | cut -c1)" -lt "9" ]; then
|
|
|
|
|
aptitude download -- $(dpkg -l | awk -v pattern="${CEPH_DEB_PKG_PATTERN}" '$0~pattern {print $2"="$3}') || exit 3
|
|
|
|
|
else
|
|
|
|
|
apt download -- $(dpkg -l | awk -v pattern="${CEPH_DEB_PKG_PATTERN}" '$0~pattern {print $2"="$3}') || exit 3
|
|
|
|
|
fi
|
2019-07-22 16:25:08 +02:00
|
|
|
|
|
2019-07-24 11:46:37 +02:00
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '%b\n' "Backup Ceph deb files in version : ${CEPH_VERSION}"
|
2019-07-24 11:26:09 +02:00
|
|
|
|
tar cf "${BKP_TAR_PATH}" ./*.deb > /dev/null 2>&1 || exit 4
|
2019-07-22 16:25:08 +02:00
|
|
|
|
|
|
|
|
|
## Remove deb files
|
|
|
|
|
rm -rf -- *.deb
|
|
|
|
|
|
|
|
|
|
cd - > /dev/null || exit 2
|
|
|
|
|
|
|
|
|
|
## Remove temp directory
|
|
|
|
|
rmdir -- "${CEPH_DEB_PKG_DIR}"
|
2019-07-22 11:58:43 +02:00
|
|
|
|
else
|
2019-07-24 11:46:37 +02:00
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '%b\n' "A backup of this version already exists : ${EXISTENT_BACKUP_TAR}"
|
|
|
|
|
exit 0
|
2019-07-22 11:43:59 +02:00
|
|
|
|
fi
|
|
|
|
|
|
2019-07-22 16:25:08 +02:00
|
|
|
|
else
|
2019-07-24 11:46:37 +02:00
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '%b\n' "Ceph doesn't seems to be available. Please take a look on \`ceph version\` command"
|
2019-07-22 16:25:08 +02:00
|
|
|
|
exit 1
|
2019-07-22 11:43:59 +02:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
exit 0
|