Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #uncomment the next line to turn on debugging
- #DEBUG=1
- TARGET="$1"
- #determine parent dataset's name
- BASE=${TARGET%*@*}
- #determine name of the snapshot name
- SNAP=${TARGET#*@*}
- #get the creation date from the snapshot
- CDATE=$(zfs get -H -o value creation "$TARGET")
- #convert this from this shape: "Fri May 17 11:52 2013" to YYYY-MM-DD
- TODATE=$(date -j -f "%a %B %d %H:%M %Y" "$CDATE" +%F)
- ## Debug diagnostics
- if [[ 1 = $DEBUG ]]
- then
- echo "$TARGET"
- echo "$BASE"
- echo "$SNAP"
- echo "$CDATE"
- echo "$TODATE"
- echo "$BASE"@"$TODATE"
- fi
- #disable action while debugging
- if [[ ! $DEBUG ]]
- then
- echo -n "Renaming" "$TARGET" to "$BASE"@"$TODATE":" "
- zfs rename "$TARGET" "$BASE"@"$TODATE"
- echo "OK"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement