小米手机怎么恢复备份

发布时间: 2023-02-24 09:34 阅读: 文章来源:转载

前 提:

有root权限备份恢复boot/system分区为例

先查看分区信息:

方法一 :

命令:ls -l /dev/block/platform/mtk-msdc.0/by-name/

root@GiONEE_GBL7319:/ # ls -l /dev/block/platform/mtk-msdc.0/by-name/lrwxrwxrwx root root2022-05-20 21:16 boot -> /dev/block/mmcblk0p7lrwxrwxrwx root root2022-05-20 21:16 cache -> /dev/block/mmcblk0p21lrwxrwxrwx root root2022-05-20 21:16 expdb -> /dev/block/mmcblk0p10lrwxrwxrwx root root2022-05-20 21:16 flashinfo -> /dev/block/mmcblk0p23lrwxrwxrwx root root2022-05-20 21:16 frp -> /dev/block/mmcblk0p17lrwxrwxrwx root root2022-05-20 21:16 keystore -> /dev/block/mmcblk0p14lrwxrwxrwx root root2022-05-20 21:16 lk -> /dev/block/mmcblk0p5lrwxrwxrwx root root2022-05-20 21:16 logo -> /dev/block/mmcblk0p9lrwxrwxrwx root root2022-05-20 21:16 metadata -> /dev/block/mmcblk0p19lrwxrwxrwx root root2022-05-20 21:16 nvdata -> /dev/block/mmcblk0p18lrwxrwxrwx root root2022-05-20 21:16 nvram -> /dev/block/mmcblk0p2lrwxrwxrwx root root2022-05-20 21:16 oemkeystore -> /dev/block/mmcblk0p12lrwxrwxrwx root root2022-05-20 21:16 para -> /dev/block/mmcblk0p6lrwxrwxrwx root root2022-05-20 21:16 proinfo -> /dev/block/mmcblk0p1lrwxrwxrwx root root2022-05-20 21:16 protect1 -> /dev/block/mmcblk0p3lrwxrwxrwx root root2022-05-20 21:16 protect2 -> /dev/block/mmcblk0p4lrwxrwxrwx root root2022-05-20 21:16 recovery -> /dev/block/mmcblk0p8lrwxrwxrwx root root2022-05-20 21:16 seccfg -> /dev/block/mmcblk0p11lrwxrwxrwx root root2022-05-20 21:16 secro -> /dev/block/mmcblk0p13lrwxrwxrwx root root2022-05-20 21:16 system -> /dev/block/mmcblk0p20lrwxrwxrwx root root2022-05-20 21:16 tee1 -> /dev/block/mmcblk0p15lrwxrwxrwx root root2022-05-20 21:16 tee2 -> /dev/block/mmcblk0p16lrwxrwxrwx root root2022-05-20 21:16 userdata -> /dev/block/mmcblk0p22

boot分区对应实际的目录是/dev/block/mmcblk0p7

方法二:

根目录/下的fstab.xxx和/dev/recovery.fstab也可查相关信息

备 份:

方法一:cat

命令:cat /dev/block/mmcblk0p7 > /sdcard/bootBAK.img

root@GiONEE_GBL7319:/ # cat /dev/block/mmcblk0p7 > /sdcard/bootBAK.img

查看结果:

root@GiONEE_GBL7319:/ # ls -l /sdcard/boot*-rw-rw---- root sdcard_r7145472 2015-06-30 07:04 boot.img-rw-rw---- root sdcard_r 16777216 2022-05-20 21:45 bootBAK.img-rw-rw---- root sdcard_r7485440 2022-02-28 08:22 bootF103_magisk.img

bootBAK.img大小是16777216字节

对比一下:

先查看分区大小

命令:cat /proc/partitions

root@GiONEE_GBL7319:/ # cat /proc/partitionsmajor minor#blocksname 2540 491520 zram07018944 loop0 179015267840 mmcblk0 17913072 mmcblk0p1 17925120 mmcblk0p2 179310240 mmcblk0p3 179410240 mmcblk0p4 1795512 mmcblk0p5 1796512 mmcblk0p6 179716384 mmcblk0p7对应boot分区 179816384 mmcblk0p8 17998192 mmcblk0p9 1791010240 mmcblk0p10 17911512 mmcblk0p11 179122048 mmcblk0p12 179136144 mmcblk0p13 179148192 mmcblk0p14 179155120 mmcblk0p15 179165120 mmcblk0p16 179171024 mmcblk0p17 1791832768 mmcblk0p18 1791937888 mmcblk0p19 179202097152 mmcblk0p20 17921 409600 mmcblk0p21 1792212563968 mmcblk0p22 1792316384 mmcblk0p23 179964096 mmcblk0rpmb 179644096 mmcblk0boot1 179324096 mmcblk0boot0

mmcblk0p7的blocks是16384块,每块大小1024字节

boot大小 = 16384 * 1024 = 16777216字节,与备份出来的大小一样。

方法二:dd

命令:dd if=/dev/block/mmcblk0p7 of=/sdcard/bootBAK2.img

1|root@GiONEE_GBL7319:/ # dd if=/dev/block/mmcblk0p7 of=/sdcard/bootBAK2.img32768+0 records in32768+0 records out16777216 bytes transferred in 2.001 secs (8384415 bytes/sec)

或者:

