@echo off
color 0a
ECHO. 

rd /s /q backup > nul 2>&1

adb shell  "rm -rf /sdcard/backup "

adb shell "mkdir /sdcard/backup"


for /F %%i in ('adb shell ls /dev/block/platform/') do ( set commitid=%%i)

echo commitid=%commitid%

set EXISTS_FLAG=false

echo %commitid%|find "soc">nul&&set EXISTS_FLAG=true

if "%EXISTS_FLAG%"=="true" (
	ECHO 正在备份 soc backup 分区，耐心等待......

	adb shell "dd if=/dev/block/platform/soc/by-name/backup    | busybox gzip -4 >/sdcard/backup/backup.img.gz"
	
	adb shell "dd if=/dev/block/platform/soc/by-name/kernel    | busybox gzip -4 >/sdcard/backup/kernel.img.gz"
	
	adb shell "dd if=/dev/block/platform/soc/by-name/boot    | busybox gzip -4 >/sdcard/backup/boot.img.gz"
	
	adb shell "dd if=/dev/block/platform/soc/by-name/recovery.img    | busybox gzip -4 >/sdcard/backup/recovery.img.gz"
	
	adb shell "dd if=/dev/block/platform/soc/by-name/system.img    | busybox gzip -4 >/sdcard/backup/system.img.gz"

	ECHO 正在上传备份的固件，耐心等待......

	adb pull -p  /sdcard/backup  backup

	ECHO 备份完成，固件存放位置为工具根目录backup文件！！！

	pause>NUL
	
) else (
	ECHO 正在备份3798 backup 分区，耐心等待......

	adb shell "dd if=/dev/block/platform/hi_mci.1/by-name/backup    of=/sdcard/backup/backup3798mv100.img"

	ECHO 正在上传备份的固件，耐心等待......

	adb pull -p  /sdcard/backup  backup

	ECHO 备份完成，固件存放位置为工具根目录backup文件！！！

	pause>NUL
)
