Simple backup script - Google Pixel 4a 5G ROMs, Kernels, Recoveries, & Ot

I can't script worth a sh|t, hence my desire to share with other Pixel 4a5g owners, haha. Provided there is already a folder named '/partbackups' on the microsd card, the script should make a dd image backup of ALL 73 partitions on the phone, including userdata (pics, etc.) in compressed .gz format to save space (and time, since the script pipes the output to gzip).
I want to make it so it creates a folder with unique $Date$Time appended if not already existing (mkdir -p) for each backup run. So if run again it makes a new folder under /partbackups,One of these days I'll finish it, unless someone else wants to. This is just a rough draft. Requires dd utility in recovery, tested with TWRP. Need fastboot to boot TWRP
Put the script where you will remember it. I put it on the root of the phone's user storage which is /sdcard (or /emulated/0) or something. Doesnt matter where you put it (Downloads,Documents, etc.)
From Bootloader screen and phone connected to USB: fastboot boot twrp.img (unplug usb cable from phone after OK from terminal/cmd window).
TWRP should load. Goto Mount screen. Insert USB2GO usb adapter/microsd reader with properly formatted filesystem (I used ext4, but I think exfat works too?). You should see your storage there and go ahead and mount it. Then back out to main menu, goto advanced, then terminal. FYI, when mounted, the path to the mount point/microsd reader (USB2GO) is '/auto0-1/' .
Make sure to mark the script as executable: chmod +x partbackupgz.sh
run the script: ./partbackupgz.sh
There will only be output after each partition compresses over to storage. userdata (sda19) takes the longest. Let it run. It's not frozen. Does seem to use battery.
When it's done it will dump and compress each partition over on the fly with gzip.
When it's done, unmount the storage, remove and reboot. Again. I don't code/script. This is a work in progress. I'm not responsible if you open up a portal.
Please improve this script. I'll write a recovery script when I need one..Lol. Or maybe you will.
Bash:
#!/system/bin/sh
dd if=/dev/block/sda1 bs=1M | gzip -c > /auto0-1/partbackups/ssd.img.gz
dd if=/dev/block/sda2 bs=1M | gzip -c > /auto0-1/partbackups/persist.img.gz
dd if=/dev/block/sda3 bs=1M | gzip -c > /auto0-1/partbackups/misc.img.gz
dd if=/dev/block/sda4 bs=1M | gzip -c > /auto0-1/partbackups/keystore.img.gz
dd if=/dev/block/sda5 bs=1M | gzip -c > /auto0-1/partbackups/frp.img.gz
dd if=/dev/block/sda6 bs=1M | gzip -c > /auto0-1/partbackups/boot_a.img.gz
dd if=/dev/block/sda7 bs=1M | gzip -c > /auto0-1/partbackups/boot_b.img.gz
dd if=/dev/block/sda8 bs=1M | gzip -c > /auto0-1/partbackups/vendor_boot_a.img.gz
dd if=/dev/block/sda9 bs=1M | gzip -c > /auto0-1/partbackups/vendor_boot_b.img.gz
dd if=/dev/block/sda10 bs=1M | gzip -c > /auto0-1/partbackups/dtbo_a.img.gz
dd if=/dev/block/sda11 bs=1M | gzip -c > /auto0-1/partbackups/dtbo_b.img.gz
dd if=/dev/block/sda12 bs=1M | gzip -c > /auto0-1/partbackups/modem_a.img.gz
dd if=/dev/block/sda13 bs=1M | gzip -c > /auto0-1/partbackups/modem_b.img.gz
dd if=/dev/block/sda14 bs=1M | gzip -c > /auto0-1/partbackups/klog.img.gz
dd if=/dev/block/sda15 bs=1M | gzip -c > /auto0-1/partbackups/metadata.img.gz
dd if=/dev/block/sda16 bs=1M | gzip -c > /auto0-1/partbackups/vbmeta_system_a.img.gz
dd if=/dev/block/sda17 bs=1M | gzip -c > /auto0-1/partbackups/vbmeta_system_b.img.gz
dd if=/dev/block/sda18 bs=1M | gzip -c > /auto0-1/partbackups/super.img.gz
dd if=/dev/block/sda19 bs=1M | gzip -c > /auto0-1/partbackups/userdata.img.gz
dd if=/dev/block/sdb1 bs=1M | gzip -c > /auto0-1/partbackups/xbl_a.img.gz
dd if=/dev/block/sdb2 bs=1M | gzip -c > /auto0-1/partbackups/xbl_config_a.img.gz
dd if=/dev/block/sdc1 bs=1M | gzip -c > /auto0-1/partbackups/xbl_b.img.gz
dd if=/dev/block/sdc2 bs=1M | gzip -c > /auto0-1/partbackups/xbl_config_b.img.gz
dd if=/dev/block/sdd1 bs=1M | gzip -c > /auto0-1/partbackups/ALIGN_TO_128K_1.img.gz
dd if=/dev/block/sdd2 bs=1M | gzip -c > /auto0-1/partbackups/cdt.img.gz
dd if=/dev/block/sdd3 bs=1M | gzip -c > /auto0-1/partbackups/ddr.img.gz
dd if=/dev/block/sde1 bs=1M | gzip -c > /auto0-1/partbackups/aop_a.img.gz
dd if=/dev/block/sde2 bs=1M | gzip -c > /auto0-1/partbackups/tz_a.img.gz
dd if=/dev/block/sde3 bs=1M | gzip -c > /auto0-1/partbackups/hyp_a.img.gz
dd if=/dev/block/sde4 bs=1M | gzip -c > /auto0-1/partbackups/abl_a.img.gz
dd if=/dev/block/sde5 bs=1M | gzip -c > /auto0-1/partbackups/keymaster_a.img.gz
dd if=/dev/block/sde6 bs=1M | gzip -c > /auto0-1/partbackups/cmnlib_a.img.gz
dd if=/dev/block/sde7 bs=1M | gzip -c > /auto0-1/partbackups/cmnlib64_a.img.gz
dd if=/dev/block/sde8 bs=1M | gzip -c > /auto0-1/partbackups/devcfg_a.img.gz
dd if=/dev/block/sde9 bs=1M | gzip -c > /auto0-1/partbackups/qupfw_a.img.gz
dd if=/dev/block/sde10 bs=1M | gzip -c > /auto0-1/partbackups/vbmeta_a.img.gz
dd if=/dev/block/sde11 bs=1M | gzip -c > /auto0-1/partbackups/reserve_1.img.gz
dd if=/dev/block/sde12 bs=1M | gzip -c > /auto0-1/partbackups/uefisecapp_a.img.gz
dd if=/dev/block/sde13 bs=1M | gzip -c > /auto0-1/partbackups/imagefv_a.img.gz
dd if=/dev/block/sde14 bs=1M | gzip -c > /auto0-1/partbackups/apdp_a.img.gz
dd if=/dev/block/sde15 bs=1M | gzip -c > /auto0-1/partbackups/multiimgoem_a.img.gz
dd if=/dev/block/sde16 bs=1M | gzip -c > /auto0-1/partbackups/featenabler_a.img.gz
dd if=/dev/block/sde17 bs=1M | gzip -c > /auto0-1/partbackups/aop_b.img.gz
dd if=/dev/block/sde18 bs=1M | gzip -c > /auto0-1/partbackups/tz_b.img.gz
dd if=/dev/block/sde19 bs=1M | gzip -c > /auto0-1/partbackups/hyp_b.img.gz
dd if=/dev/block/sde20 bs=1M | gzip -c > /auto0-1/partbackups/abl_b.img.gz
dd if=/dev/block/sde21 bs=1M | gzip -c > /auto0-1/partbackups/keymaster_b.img.gz
dd if=/dev/block/sde22 bs=1M | gzip -c > /auto0-1/partbackups/cmnlib_b.img.gz
dd if=/dev/block/sde23 bs=1M | gzip -c > /auto0-1/partbackups/cmnlib64_b.img.gz
dd if=/dev/block/sde24 bs=1M | gzip -c > /auto0-1/partbackups/devcfg_b.img.gz
dd if=/dev/block/sde25 bs=1M | gzip -c > /auto0-1/partbackups/qupfw_b.img.gz
dd if=/dev/block/sde26 bs=1M | gzip -c > /auto0-1/partbackups/vbmeta_b.img.gz
dd if=/dev/block/sde27 bs=1M | gzip -c > /auto0-1/partbackups/reserve_2.img.gz
dd if=/dev/block/sde28 bs=1M | gzip -c > /auto0-1/partbackups/uefisecapp_b.img.gz
dd if=/dev/block/sde29 bs=1M | gzip -c > /auto0-1/partbackups/imagefv_b.img.gz
dd if=/dev/block/sde30 bs=1M | gzip -c > /auto0-1/partbackups/apdp_b.img.gz
dd if=/dev/block/sde31 bs=1M | gzip -c > /auto0-1/partbackups/multiimgoem_b.img.gz
dd if=/dev/block/sde32 bs=1M | gzip -c > /auto0-1/partbackups/featenabler_b.img.gz
dd if=/dev/block/sde33 bs=1M | gzip -c > /auto0-1/partbackups/devinfo.img.gz
dd if=/dev/block/sde34 bs=1M | gzip -c > /auto0-1/partbackups/spunvm.img.gz
dd if=/dev/block/sde35 bs=1M | gzip -c > /auto0-1/partbackups/splash.img.gz
dd if=/dev/block/sde36 bs=1M | gzip -c > /auto0-1/partbackups/limits.img.gz
dd if=/dev/block/sde37 bs=1M | gzip -c > /auto0-1/partbackups/limits-cdsp.img.gz
dd if=/dev/block/sde38 bs=1M | gzip -c > /auto0-1/partbackups/toolsfv.img.gz
dd if=/dev/block/sde39 bs=1M | gzip -c > /auto0-1/partbackups/logfs.img.gz
dd if=/dev/block/sde40 bs=1M | gzip -c > /auto0-1/partbackups/storsec.img.gz
dd if=/dev/block/sde41 bs=1M | gzip -c > /auto0-1/partbackups/uefivarstore.img.gz
dd if=/dev/block/sde42 bs=1M | gzip -c > /auto0-1/partbackups/secdata.img.gz
dd if=/dev/block/sdf1 bs=1M | gzip -c > /auto0-1/partbackups/ALIGN_TO_128K_2.img.gz
dd if=/dev/block/sdf2 bs=1M | gzip -c > /auto0-1/partbackups/modemst1.img.gz
dd if=/dev/block/sdf3 bs=1M | gzip -c > /auto0-1/partbackups/modemst2.img.gz
dd if=/dev/block/sdf4 bs=1M | gzip -c > /auto0-1/partbackups/fsg.img.gz
dd if=/dev/block/sdf5 bs=1M | gzip -c > /auto0-1/partbackups/fsc.img.gz

