summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
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