Home » #Technology » Mastering Android Backup and Restore on Windows with ADB

Mastering Android Backup and Restore on Windows with ADB

As a tech enthusiast or developer, efficiently managing your Android devices is crucial. As developer on windows pc, on can too Leveraging the power of the Batch scripts along with Android Debug Bridge (ADB) provides powerful tools for deep control over your device’s operations. Previously I wrote taking backup on Linux and Mac, In this tech blog post, we’ll look into straightforward process to back up and restore your Android apps and data using ADB on a Windows PC, ensuring a seamless transfer from one device to another. ADB is an indispensable command-line tool that allows you to interact with your device, providing capabilities far beyond what the standard user interface can achieve.

Prerequisites

Before we dive into the script and commands, let’s assume you have ADB installed on your Windows machine. If not, you can check out my previous tech blog post for installation instructions and necessary commands. Additionally, make sure to enable USB debugging on both your Android devices:

  1. Open Settings.
  2. Navigate to About phone.
  3. Tap Build number seven times to enable Developer options.
  4. Go back to the main Settings menu and select Developer options.
  5. Enable USB debugging.

Backup and Restore Script for Windows

Here’s a comprehensive batch script (backup_restore.bat) to automate the backup and restore process on your Windows PC:

@echo off
setlocal

REM Check if adb is installed
if not exist "platform-tools\adb.exe" (
    echo ADB is not installed. Please install ADB and try again.
    pause
    exit /b
)

REM List connected devices
echo Checking connected devices...
platform-tools\adb.exe devices

REM Ask for source and target device serial numbers
set /p source_device=Enter the serial number of the source device (the device you want to backup from): 
set /p target_device=Enter the serial number of the target device (the device you want to restore to): 

REM Backup APKs and data from source device
echo Backing up APKs and data from the source device...
mkdir backup
platform-tools\adb.exe -s %source_device% backup -apk -all -f backup\backup.ab

REM Restore APKs and data to target device
echo Restoring APKs and data to the target device...
platform-tools\adb.exe -s %target_device% restore backup\backup.ab

REM Cleanup
echo Cleaning up...
rd /s /q backup

echo Backup and restore process completed successfully.
pause
endlocal

Steps to Run the Script

  1. Download and Extract ADB:
  2. Create the Batch Script:
    • Open Notepad or any text editor.
    • Copy and paste the above script into the text editor.
    • Save the file with a .bat extension, for example, backup_restore.bat.
  3. Move the Script to ADB Directory:
    • Move the backup_restore.bat file to the directory where adb.exe is located (e.g., C:\adb).
  4. Run the Script:
    • Open Command Prompt as an administrator.
    • Navigate to the directory where adb.exe is located (e.g., cd C:\adb).
    • Run the script by typing backup_restore.bat and pressing Enter.

Detailed Explanation

  • ADB Installation Check: The script first checks if adb.exe exists in the specified directory.
  • Device Connectivity: It lists connected devices and prompts you to enter the serial numbers of the source (backup from) and target (restore to) devices.
  • Backup Process: The script uses adb backup to create a backup file that includes both APKs and app data from the source device.
  • Restore Process: It then uses adb restore to transfer the backup to the target device.
  • Cleanup: Finally, the script cleans up by removing the backup files from your computer.

Most development in the tech industry is done on Windows machines due to their cost-effectiveness and user-friendly experience. As a developer, using the command line is essential to accelerate the development process. ADB, coupled with command line batch scripts, offers a powerful tool that provides extensive control over your Android devices. By mastering these commands and scripts, you can streamline your workflow, troubleshoot issues, and fully leverage your device’s capabilities. Happy debugging!

#AskDushyant
#ADB #DeveloperTools #CommandLine #MobileDevelopment #AppDevelopment #Debugging #Programming #Windows
Note: The scripts shared is been tested on our development machine but may required necessary changes as per command terminal used.

Leave a Reply

Your email address will not be published. Required fields are marked *