[Moto G4 Plus Guides, News, & Discussion] HeethJain21:
#include <disclaimer.h>
/*
* Your warranty is now.......(wait a minute)........still valid?
*
* I am not responsible for bricked devices.
* YOU are choosing to make these modifications, and if you point
* your finger at me for messing up your device, I will laugh at you.
*/

As we know that on flashing ROMs/kernels/other mods, we sometimes do some mistake or face some issues so it is always recommended to take backup.

But unfortunately, TWRP does not takes backup of all the partitions.

When you open/dev/block/bootdevice/by-name/ you can see the names of the partitions and there are a total of 48 partitions. Of course not every one of them is important to back up, but it's better to be safe than sorry.

This method has been tested on my Moto G4 Plus (XT1643) and all the parts are work on it (backup and restore both using zip file and batch file)

Here is the list to all those partitions along with their number/id (maybe that's what its called, please correct me if there's any mistake)

Number/ID Name

mmcblk0p1	modem
mmcblk0p2	fsc
mmcblk0p3	ssd
mmcblk0p4	sbl1

mmcblk0p5	sbl1bak
mmcblk0p6	rpm
mmcblk0p7	rpmbak
mmcblk0p8	tz

mmcblk0p9	tzbak
mmcblk0p10	hyp
mmcblk0p11	hypbak
mmcblk0p12	dsp

mmcblk0p13	modemst1
mmcblk0p14	modemst2
mmcblk0p15	DDR
mmcblk0p16	fsg

mmcblk0p17	sec
mmcblk0p18	aboot
mmcblk0p19	abootbak
mmcblk0p20	logs

mmcblk0p21	utags
mmcblk0p22	utagsBackup
mmcblk0p23	cid
mmcblk0p24	logo

mmcblk0p25	clogo
mmcblk0p26	metadata
mmcblk0p27	kpan
mmcblk0p28	boot

mmcblk0p29	recovery
mmcblk0p30	persist
mmcblk0p31	misc
mmcblk0p32	config

mmcblk0p33	limits
mmcblk0p34	mota
mmcblk0p35	devcfg
mmcblk0p36	dip

mmcblk0p37	syscfg
mmcblk0p38	cmnlib
mmcblk0p39	keymaster
mmcblk0p40	frp

mmcblk0p41	padC
mmcblk0p42	sp
mmcblk0p43	hw
mmcblk0p44	customize

mmcblk0p45	oem
mmcblk0p46	cache
mmcblk0p47	system
mmcblk0p48	userdata

modemst1 and modemst2 are your EFS (the IMEI which you see in settings). When we flash Stock ROM, we erase them with fastboot erase commands but they are regenerated with the help of persist, so never ever restore somebody else's persist on your device and always keep a backup of modemst1, modemst2 a.k.a EFS and persist.

[MENTION=8274594]givitago[/MENTION] has already made a backup script for all the partitions which can be found here: Complete Partition Backup Script, so huge thanx to him!

Q) So why create another thread?

A) Frankly speaking, this thread does the same work as the above-mentioned thread, but it also talks about restoring the backup.

Also, now you can back up the partitions with a TWRP flashable zip file and restore them too with a TWRP flashable zip too!

The backup and restore will be done using dd commands.

Those who are unaware of dd commands, it is generally used for converting files.

Here is the syntax for dd command (I have used colors so that it is easy to differentiate them):

[COLOR="Green"]su
dd[/COLOR] [COLOR="Blue"]if=/directoryName/fileName[SIZE="4"].[/SIZE]fileExtension[/COLOR] [COLOR="DeepSkyBlue"]of=/yourDirectoryName/yourFileName[SIZE="4"].[/SIZE]yourFileExtension[/COLOR]

directoryName is the generic name of the directory where the file (which we want to access) is present.

fileName is the generic name of the file which we want to access.

fileExtension is the generic file extension of the file which we want to access.

yourDirectoryName is the generic name of the directory where we will store the file.

yourFileName is the generic name of the file which we will store as backup.

yourFileExtension is the generic file extension of the file which we are taking a backup of.

And lastly, su because we will run these commands under root permissions.

This thread is divided into 2 parts, backup and restore.

We will be using .img extension for the backed up partitions.

Pre-requisites:

You must be on latest Stock ROM

You must be rooted (install Elemental-X kernel first and then flash Magisk otherwise you will have boot issues)

Terminal app or adb drivers in PC/Laptop

Official TWRP only (if you use adb in TWRP)

Note: The below commands are to be typed in a terminal app or adb shell.

Q) How to type in adb shell?

A) Open command prompt in the folder where you have adb and fastboot installed and type:

adb shell

su

This command it to get root access for the terminal/shell. Grant the root access and you will see that the $ symbol is replaced with# symbol which means that root access has been granted.

You can skip this command if you are using TWRP (although then you wouldn't be able to backup build.prop)

Note: The flashable zip files are attached as well as their link has been given. The rar files are the ones which contain the commands for backup/restore and also contains the batch file.

Its been a while since I have moved on to a newer device, and not remember quite a few things about the device. Here is something important to note:

This method won't backup/restore system, userdata and cache as they take up too much space and are reset on flashing Stock ROM again.