what's the point of backup partitions? most can be downloaded from google, some are auto generated, some are just cache and userdata is encrypted therefore useless. not to mention will fail on fat32 storage.

mine aren't encrypted. i think when I put a custom rom on, one of the requirements was to wipe the device which removed the encryption (LineageOS). I can open the .gz files with any archive utility. Or flash them. Similar but different than an ADB pull since dd copies ALL bits including those shown as not in use which for recovery purposes might be good (deleted file).
Some of the partitions not included are EFS partitions that include things like IMEI and serial number. There is supposed to be a backup/auto restoration if one gets wiped and/or golden copy but it has been known on "some" roms (I'd never use MIUI) where EFS gets totally nuked and unless you have a backup of it, or QPST backup of NV, you're screwed.
I think, this will copy EVERYTHING. For encrypted phones, this could still work, abeit more work involved because one would have to extract their key beforehand and then they coud use it to access their encrypted archives. I guess? I dunno.
And this script would be run from the phone in recovery (TWRP), I thought TWRP (or LineageRecovery) works with no encryption only? So it would only benefit those people anyway.

wouldn't it be easier to add important partitions to twrp fstab with flag backup=1?
FBE + metadata encryption used to be supported in TWRP up to Android 12, seems maintainers still working on it.

Oh, if that's the case, great (encryption support). I guess there were issues with A11-A12 and twrp at least
on 4a5g.
Does modiying twrp /fstab give more access to partitions to backup? If so, that would be sweet because I would have it do ALL of them, or at least of course the option. The persist is not enough, in some.....weird...cases and not nessessary this model phone, people have hosed their EFS--how, who knows. But yea I love TWRP. If twrp could be tweaked to backup all partitions if listed in /fstab, that would be super spiffy.

seriously I have no clue how things work on this TWRP, but on older devices one could just add lines in twrp.fstab ourself.
please ask in TWRP support thread maintainer might add important partitions.

thx for info.

Related

extracting initramfs from zImage

I *think* I got this to work, but someone with less n00b should verify.
Code:
'find your header
grep -a -b --only-matching $'\x1f\x8b\x08\x00' < zImage
'use your header value
dd bs=1 if=zImage skip={your number} | gzip -d -c > initramfs.cpio
'extract
sudo cpio -i --no-absolute-filenames < ../initramfs.cpio
I did compile this into a new zImage, but it made no difference, still looping samsungs..
This method (not mine) also works, but generates a file list. You should be able cpio out the files with minor adjustments.. credit to skeeterslint for this.
Code:
grep -a -b --only-matching `perl -e'print "\x1F\x8B\x08"'` zImage
dd if=zImage bs=1 skip=#fromsteponehere | gunzip > Image
grep -a -b --only-matching `perl -e'print "\x1F\x8B\x08"'` Image
dd if=Image bs=1 skip=#fromstep3goeshere | gzip -d -c | cpio -t

[Q] custom backup for Odin restore?

Hey
I found another post which details a way to get all of the relevant files together from your device, and then bundled into a tar, so that you can use Odin to reflash your own 'custom' backup. I have put the commands below, does anyone know how to tailor this for the SGS2 ? The \dev\block\* devices are different as when i try through adb shell or terminal emulator it doesn't recognise the devices ::
Sys:
dd if=/dev/block/stl10 of=/sdcard/factoryfs.rfs bs=4096
Kernel:
dd if=/dev/block/bml8 of=/sdcard/zImage bs=4096
Recovery:
dd if=/dev/block/bml9 of=/sdcard/recovery.bin bs=4096
(personal info)
Cache:
dd if=/dev/block/mmcblk0p3 of=/sdcard/cache.rfs bs=4096
DBData:
dd if=/dev/block/stl11 of=/sdcard/dbdata.rfs bs=4096
Data:
dd if=/dev/block/mmcblk0p1 of=/sdcard/movinand.bin bs=4096
and then to make the image for Odin to flash:
tar -H ustar -c cache.rfs dbdata.rfs factoryfs.rfs movinand.bin recovery.bin zImage > package_name.tar
md5sum -t package_name.tar >> package_name.tar
mv package_name.tar package_name.tar.md5
Any help appreciated
Thanks
I'm interested in this, too!
hi sea_salt !
I got the commands from another post:
dd if=/dev/block/mmcblk0p1 of=/sdcard/p1-EFS.img bs=4096
dd if=/dev/block/mmcblk0p4 of=/sdcard/p4-PARAM.img bs=4096
dd if=/dev/block/mmcblk0p5 of=/sdcard/p5-KERNEL.img bs=4096
dd if=/dev/block/mmcblk0p8 of=/sdcard/p8-MODEM.img bs=4096
dd if=/dev/block/mmcblk0p9 of=/sdcard/p9-FACTORYFS.img bs=4096
dd if=/dev/block/mmcblk0p12 of=/sdcard/p12-HIDDEN.img bs=4096
I have tried them using adb shell and they work .
The question is how do i get them now into a .tar/.md5 so that Odin can flash them ?
spoonflames said:
hi sea_salt !
I got the commands from another post:
dd if=/dev/block/mmcblk0p1 of=/sdcard/p1-EFS.img bs=4096
dd if=/dev/block/mmcblk0p4 of=/sdcard/p4-PARAM.img bs=4096
dd if=/dev/block/mmcblk0p5 of=/sdcard/p5-KERNEL.img bs=4096
dd if=/dev/block/mmcblk0p8 of=/sdcard/p8-MODEM.img bs=4096
dd if=/dev/block/mmcblk0p9 of=/sdcard/p9-FACTORYFS.img bs=4096
dd if=/dev/block/mmcblk0p12 of=/sdcard/p12-HIDDEN.img bs=4096
I have tried them using adb shell and they work .
The question is how do i get them now into a .tar/.md5 so that Odin can flash them ?
Click to expand...
Click to collapse
hey this sounds great. thanks for your reply!
Does EFS, PARAM, KERNEL, MODEM, FACTORYFS, HIDDEN contain ALL stuff of the sgs2-phone's-rom and data, so that it can be used to completetely backup the device?
but I suppose that these adb-commands only work when you already have a root-kernel, or not?
are there the same commands to use adb to restore all this stuff?

odin flashable package making

i have heard that a lot of devs are struggling to make an odin flashable package.so i share this tutorial.hope i help you in any way.
make a backup folder in external sdcard
open terminal emulator in phone
in a terminal emulator.run
su
dd if=/dev/block/mmcblk0p14 of=/mnt/extSdCard/backup/mmcblk0p14_system.img bs=4096(for system)
dd if=/dev/block/mmcblk0p18 of=/mnt/extSdCard/backup/mmcblk0p18_recovery.img bs=4096(for recovery)
dd if=/dev/block/mmcblk0p15 of=/mnt/extSdCard/backup/mmcblk0p15_userdata.img bs=4096(for user data)
dd if=/dev/block/mmcblk0p17 of=/mnt/extSdCard/backup/mmcblk0p17_cache.img bs=4096(for cache)
dd if=/dev/block/mmcblk0p7 of=/mnt/extSdCard/backup/mmcblk0p7_boot.img bs=4096(for kernel)
now copy all these files in a your computer and open a linux command line
tar -H ustar -c "INSERT_.IMG FILE HERE" mmcblk0p14_system.img > package_name.tar
md5sum -t package_name.tar >> package_name.tar
mv package_name.tar package_name.tar.md5
Add any combination of image files you want after the "-c" and before the ">"
Make sure each .IMG file has a space between the next one.
best of luck
credits
das7982
darky
Anybody found it useful?
press thankks if you like my work
Tryin'
Edit : oh no my computer broken
?
press thankks if you like my work

[Q] Need urgent help with adb fastboot nandroid backup (paid assistance)

Hi,
I have idea like "backup all data (include apps, accounts, system settings) -> wipe all data -> upload backup -> start device", but backup upload on server by ftp/sftp.
After few times another script download necessary backup and upload on phone by adb/fastboot and start device.
Now i create backup by this script (sorry, i`m only learn)
Code:
adb wait-for-device
set dirname=%date:~0,2%%date:~3,2%%date:~8,2%%time:~0,2%%time:~3,2%
mkdir %dirname% > NULL
adb shell su -c "dd if=/$(ls -la /dev/block/platform/msm_sdcc.1/by-name | grep system | sed -r 's/.* .//') of=/sdcard/blkbackup.img"
adb pull /sdcard/blkbackup.img %dirname%\system.img
adb shell rm /sdcard/blkbackup.img
adb shell su -c "dd if=/$(ls -la /dev/block/platform/msm_sdcc.1/by-name | grep boot | sed -r 's/.* .//') of=/sdcard/blkbackup.img"
adb pull /sdcard/blkbackup.img %dirname%\boot.img
adb shell rm /sdcard/blkbackup.img
adb shell su -c "dd if=/$(ls -la /dev/block/platform/msm_sdcc.1/by-name | grep recovery | sed -r 's/.* .//') of=/sdcard/blkbackup.img"
adb pull /sdcard/blkbackup.img %dirname%\recovery.img
adb shell rm /sdcard/blkbackup.img
adb shell su -c "dd if=/$(ls -la /dev/block/platform/msm_sdcc.1/by-name | grep cache | sed -r 's/.* .//') of=/sdcard/blkbackup.img"
adb pull /sdcard/blkbackup.img %dirname%\cache.img
adb shell rm /sdcard/blkbackup.img
adb shell su -c "dd if=/$(ls -la /dev/block/platform/msm_sdcc.1/by-name | grep userdata | sed -r 's/.* .//') of=/sdcard/blkbackup.img"
adb pull /sdcard/blkbackup.img %dirname%\userdata.img
adb shell rm /sdcard/blkbackup.img
adb shell "pm list package -s" > %dirname%\system.apps.list
adb shell "pm list package -3" > %dirname%\3d-party.apps.list
i think what this logicaly work, but in realy - dont work and i cant upload backup in server.
can you explain me how i can create fully backup android device and restore it adter few days in device by shellscript.
In an ideal world I see it this way:
1) made a backup using http://forum.xda-developers.com/showthread.php?t=1620255
2) loading on server
3) another script download the desired backup and load it on your phone or PC
4) install
4.1) profit
PS Since I need it urgently enough and I tried huge amount of scripts and commands - asking for your help (in debt will not stay).
PPS ubuntu
Skype: a.roman2403

tarball over adb exec-in without temporary files

I'm looking for a way to transfer files with the correct permissions over adb. I can create a tarball and push it to my phone on the fly but for some reason I can't extract it without creating a temporary file. What I mean is that
Code:
tar -c file | adb exec-in 'cat > /file.tar' && adb shell 'tar -xf /file.tar -C dir'
works but
Code:
tar -c file | adb exec-in 'tar -xf - -C dir'
doesn't. Actually, it does but not all files are transferred over. Am I missing out on something?
@Ciren__
adb exec-out and/or adb exec-in
writes/reads to/from only files
I've used this:
Bash:
tar czplf - --acls --selinux --xattrs --numeric-owner -C /mnt/tmp/ data/com.android.messaging | adb exec-in tar -f - -x -p -z -v -C /data
... to restore an app from a whole partition image backup (mounted with `kpartx` and `mount -t ext4 -o ro,noload`).
I'm not sure if all those flags are actually needed, but that was my first guess at something which I thought would work.

Categories

Resources