My Tech Scrap
Flipkart.com

Translate

Share |

Tuesday, 16 September 2025

📱 Backing Up My Redmi Phone with PowerShell + ADB: A Journey

Like many of us, I rely heavily on my phone — photos, downloads, documents, and a random mix of files I probably should’ve organized months ago. One day, I decided it was time to back everything up from my Redmi 9 Prime to my PC. I thought: “Easy. Just use PowerShell and Robocopy.”

That’s when reality hit me.


❌ The First Roadblock: MTP Isn’t a Real Drive

When you plug in an Android phone over USB, Windows shows it in This PC as:

This PC\Redmi 9 Prime\Internal shared storage

Looks like a normal path, right? But try to script it and… nope.
MTP (Media Transfer Protocol) isn’t a normal file system, so neither PowerShell’s Get-ChildItem nor robocopy could see it.

I needed a different approach.


🔑 Enter ADB (Android Debug Bridge)

ADB is a developer tool from Google that lets your computer talk directly to your Android device. With it, I could copy files reliably and even automate backups.

Here’s how I set it up:

  1. Downloaded Platform Tools and extracted to C:\platform-tools.

  2. Added that folder to my PATH.

  3. Enabled Developer Options → USB Debugging on my Redmi.

  4. Ran:

adb devices

At first, it showed:

hdshdsdhshd unauthorized

The phone was waiting for me to approve the connection. A quick tap on “Allow USB debugging” fixed it, and finally:

hdshdsdhshd device

Success! 🎉


🛠️ Writing the PowerShell Script

Now I needed a script that would:

  • Copy all internal storage folders.

  • Copy external SD card storage (if present).

  • Log the status of each root folder as COMPLETE or FAILED.

Here’s the final version I came up with:

param( [string]$Destination = "E:\PhoneBackup", [string]$LogFile = "E:\PhoneBackup\BackupLog.txt" ) if (!(Test-Path $Destination)) { New-Item -ItemType Directory -Path $Destination -Force | Out-Null } "Backup started: $(Get-Date)" | Out-File -FilePath $LogFile -Encoding UTF8 # -------- INTERNAL STORAGE (/sdcard) -------- $internalFolders = adb shell "ls /sdcard/" | ForEach-Object { $_.Trim() } foreach ($folder in $internalFolders) { $src = "/sdcard/$folder" $dst = Join-Path $Destination "Internal_$folder" "Backing up [INTERNAL][$folder]..." | Tee-Object -FilePath $LogFile -Append adb pull $src $dst | Out-Null if ($LASTEXITCODE -eq 0) { Add-Content $LogFile "STATUS: [INTERNAL][$folder] COMPLETE at $(Get-Date)" } else { Add-Content $LogFile "STATUS: [INTERNAL][$folder] FAILED (exit code $LASTEXITCODE) at $(Get-Date)" } } # -------- EXTERNAL STORAGE (/storage/XXXX-XXXX) -------- $externalMounts = adb shell "ls /storage" | ForEach-Object { $_.Trim() } | Where-Object { $_ -match '^[0-9A-Fa-f-]+$' } foreach ($mount in $externalMounts) { $basePath = "/storage/$mount" $externalFolders = adb shell "ls $basePath" | ForEach-Object { $_.Trim() } foreach ($folder in $externalFolders) { $src = "$basePath/$folder" $dst = Join-Path $Destination "External_${mount}_$folder" "Backing up [EXTERNAL][$mount][$folder]..." | Tee-Object -FilePath $LogFile -Append adb pull $src $dst | Out-Null if ($LASTEXITCODE -eq 0) { Add-Content $LogFile "STATUS: [EXTERNAL][$mount][$folder] COMPLETE at $(Get-Date)" } else { Add-Content $LogFile "STATUS: [EXTERNAL][$mount][$folder] FAILED (exit code $LASTEXITCODE) at $(Get-Date)" } } } "Backup finished: $(Get-Date)" | Add-Content $LogFile

📋 Example Log Output

After running the script, the log looked like this:

Backup started: 09/17/2025 12:00:12 Backing up [INTERNAL][DCIM]... STATUS: [INTERNAL][DCIM] COMPLETE at 09/17/2025 12:05:10 Backing up [INTERNAL][Download]... STATUS: [INTERNAL][Download] COMPLETE at 09/17/2025 12:07:02 Backing up [EXTERNAL][1234-5678][Music]... STATUS: [EXTERNAL][1234-5678][Music] COMPLETE at 09/17/2025 12:09:15 Backup finished: 09/17/2025 12:10:00

That was exactly what I needed: a per-folder backup status I could trust.


🎯 Final Thoughts

Backing up an Android phone via USB isn’t as straightforward as copying from a hard drive, but with ADB and a bit of PowerShell, it’s totally doable.

This setup now gives me peace of mind - my Redmi’s internal and external storage are mirrored onto my PC with logs to prove it.