You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB
Bash

#!/bin/bash
PARTITION_DIRECTORY="/dev/block/platform/msm_sdcc.1/by-name"
current_date="$(date +%Y%m%d)"
function backup_partition {
partition_path="$1"
partition_name="$(basename "${partition_path}")"
echo "Backing up partition ${partition_name}."
backup_image_name="${partition_name}-${current_date}.img"
echo "Copying partition."
adb shell "base64 < \"${partition_path}\"" | base64 -di > "$backup_image_name"
echo "Hashing backup image."
sha256sum "$backup_image_name" > "${backup_image_name}.SHA256SUM"
backup_hash=$(cut -d ' ' -f 1 < "${backup_image_name}.SHA256SUM")
echo "Hashing original image."
original_hash=$(adb shell "sha256sum ${partition_path}" | cut -d ' ' -f 1)
if [ "$original_hash" = "$backup_hash" ]; then
echo "Backup successful."
else
echo "Backup of partition ${partition_name} failed."
fi
}
# Technically this is a bit fragile, but the partition names don't break it and aren't going
# to change anytime soon and this is much easier to read than the super safe solution.
for partition_path in $(find "${PARTITION_DIRECTORY}"); do
backup_partition "$partition_path"
done