Advertisement
killermist

snap-to-date.sh

Jun 11th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.73 KB | None | 0 0
  1. #!/bin/bash
  2. #uncomment the next line to turn on debugging
  3. #DEBUG=1
  4. TARGET="$1"
  5. #determine parent dataset's name
  6. BASE=${TARGET%*@*}
  7. #determine name of the snapshot name
  8. SNAP=${TARGET#*@*}
  9. #get the creation date from the snapshot
  10. CDATE=$(zfs get -H -o value creation "$TARGET")
  11. #convert this from this shape: "Fri May 17 11:52 2013" to YYYY-MM-DD
  12. TODATE=$(date -j -f "%a %B %d %H:%M %Y" "$CDATE"  +%F)
  13. ## Debug diagnostics
  14. if [[ 1 = $DEBUG ]]
  15. then
  16.   echo "$TARGET"
  17.   echo "$BASE"
  18.   echo "$SNAP"
  19.   echo "$CDATE"
  20.   echo "$TODATE"
  21.   echo "$BASE"@"$TODATE"
  22. fi
  23. #disable action while debugging
  24. if [[ ! $DEBUG ]]
  25. then
  26.   echo -n "Renaming" "$TARGET" to "$BASE"@"$TODATE":"   "
  27.   zfs rename "$TARGET" "$BASE"@"$TODATE"
  28.   echo "OK"
  29. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement