Commit 92cc79ec authored by Alban Bruder's avatar Alban Bruder

Update cephfs snapshot tool

parent 54f5ab37
......@@ -21,6 +21,7 @@ check_tools "realpath"
### : path : dpath! : .
### : -t : --tag : str : manual : Snapshot tag
### : -n : --num : int :: Number of snapshots with the given tag
### :: --timestamp : str : %Y%m%d_%H%M%S : Timestamp or date format
cmd_snapshot() {
ARG_PATH="$(realpath "$ARG_PATH")"
......@@ -33,7 +34,7 @@ cmd_snapshot() {
ARG_NUM="-1"
fi
newsnap="${ARG_PATH}/.snap/${ARG_TAG}_$(date +'%Y%m%d_%H%M%S')"
newsnap="${ARG_PATH}/.snap/${ARG_TAG}_$(date +"$ARG_TIMESTAMP")"
# Create snapshot
if [ ! "$ARG_NUM" -eq 0 ] ; then
......@@ -65,9 +66,9 @@ cmd_snapshot() {
### : path : path : .
### : -t : --tag : str :: Snapshot tag
cmd_snapshot_list() {
snappattern=^.
snappattern=.
if [[ ! -z "$ARG_TAG" ]]; then
snappattern="${ARG_TAG}_*_*"
snappattern="${ARG_TAG}_"
fi
prefix="$(realpath -m "$ARG_PATH")"
......@@ -76,10 +77,13 @@ cmd_snapshot_list() {
# list snapshots
while [[ "$prefix" != "/" ]]; do
ls -d -1a "${prefix}"/.snap/* 2>/dev/null | while read snap ; do
if [[ -e "$snap/$suffix" ]] && { [[ -z "$ARG_TAG" ]] || [[ "$(basename $snap)" =~ ^"$ARG_TAG"_[0-9]{8}_[0-9]{6}$ ]]; }; then
if [[ "$(basename $snap)" =~ ^[a-zA-Z0-9]*_[0-9]{8}_[0-9]{6}$ ]]; then
if [[ -e "$snap/$suffix" ]] && { [[ -z "$ARG_TAG" ]] || [[ "$(basename $snap)" =~ ^"$snappattern" ]]; }; then
if [[ "$(basename $snap)" =~ ^[^_]+_[0-9]{8}_[0-9]{6}$ ]]; then
snap_date="$(basename $snap | awk -F'_' '{print substr($2,1,4) "-" substr($2,5,2) "-" substr($2,7,2) " " substr($3,1,2) ":" substr($3,3,2) ":" substr($3,5,2)}')"
snap_tag="$(basename $snap | awk -F'_' '{print $1}')"
elif [[ "$(basename $snap)" =~ ^[^_]+_[0-9]{8}$ ]]; then
snap_date="$(basename $snap | awk -F'_' '{print substr($2,1,4) "-" substr($2,5,2) "-" substr($2,7,2)}') 00:00:00"
snap_tag="$(basename $snap | awk -F'_' '{print $1}')"
else
snap_date="$(date -r "$snap" "+%Y-%m-%d %H:%M:%S")"
snap_tag="$(basename $snap)"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment