[Moto G General] eastdata:
Hello,

Here are a couple of scripts to backup and restore the device IMEI. They won't help with a lost IMEI. Use them to backup your pds partition that store all the device specific data just in case they are lost. They should also be compatible with any device that has the same partitioning as our Moto G (eg Moto X).

Requirements:

- Device has to be rooted, with USB debugging enabled.

- Motorola fastboot (see attachment).

- ADB installed, minimal or the full ADK.

You can search the forum to find how to meet these requirements or for the terms described in this post beginning here:

http://xdaforums.com/showthread.php?t=2558638

Installation:

Extract imei_scripts.zip (attached) and copy the scripts "imei_backup.bat" and "imei_flash.bat" into the ADB root directory.

Extract mfastboot_only.zip (attached) and copy "mfastboot.exe" into the ADB root directory.

Description/How to use:

These are batch scripts and can be run by double-clicking them or opening a command window from the ADB root. Help is also contained in the scripts. They are run interactively and won't execute anything without the user selecting a choice.

"imei_backup.bat"

Use this script to backup and restore normally using ADB.

"imei_flash.bat"

Use this script to flash the partition as an alternative to the other method using mfastboot while in bootloader mode. The backup, "pds.img" must be located in the ADB directory for the script to run.

The backup is made on the sdcard and is named "pds.img". You'll want to store this elsewhere once backed up. Once done, that's it! You don't need to do anything more. The purpose is as a preventative in the event of the loss of your IMEI. :)

Run the scripts for additional options and help.:angel:

The contents of "imei_backup.bat" (use this script to backup and restore IMEI):

@ECHO OFF

:: 2014-03-09 script by eastdata @ XDA

:: run script from ADB root
IF NOT EXIST adb.exe (
ECHO.
ECHO This script must be run in the ADB root directory.
ECHO.
PAUSE
EXIT /B 0
)

:: set path
SET PATH=.;%PATH%
:: unset android serial if set by dev
SET ANDROID_SERIAL=

:options
CLS
ECHO.
ECHO Moto G and compatible IMEI backup/restore script
ECHO.
ECHO The device must have root permissions to perform the backup/restore functions in this script (su). USB debugging must be enabled. The backup must be in the sdcard root for restore.
ECHO.
ECHO The backup will be created in the sdcard directory as "pds.img". The backup can be copied to/from the ADB directory using the script file functions. Use with caution, you won't be prompted again if you choose to restore the pds partition. Store the backup securely either locally or online for later recovery.
ECHO.
ECHO DISCLAIMER: Use this script only at your own risk!
ECHO.
ECHO Options:-
ECHO.
ECHO backup:
ECHO b - backup pds partition
ECHO.
ECHO restore:
ECHO r - restore pds partition
ECHO.
ECHO file functions:
ECHO p - copy backup from sdcard to pc
ECHO s - copy backup from pc to sdcard
ECHO d - delete backup from sdcard
ECHO.
ECHO other:
ECHO q - quit
ECHO.
SET /P option="Select an option [b|r|p|s|d|q]: "
ECHO.

SET bad_option=1

:: backup to sdcard
IF /I "%option%" == "b" (
ECHO Performing backup...
adb shell su -c "dd if=/dev/block/platform/msm_sdcc.1/by-name/pds of=/sdcard/pds.img"
GOTO :proc_end
)

:: restore from sdcard
IF /I "%option%" == "r" (
ECHO Performing restore...
adb shell su -c "dd if=/sdcard/pds.img of=/dev/block/platform/msm_sdcc.1/by-name/pds"
GOTO :proc_end
)

:: copy to pc (pull)
IF /I "%option%" == "p" (
ECHO Performing copy to pc...
adb pull /sdcard/pds.img
GOTO :proc_end
)

:: copy to sdcard (push)
IF /I "%option%" == "s" (
ECHO Performing copy to sdcard...
adb push pds.img /sdcard/pds.img
GOTO :proc_end
)

:: delete from sdcard (rm)
IF /I "%option%" == "d" (
ECHO Performing delete from sdcard...
adb shell rm /sdcard/pds.img
GOTO :proc_end
)

:: quit script
IF /I "%option%" == "q" (
EXIT /B 0
)

:: bad option
IF %bad_option% == 1 (
ECHO Bad option.
GOTO :proc_end
)

:proc_end
ECHO.
PAUSE
GOTO :options

The contents of "imei_flash.bat" (alternative to restore IMEI using mfastboot):

@ECHO OFF

:: 2014-03-09 script by eastdata @ XDA

:: run script from ADB root
IF NOT EXIST adb.exe (
ECHO.
ECHO This script must be run in the ADB root directory.
ECHO.
PAUSE
EXIT /B 0
)

:: require Motorola fastboot
IF NOT EXIST mfastboot.exe (
ECHO.
ECHO This script requires Motorola fastboot renamed "mfastboot.exe" in the ADB directory.
ECHO.
PAUSE
EXIT /B 0
)

:: is there an existing backup?
IF NOT EXIST pds.img (
ECHO.
ECHO Backup file "pds.img" not found in the ADB directory.
ECHO.
PAUSE
EXIT /B 0
)

:: set path
SET PATH=.;%PATH%
:: unset android serial if set by dev
SET ANDROID_SERIAL=

:options
CLS
ECHO.
ECHO Moto G and compatible IMEI flash script
ECHO.
ECHO The device must be in bootloader mode to flash the pds partition. Use the device functions to reboot into the bootloader. Use with caution, you won't be prompted again if you choose to flash the pds partition.
ECHO.
ECHO DISCLAIMER: Use this script only at your own risk!
ECHO.
ECHO Options:-
ECHO.
ECHO flash:
ECHO f - flash pds partition
ECHO.
ECHO device functions:
ECHO b - reboot into bootloader (adb)
ECHO r - reboot (mfastboot)
ECHO.
ECHO other:
ECHO q - quit
ECHO.
SET /P option="Select an option [f|b|r|q]: "
ECHO.

SET bad_option=1

:: flash partition
IF /I "%option%" == "f" (

FOR /F "usebackq tokens=1" %%C in (`mfastboot devices ^| find /C "fastboot"`) DO (

IF %%C% EQU 1 (
ECHO Performing flash...
mfastboot flash pds pds.img
) ELSE (
ECHO Device not found or too many devices, reboot device into bootloader or disconnect any other devices.
)

)

GOTO :proc_end
)

:: reboot bootloader
IF /I "%option%" == "b" (
ECHO Performing reboot into bootloader, please wait for the device to become ready...
adb reboot-bootloader
GOTO :proc_end
)

:: reboot
IF /I "%option%" == "r" (
ECHO Performing reboot, please wait for the device to become ready...
mfastboot reboot
GOTO :proc_end
)

:: quit script
IF /I "%option%" == "q" (
EXIT /B 0
)

:: bad option
IF %bad_option% == 1 (
ECHO Bad option.
GOTO :proc_end
)

:proc_end
ECHO.
PAUSE
GOTO :options

DISCLAIMER: I've tried to make the scripts foolproof, but in the event that you lose data or they corrupt/break your phone, I won't be held responsible. That is, use only at your own risk!