dd if=/dev/block/mmcblk0p7 of=/sdcard/bootBAK2.img bs=1024 count=16384

命令说明 :

if表示输入(数据源)of表示输出(备份到哪)bs即blockscount是多少个bs

结果:

root@GiONEE_GBL7319:/ # ls -l /sdcard/boot*-rw-rw---- root sdcard_r7145472 2015-06-30 07:04 boot.img-rw-rw---- root sdcard_r 16777216 2022-05-20 21:45 bootBAK.img-rw-rw---- root sdcard_r 16777216 2022-05-20 21:56 bootBAK2.img-rw-rw---- root sdcard_r7485440 2022-02-28 08:22 bootF103_magisk.img

方法三:cpio

命令:find /system -print | cpio -ovd -H newc > /sdcard/system.cpio 备份/system

root@GiONEE_GBL7319:/ # find /system -print | busybox cpio -ovd -H newc > /sdcard/system.cpioroot@GiONEE_GBL7319:/ # ls -l /sdcard/system*-rw-rw---- root sdcard_r 1916820332 2022-05-25 23:11 system.cpioroot@GiONEE_GBL7319:/ # file /sdcard/system.cpio/sdcard/system.cpio: ASCII cpio archive (SVR4 with no CRC)

方法四:tar

命令:tar cvzpf system-bak0526.tar.gz --exclude=/system/lost+found --exclude=/system/recovery-from-boot.bak /system

备份/system时排除掉./lost+found , recovery-from-boot.bak

先查看/system数据:

c:\tmp\fastboot>adb shellshell@GiONEE_GBL7319:/ $ suroot@GiONEE_GBL7319:/ # ls /systemappbinbuild.propdataetcfontsframeworkliblib64lost+foundmediapluginpriv-apprecovery-from-boot.bakresttsusrvendorxbin

执行备份:

root@GiONEE_GBL7319:/ # cd /sdcardroot@GiONEE_GBL7319:/sdcard # busybox tar cvzpf system-bak0526.tar.gz --exclude=/system/lost+found --exclude=/system/recovery-from-boot.bak/system

参数说明:

-c 建立压缩文件-x 解开压缩文件-v 显示列表-z 用gzip进行压缩-p 保留原来的属性-f 指定压缩文档名--exclude 排除的文件或目录

查看结果:

root@GiONEE_GBL7319:/sdcard # ll sys*-rw-rw---- root sdcard_r 1132545851 2022-05-26 16:04 system-bak0526.tar.gz130|root@GiONEE_GBL7319:/sdcard # busybox tar -tf system-bak0526.tar.gz|grep flash_imagesystem/xbin/flash_image

=================================

恢 复 分 区/数据:

方法一:dd

命令:dd if=/sdcard/bootBAK2.img of=/dev/block/mmcblk0p7

root@GiONEE_GBL7319:/ # dd if=/sdcard/bootBAK2.img of=/dev/block/mmcblk0p7

方法二:fastboot flash

命令:fastboot flash boot bootBAK2.img

c:\tmp\fastboot>adb reboot bootloaderc:\tmp\fastboot>fastboot devices8T8HBIZSBU9PCM4Sfastbootc:\tmp\fastboot>fastboot flash boot bootBAK2.img

方法三:flash_image

命令:flash_image partition file.img

有时候partition不识别boot, 则改为/dev/block/mmcblk0p7试试

root@GiONEE_GBL7319:/ # flash_image boot /sdcard/bootBAK2.imgfailed with error: -1root@GiONEE_GBL7319:/ # flash_image /dev/block/mmcblk0p7 /sdcard/bootBAK2.img

方法四:cpio

命令:cpio -iuvd < /sdcard/system.cpio

参数说明:

-i 将数据文件复制到系统中,copy-in-o 将系统数据复制成文件,copy-out-u 自动将较新文件覆盖旧文件-v 显示清单-d 自动建立目录-p 原版备份,不进行额外处理-H format

format有如下格式:

bin : The obsolete binary format. (2147483647 bytes)odc : The old (POSIX.1) portable format. (8589934591 bytes)newc : The new (SVR4) portable format, which supports file systems having more than 65536 i-nodes. (4294967295 bytes)

另外说明 :

dd命令可备份 :文件、分区、磁盘、光盘等

用法说明:

Usage: dd [if=FILE] [of=FILE] [ibs=N obs=N/bs=N] [count=N] [skip=N] [seek=N][conv=notrunc|noerror|sync|fsync][iflag=skip_bytes|fullblock] [oflag=seek_bytes|append]Copy a file with converting and formattingif=FILE Read from FILE instead of stdinof=FILE Write to FILE instead of stdoutbs=NRead and write N bytes at a timeibs=NRead N bytes at a timeobs=NWrite N bytes at a timecount=N Copy only N input blocksskip=NSkip N input blocksseek=NSkip N output blocksconv=notruncDon‘t truncate output fileconv=noerrorContinue after read errorsconv=syncPad blocks with zerosconv=fsyncPhysically write data out before finishingconv=swabSwap every pair of bytesiflag=skip_bytesskip=N is in bytesiflag=fullblock Read full blocksoflag=seek_bytesseek=N is in bytesoflag=appendOpen output file in append modestatus=noxferSuppress rate outputstatus=none Suppress all outputN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G

/dev/null : 回收站

/dev/zero :生成0字符

•••展开全文
相关文章