[General Questions and Answers] xXx yYy:
[2024-02-03] EDIT: The solutions shown below do not work on phones running Android 11 or higher!

Use ADB to backup / restore a phone's user apps and their data: ADB backup does not require root access. This means that you can back up your user apps and data without having to unlock your device's bootloader or root it. This is a major advantage of using ADB backup over other backup methods that require root access. However, you may not be able to back up all of the data from some apps.

Backing up a device :

adb devices
adb backup -apk -shared -all -f C:\backup.ab

This will create a backup file named "backup.ab" on your PC. This backup file will include all of your user apps and their data.

Restoring the backup to the destination device:

adb devices
adb restore C:\backup.ab

This will restore your user apps and data from the backup file to your target Android device.

EDIT:

Here is a Powershell 5 script that is backing up all user-app's APK file, its data and its .OBB -files via ADB:

# Set backup directory
$BACKUP_DIR = "C:\path\to\backup" # Replace with your desired path
# Set ADB executable
$ADB = "C:\ADB\adb.exe"
# Test presence of adb.exe
if (-not (Test-Path $ADB)) {
$text = "ADB executable on defined location not present."
Write-Host "$text"
Write-Host " "
Start-Sleep -Second 10
exit 1 #error
}
# Check if a device is connected
$devices = (& $ADB devices | Select-String -Pattern '[a-zA-Z0-9-] + device(s) connected')
if (-not $devices.Contains("device")) {
$text = "No connected devices found."
Write-Host "$text"
Write-Host " "
Start-Sleep -Second 10
exit 1 #error
}
Write-Host "Backing up ..."
# Create necessary directories
New-Item -ItemType Directory -Path "$BACKUP_DIR\data", "$BACKUP_DIR\obb", "$BACKUP_DIR\apk" -Force
# Get list of installed packages
$packages = (& $ADB shell "pm list packages -f ")
# Loop through packages
foreach ($pkg in $packages) {
# Extract package name
$name = $pkg.Split("=")[0]
# Check if data directory exists
if (& $ADB shell "test -d /data/data/$name") {
# Copy data directory
$ret = (& $ADB pull /data/data/$name "$BACKUP_DIR\data\$name"| Out-Null)
}
# Check if OBB directory exists
if (& $ADB shell "test -d /sdcard/Android/obb/$name") {
# Copy OBB directory
$ret = (& $ADB pull /sdcard/Android/obb/$name "$BACKUP_DIR\obb\$name" | Out-Null)
}
# Check if APK file exists
if (& $ADB shell "test -f /data/app/$name-*.apk") {
# Copy APK file
$ret = (& $ADB pull /data/app/$name-*.apk "$BACKUP_DIR\apk\$name.apk" | Out-Null)
}
}
Write-Host "Backup complete. Data, OBB, and APK files in $BACKUP_DIR"
Write-Host " "
Start-Sleep -Second 10
exit 0 # success

Here is a Powershell 5 script that is restoring all user-app's APK file, its data and its .OBB -files via ADB backed up with script printed above:

# Set backup directory
$BACKUP_DIR = "C:\path\to\backup"
# Set ADB executable
$ADB = "C:\ADB\adb.exe"
# Test presence of adb.exe
if (-not (Test-Path $ADB)) {
$text = "ADB executable on defined location not present."
Write-Host "$text"
Write-Host " "
Start-Sleep -Second 10
exit 1 #error
}
# Check if a device is connected
$devices = (& $ADB devices | Select-String -Pattern '[a-zA-Z0-9-] + device(s) connected')
if (-not $devices.Contains("device")) {
$text = "No connected devices found."
Write-Host "$text"
Write-Host " "
Start-Sleep -Second 10
exit 1 #error
}
Write-Host "Restoring ..."
# Restore data directories
Get-ChildItem -Path "$BACKUP_DIR\data" -Directory | ForEach-Object {
$name = $_.Name
$ret = (& $ADB shell mkdir -p "/data/data/$name")
$ret = (& $ADB push -r $_.FullName "/data/data/$name | Out-Null")
}
# Restore OBB directories
Get-ChildItem -Path "$BACKUP_DIR\obb" -Directory | ForEach-Object {
$name = $_.Name
$ret = (& $ADB shell mkdir -p "/sdcard/Android/obb/$name")
$ret = (& $ADB push -r $_.FullName "/sdcard/Android/obb/$name" | Out-Null)
}
# Restore APK files
Get-ChildItem -Path "$BACKUP_DIR\apk" -Filter *.apk | ForEach-Object
{
$name = $_.BaseName
$ret = (& $ADB push $_.FullName "/data/app/$name" | Out-Null)
}
Write-Host "Data, OBB, and APK files restored from $BACKUP_DIR"
Write-Host " "
Start-Sleep -Second 10
exit 0 # success