summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2017-04-10 22:07:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2017-04-10 22:07:56 +0000
commitc942987a96449cc168c1b50397680c73998932ab (patch)
tree4c1e385f4a2529f50802b12155aa1db113474a64 /bin
parentAdding debian version 20170405-1. (diff)
downloadopen-infrastructure-storage-tools-c942987a96449cc168c1b50397680c73998932ab.tar.xz
open-infrastructure-storage-tools-c942987a96449cc168c1b50397680c73998932ab.zip
Merging upstream version 20170410.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cephfs-snap56
1 files changed, 42 insertions, 14 deletions
diff --git a/bin/cephfs-snap b/bin/cephfs-snap
index d846ef4..52548d3 100755
--- a/bin/cephfs-snap
+++ b/bin/cephfs-snap
@@ -21,11 +21,11 @@ set -e
SOFTWARE="storage-tools"
PROGRAM="cephfs-snap"
-ACTION="${1}"
+ACTION="${1:-manual}"
Usage ()
{
- echo "Usage: ${PROGRAM} {hourly|daily|weekly|hourly}" >&2
+ echo "Usage: ${PROGRAM} {hourly|daily|weekly|monthly|yearly}" >&2
exit 1
}
@@ -43,15 +43,24 @@ case "${CEPHFS_SNAP}" in
;;
esac
-if [ -z "${CEPHFS_DIRECTORIES}" ]
+if [ -z "${CEPHFS_SNAP_DIRECTORIES}" ]
then
echo "E: no cephfs directories defined in /etc/default/${SOFTWARE}" >&2
exit 1
fi
case "${ACTION}" in
- hourly|daily|weekly|monthly)
+ hourly|daily|weekly|monthly|yearly)
+ ROTATION="$(eval "echo \${CEPHFS_SNAP_$(echo "${ACTION}" | tr [a-z] [A-Z])}")"
+
+ if [ -z "${ROTATION}" ]
+ then
+ echo "E: no cephfs snapshot rotation for ${ACTION} defined in /etc/default/${SOFTWARE}" >&2
+ exit 1
+ fi
+ ;;
+ manual)
;;
*)
@@ -60,14 +69,39 @@ case "${ACTION}" in
esac
# Run
+TIME="$(date +%Y-%m-%d_%H%M%S%z)"
+SNAPSHOT="${TIME}_${ACTION}"
+
+for CEPHFS_SNAP_DIRECTORY in ${CEPHFS_SNAP_DIRECTORIES}
+do
+ cd "${CEPHFS_SNAP_DIRECTORY}"/.snap
+ mkdir "${SNAPSHOT}"
+
+ case "${ACTION}" in
+ manual)
+ ;;
+
+ *)
+ if [ "$(ls -d *_"${ACTION}" | wc -l)" -gt "${ROTATION}" ]
+ then
+ # more snapshots available than configured to keep
+ SNAPS="$(ls -d *_"${ACTION}" | sort -r | tail -n +$((${ROTATION} + 1)))"
+
+ for SNAP in ${SNAPS}
+ do
+ rmdir "${SNAP}"
+ done
+ fi
+ ;;
+ esac
+done
+
DATE="$(date +%Y-%m-%d\ %H:%M:%S)"
HOST="$(hostname -f)"
-TIME="$(date +%Y-%m-%d_%H%M%z)"
-SNAPSHOT="${ACTION}_${TIME}"
-
# logfile
-echo "${DATE} ${HOST} ${PROGRAM} creating ${ACTION} snapshots" >> "/var/log/${SOFTWARE}/${PROGRAM}.log"
+mkdir -p "/var/log/${SOFTWARE}/${PROGRAM}"
+echo "${DATE} ${HOST} ${PROGRAM} creating ${ACTION} snapshots" >> "/var/log/${SOFTWARE}/${PROGRAM}/${PROGRAM}.log"
# irc
if [ -e /usr/bin/irk ] && [ -e "/etc/default/${SOFTWARE}" ]
@@ -80,9 +114,3 @@ then
done
fi
fi
-
-for CEPHFS_DIRECTORY in ${CEPHFS_DIRECTORIES}
-do
- cd "${CEPHFS_DIRECTORY}"/.snap
- mkdir "${SNAPSHOT}"
-done