Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,733,372 Members 39,325 Now Online
XDA Developers Android and Mobile Development Forum

[SCRIPTS] IMEI backup/restore scripts (pds partition)

Tip us?
 
eastdata
Old
#1  
Senior Member - OP
Thanks Meter 28
Posts: 108
Join Date: Apr 2011
Default [SCRIPTS] IMEI backup/restore scripts (pds partition)

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://forum.xda-developers.com/show....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.

The contents of "imei_backup.bat" (use this script to backup and restore IMEI):
 
Code:
@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):
 
Code:
@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!
Attached Files
File Type: zip imei_scripts.zip - [Click for QR Code] (2.0 KB, 318 views)
File Type: zip mfastboot_only.zip - [Click for QR Code] (219.3 KB, 184 views)
The Following 7 Users Say Thank You to eastdata For This Useful Post: [ Click to Expand ]
 
RestlessScreams
Old
#2  
RestlessScreams's Avatar
Senior Member
Thanks Meter 69
Posts: 215
Join Date: Oct 2012
Did someone find a way to read the IMEI in the pds file?
 
eastdata
Old
#3  
Senior Member - OP
Thanks Meter 28
Posts: 108
Join Date: Apr 2011
I'm not aware that anyone has.
 
sheraz1015
Old
#4  
Senior Member
Thanks Meter 22
Posts: 190
Join Date: Jun 2012
Thumbs up Thanks man

Quote:
Originally Posted by eastdata View Post
I'm not aware that anyone has.

Thanks man , ur imei script works like a charm . backed up my imei using ur tool sucessfully .
Great work . keep it up
 
Jerome-X
Old
#5  
Jerome-X's Avatar
Senior Member
Thanks Meter 140
Posts: 105
Join Date: Aug 2007
Location: Invaders must DIE!
backup yes, restore my IMEI, no way... any ideas left?
fastboot shows the correct IMEI, system not = 0

QUICK HELP IS NEEDED! Thanks guys
JX!
 
denzel09
Old
#6  
denzel09's Avatar
Senior Member
Thanks Meter 667
Posts: 3,210
Join Date: Jun 2009
Location: Venezia
Quote:
Originally Posted by Jerome-X View Post
backup yes, restore my IMEI, no way... any ideas left?
fastboot shows the correct IMEI, system not = 0

QUICK HELP IS NEEDED! Thanks guys
JX!
There is not a real working solution atm
 
rgonera
Old
#7  
Junior Member
Thanks Meter 1
Posts: 7
Join Date: Mar 2014
Quote:
Originally Posted by eastdata View Post
Hello,
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!
What happens if you restore your imei with a different file from the origin of our phone ?
 
mokkami
Old
#8  
mokkami's Avatar
Senior Member
Thanks Meter 85
Posts: 403
Join Date: Dec 2009
Location: Pune (IN), Düsseldorf (DE)
Do we actually have a reason now, why people are loosing their pds partition?

Sent from my Commodore 16 using NSA's satellite dish
..................pls hit Thanks button if anyone helped you!
 
denzel09
Old
#9  
denzel09's Avatar
Senior Member
Thanks Meter 667
Posts: 3,210
Join Date: Jun 2009
Location: Venezia
Quote:
Originally Posted by mokkami View Post
Do we actually have a reason now, why people are loosing their pds partition?
Not yet. Still we dont know the exactly cause.
 
Alkalinorap
Old
#10  
Junior Member
Thanks Meter 1
Posts: 13
Join Date: Jun 2012
Thanks man.

Tags
imei backup, partition, pds, restore, script
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

LG G Watch Tool is a Toolkit all Owners Need

The LG G Watch is one of the first two devices hitting the market rocking the highly anticipated … more

Benchmark Your CPU Performance with Mini CPU Integer Script

When it comes to device testing, there are two types of people on XDA. The first … more

Rid Yourself of Charging Annoyances with No Wake on Charge Xposed Module

Almost every OEM has skinned and otherwise modifiedAndroid to suit … more