When you switch phones, perform a factory reset, or simply want a safety net, a full device backup is essential. The built‑in adb backup command can capture apps, app data, and shared storage without rooting. However, the raw .ab file is stored in clear text on your computer, which is a privacy risk if the backup falls into the wrong hands. Adding a password encrypts the file, turning it into a secure vault that only you can open.
Take a quick full backup of the computer or copy the backup file to an external drive after you finish. Encrypted backups are safe, but a corrupted file is unrecoverable.
Plug the phone into the computer. Open a terminal (or Command Prompt) and run:
adb devices
You should see a line with your device serial number and the word device. If it says unauthorized, check the phone for a dialog asking to allow USB debugging and tap Allow.
The adb backup command accepts several flags:
-apk – include the APK files of installed apps.-shared – include files from the shared storage (photos, downloads, etc.).-all – back up all user apps; combine with -system to include system apps (rarely needed).-nosystem – explicitly exclude system apps (default for most users).For a typical personal backup we recommend:
-apk -shared -all -nosystem
Enter the following, replacing mybackup.ab with a name you’ll recognize:
adb backup -apk -shared -all -nosystem -f mybackup.ab
Immediately after you press Enter, the phone will display a prompt:
"Backup password (optional)" – type a strong password, then confirm it.
Do NOT leave the password field blank; an empty password creates an unencrypted backup.
When the backup finishes, the terminal will return to the prompt and the phone will show a Backup complete toast.
On your computer, run:
ls -lh mybackup.ab
The size should roughly match the amount of data you selected. If the file is suspiciously tiny (< 1 MB), the backup likely failed – repeat the process and watch the phone for any error dialogs.
Even an encrypted backup can become corrupted during transfer. A quick integrity check saves you from a painful restore later.
Run the following to display the first few bytes of the file:
head -c 12 mybackup.ab | hexdump -C
You should see the ASCII string ANDROID BACKUP followed by the version number (e.g., 01). If the output is garbled, the file is not a valid ADB backup.
If you want to be absolutely sure the password works, attempt a quick extract (see the next section). The decryption step will prompt for the same password you set earlier.
The .ab format is a custom Android container. Converting it to a standard .tar lets you peek inside without restoring the whole device.
Run:
dd if=mybackup.ab bs=24 skip=1 of=backup.tar
This strips the 24‑byte header that adb adds.
Use OpenSSL to decrypt:
openssl aes-256-cbc -d -in backup.tar -out backup_decrypted.tar -pass pass:YOUR_PASSWORD
Replace YOUR_PASSWORD with the exact password you entered on the phone. The command will produce backup_decrypted.tar if the password matches.
Now you can list the archive without extracting:
tar -tf backup_decrypted.tar | head
You should see directories like apps/, shared/, and system/. This confirms the backup captured the expected data.
If the OpenSSL step fails with “bad decrypt”, double‑check the password and ensure you used the exact same case and symbols.
Restoring follows the same command line pattern, but you must be careful not to overwrite data unintentionally.
Same as step 1 of the backup process: adb devices should list your phone.
Run:
adb restore -f mybackup.ab
The phone will display a prompt asking for the backup password. Enter the same password you used when creating the backup.
A progress bar appears on the phone. Do not disconnect the cable until the toast says “Restore complete”.
After a restore, Android may show some apps as “disabled” because the system is still processing the restored data. Open Settings > Apps, locate any disabled apps, and tap “Enable”.
adb pull for specific folders or a third‑party solution like TWRP (requires unlocking the bootloader).-shared will skip all media files, which can make the backup appear tiny. Re‑run with the full flag set.-d (decrypt) flag and that the backup.tar you passed is the one produced by dd. Also verify that the bs value (24) matches the header size for your Android version (some OEMs use 28 bytes).While ADB backup is convenient, it has limitations:
-system, which may cause compatibility issues on restore.For a truly complete image, consider flashing a custom recovery (TWRP) and making a NANDroid backup – but that requires an unlocked bootloader and is outside the scope of a no‑root tutorial.
With the steps above you now have a reliable, password‑protected backup of your Android device that you can store safely, verify at any time, and restore whenever you need. Keep the backup file in an encrypted cloud folder or on an external drive, and you’ll avoid the dreaded “I lost all my data” scenario.









