diff --git a/bootable/recovery/system-image-upgrader b/bootable/recovery/system-image-upgrader
index f665d49..c273634 100755
--- a/bootable/recovery/system-image-upgrader
+++ b/bootable/recovery/system-image-upgrader
@@ -13,6 +13,9 @@ REMOVE_LIST="$COMMAND_FILE"
# Used as a security check to see if we would change the password
DATA_FORMAT=0
+# Used as indication if we have applied an update or not
+UPDATE_APPLIED=0
+
# System Mountpoint
SYSTEM_MOUNTPOINT=/cache/system
@@ -320,6 +323,15 @@ do
;;
data)
+ WHITELIST=".last_update .last_ubuntu-build system-data/var/lib/dbus/machine-id system-data/var/lib/whoopsie/whoopsie-id"
+ BACKUP_DIR=`mktemp -d /tmp/backup.XXXXXX`
+
+ # Backup all whitelisted files here so we can restore them later
+ for file in $WHITELIST ; do
+ mkdir -p $BACKUP_DIR/`dirname $file`
+ cp -av $file $BACKUP_DIR/data/$file
+ done
+
# If Android bits are used from the real system partition and we don't
# have any image in /data we need to loop mount we can simply reformat
# the userdata partition instead of erasing just files. In the other
@@ -342,6 +354,12 @@ do
done
fi
+ # Now restore all files we created a backup for
+ for file in $WHITELIST ; do
+ mkdir -p /data/`dirname $file`
+ cp -av $BACKUP_DIR/$file /data/$file
+ done
+
# mtp is always enabled by default
usb_enable mtp
DATA_FORMAT=1
@@ -511,6 +529,8 @@ do
rm partitions/${part}.img
fi
done
+
+ UPDATE_APPLIED=1
;;
*)
@@ -561,7 +581,14 @@ fi
chmod 600 /data/SWAP.img
chown 0:0 /data/SWAP.img
-touch /data/.last_update || true
+# Only touch .last_update file when
+# * it doesn't exist
+# * or an update was applied
+# In all other caes we leave it as is to avoid changing it's access time
+if [ ! -e /data/.last_update ] || [ "$UPDATE_APPLIED" -eq 0 ] ; then
+ touch /data/.last_update
+fi
+
sync
echo "Done upgrading: $(date)"