diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2017-04-10 22:07:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2017-04-10 22:07:25 +0000 |
commit | 68020a27f8936e5d2fb2aa70efa572d0c65b55a8 (patch) | |
tree | a4905e61caef9cae11c39f6b46df0e5e69947ea7 /bin/cephfs-snap | |
parent | Adding upstream version 20170405. (diff) | |
download | open-infrastructure-storage-tools-68020a27f8936e5d2fb2aa70efa572d0c65b55a8.tar.xz open-infrastructure-storage-tools-68020a27f8936e5d2fb2aa70efa572d0c65b55a8.zip |
Adding upstream version 20170410.upstream/20170410
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'bin/cephfs-snap')
-rwxr-xr-x | bin/cephfs-snap | 56 |
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 |