]> arthur.barton.de Git - backup-script.git/commitdiff
ZFS: Use correct date for snapshot names
authorAlexander Barton <alex@barton.de>
Tue, 4 Aug 2015 12:10:30 +0000 (14:10 +0200)
committerAlexander Barton <alex@barton.de>
Tue, 4 Aug 2015 12:10:30 +0000 (14:10 +0200)
Don't use the current time, but the time of the (last) backup.

bin/backup-script

index 82016cd68e319fdfdd6115bbebe6f26336498019..e3032e4a6bd7ce21ab8a8fd755bd244d35bb5ae8 100755 (executable)
@@ -234,10 +234,21 @@ Initialize_Last_SysTarget_Snapshot() {
                ;;
          "zfs")
                # On ZFS, the last generation is always named "current"
-               [ -e "$sys_target/current" ] \
-                       && last="$sys_target/current" \
-                       || last=""
-               snapshot="$(echo "$sys_target/current" | cut -c2-)@$(date +%Y%m%d-%H%M%S)"
+               if [ -e "$sys_target/current" ]; then
+                       last="$sys_target/current"
+                       if [ "$(uname)" = "Linux" ]; then
+                               date=$(LC_ALL=C stat "$1" | grep "^Modify: " \
+                                | cut -d':' -f2- | cut -d. -f1)
+                       else
+                               date=$(LC_ALL=C stat -f "%Sc" "$1")
+                       fi
+                       date=$(echo "$date" | sed -e's/^ //g' -e 's/[-:]//g' -e 's/ /-/g')
+
+               else
+                       last=""
+                       date="$(date +%Y%m%d-%H%M%S)"
+               fi
+               snapshot="$(echo "$sys_target/current" | cut -c2-)@$date"
                sys_target="$sys_target/current"
                ;;
          *)