FORUMS
Remove All Ads from XDA

[HOW TO] Fully Backup & Restore Android Device

556 posts
Thanks Meter: 219
 
By mirfatif, Senior Member on 6th May 2017, 07:32 PM
Post Reply Email Thread
NOTE:
I'm not a developer or something even near to that. I'm a newbie and will be, seems so. All information provided here is copied and compiled from different internet sources. This information is according to best of my knowledge and comprehension and is just for curious souls like me who want to understand things in quite simple words.
I have tested this on different devices. I'll not be responsible for any harm to you or your device. It works perfectly for me. You may try it on your own risk.
Encrypted memory may cause problem in backing up and restoring data. So better decrypt it before proceeding. Or the Recovery should support decryption of /data partition.


WHY YOU NEED TO BACKUP YOUR DATA
  • For security, in case if device is lost. Read here more about the risks.
  • If you are going to change your device.
  • If your device is running out of memory space.
  • If your device is slowing down or giving random errors and you want a clean start i.e. by factory data reset.
  • If you are upgrading your Factory Firmware or ROM (OS).
  • If you are a curious soul like me and interested in experimenting with device.

WHAT TO BACKUP
Backup is a broad term used in many contexts.

PERSONAL DATA
On an android device, backing up personal data like pictures, music, videos, documents, e-books etc. means backing up Internal Memory (/data/media/) and SD card (if you use one). If you have disabled internal memory (D.I.M), your SD Card would be working as Internal Memory.
Personal data might be created by apps (like Camera, Facebook, WhatsApp etc) or imported from internet or other devices by yourself.

APPS & APPS DATA
If you are upgrading your ROM permanently, you might be interested in backing up your apps and their data as well. So that you don't lose important data and don't have to install apps again. System apps are stored in different folders under /system/ while user apps under /data/.
Apps typically store their data in /data/data/ but it's not a rule. Many apps save / backup their data on Internal Memory and/or SD Card as well. That's why you see folders named 'Android', 'data' etc. on Internal Memory and SD Card. Also, there are numerous folders named after app names. These folders may contain Personal Data as well, created by that certain app.
Contacts and messages are also stored in their default apps' data folder i.e. in /data/data/ and are not usually backed up manually.

OPERATING SYSTEM & APPS & APPS DATA
If you are going to install new ROM temporarily, you may want a complete backup so that you don't have to go through the hassle of installing apps and setting up / personalizing your device again. It usually includes /system, /boot and /data partitions.
OS consists of SYSTEM and BOOT. While user apps & apps data is stored in DATA.

PARTITION IMAGES
From a developer's perspective, one may want to backup the whole device partitions, in case if something goes wrong during experimenting.
Read here more about android partitions.

WHERE TO BACKUP
INTERNAL MEMORY (/sdcard) (/storage/sdcard0) (/data/media/0)
This memory can be used to save data if you are not going to wipe / clean it. A Factory Data Reset usually doesn't wipe this but it can. It depends on the device. Similarly, Recoveries usually don't wipe internal memory but you can manually do so. However, formatting /data would certainly erase internal memory. Formatting might be a part of flashable zip if you are going to install new ROM. Flashing Factory Firmware using flasher will also erase internal memory.

EXTERNAL SD CARD (/external_sd) (/storage/sdcard1)
This is a more safer place to save / backup data because it is not wiped unless done manually or accidentally.

PERSONAL COMPUTER (USB Flash drive or Internal / External Hard Disk)
This is the safest place to keep data with abundant space and the least chances of losing / corrupting data.

ONLINE / CLOUD STORAGE
Some apps, including Google offer backing up your data online and auto-synchronizes it. You should certainly avail this option particularly for sensitive and light weight data like contacts, messages, documents, saved passwords, bookmarks, financial transactions etc. WhatsApp also has a good online backup option. You can use apps like Drive, SMS Backup & Restore, FolderSync, KeepSafe etc. to better utilize this option. But technically, this is a limited option.

HOW TO BACKUP
FILE EXPLORER APPS
You can use a file explorer like ES Explorer or Solid Explorer to manually copy files from, say, Internal Memory to SD Card to back it up.

BACKUP APPS
Some default apps have built-in feature to backup data and settings locally and online e.g. GO-SMS, Tasker etc. You can check apps for this feature.
Also, special backup apps like Titanium Backup can backup almost all of your user and system apps and their data. It can also backup contacts, messages, device settings etc. It can create a flashable zip of backed up data to flash through recovery. However, backups from one ROM may not fully work with other ROM's.

CUSTOM RECOVERY
Backing up data when ROM is running isn't safe. When files are being used by OS, they might not be written / read sometimes. So, a custom recovery is the best option to backup/restore data. Custom recoveries (TWRP/CWM) can backup / restore partitions SYSTEM, BOOT and DATA (excluding internal memory) for sure. Some new recoveries offer backing up more (or all) partitions on device. You can choose where to save backup files i.e. Internal Memory or SD Card. Then you can transfer these files to PC as well.
You can also use recovery's File Explorer to copy Internal Memory to SD Card. However, it's a slower process if you have a large number of files to backup.

PC
You can use PC in multiple ways to backup/restore data within device or from/to PC.
  • First of all, you will often come across different software advertised on net claiming to fully backup your device when connected to PC. They work but are not much useful / reliable according to my experience. Give them a try, if you want to.
  • Secondly, you can use USB cable to directly connect your device (as MTP in ROM or recovery) to PC or use apps like Wi-Fi File Transfer to wirelessly connect (in ROM) and then explore Internal Memory and SD Card. FTP or SFTP (SSH) server may also be setup on Android to remotely access it from PC if both are on same network.
  • Thirdly, you can mount SD Card as flash drive (UMS in ROM) or switch off your device, remove SD Card and then insert directly into PC through card reader to manually copy files. This method is faster, to copy large data. However, mounting as UMS in running ROM isn't recommended, particularly if you are using D.I.M. It will crash apps.
    In Android 5+ UMS may not be available in USB settings as it has been deprecated in favor of MTP to avoid problems. However, to copy large data from internal SD card is really problematic without direct USB connection. Or what if we need to recover accidentally deleted data from internal memory? We can directly attach internal memory (as in UMS) to PC by a little hacking.
  • Fourthly and ultimately, like a boss , you can use life saving ADB feature of android to backup/restore your data as well as recovering your device from difficult situations and doing a lot of stuff. It's the best and fastest method to backup Internal Memory to SD Card and then restore (COPY WHOLE FOLDER (within device)). Or you can COPY WHOLE FOLDER (From/To PC) or COPY WHOLE PARTITION IMAGE (within device) or BACKUP / RESTORE APPS & DATA (From/To PC) in seconds.
    Read here more about android partitions.
The Following 7 Users Say Thank You to mirfatif For This Useful Post: [ View ] Gift mirfatif Ad-Free
 
 
18th August 2017, 09:33 AM |#2  
Junior Member
Thanks Meter: 1
 
More
Another application that you can use to backup your phone to computer is Apowersoft Phone Manager. This works greatly in managing your devices plus it make sure that all your files are secured from being corrupted or loss.
5th September 2017, 11:27 AM |#3  
Junior Member
Thanks Meter: 3
 
More
Quote:
Originally Posted by doublematteo

Another application that you can use to backup your phone to computer is Apowersoft Phone Manager. This works greatly in managing your devices plus it make sure that all your files are secured from being corrupted or loss.

I can't determine the efficiency of the Apowersoft tool, but if you want to backup data , this is right way , after the phone data is backuped ,you don't have to worry about the deleted data unable be recovered back ,
The backup files is the best way to recover deleted data from phone
The Following 2 Users Say Thank You to Oanksser For This Useful Post: [ View ] Gift Oanksser Ad-Free
5th October 2017, 08:30 AM |#4  
Junior Member
Thanks Meter: 3
 
More
Kindly guide me on restoring app data alone from a nandroid to newer version of an app..
The scenario is that ,I upgraded to a higher android OS but find some of my apps(with no cloud storage),restored from my nandroid ,crashing; probably prompted by the change in OS.
I downloaded the compatible version of the app from playstore,but am clueless how to sync restored app data from nandroid to this version.
6th October 2017, 05:31 PM |#5  
OP Senior Member
Flag Toba Tek Singh
Thanks Meter: 219
 
More
Quote:
Originally Posted by DIGVIJAY24

Kindly guide me on restoring app data alone from a nandroid to newer version of an app..
The scenario is that ,I upgraded to a higher android OS but find some of my apps(with no cloud storage),restored from my nandroid ,crashing; probably prompted by the change in OS.
I downloaded the compatible version of the app from playstore,but am clueless how to sync restored app data from nandroid to this version.

Would you please mention apps names? Don't uninstall previous version. Just install compatible version over it. It should automatically have previous app data.
2nd January 2018, 03:34 AM |#6  
Junior Member
Thanks Meter: 0
 
More
The backup program is much simpler than the android recovery program,
4th January 2018, 07:51 PM |#7  
DrPhant0m's Avatar
Senior Member
Thanks Meter: 275
 
More
I came here looking for the best way to back up my internal storage before activities like flashing a new ROM or firmware. Previously, I'd plug my phone into my PC and just drag and drop the internal storage partition to a folder on my computer, but I'd often have to do it a few times because some file would get hung up, or the phone would randomly disconnect (even though my phone, cables, and computer are all new and high quality).

I'm currently using the TWRP file explorer to copy /sdcard to /external-sd/!InternalBackup, but there is no running log or progress indicator... So, this approach is less than ideal.

I'm still looking for the best method (not necessarily a software that will do it for me) that will do it fast, not get interrupted, and provide good feedback on if it's working and how much longer it will take. (The TWRP method above checks the first 2 criteria, but the 3rd is woefully insufficient.

I'm thinking that the best way to back up the internal SD will be in recovery, otherwise something might be in use and will halt the process.

Any suggestions?
5th January 2018, 01:15 PM |#8  
OP Senior Member
Flag Toba Tek Singh
Thanks Meter: 219
 
More
Quote:
Originally Posted by DrPhant0m

I came here looking for the best way to back up my internal storage before activities like flashing a new ROM or firmware. Previously, I'd plug my phone into my PC and just drag and drop the internal storage partition to a folder on my computer, but I'd often have to do it a few times because some file would get hung up, or the phone would randomly disconnect (even though my phone, cables, and computer are all new and high quality).

I'm currently using the TWRP file explorer to copy /sdcard to /external-sd/!InternalBackup, but there is no running log or progress indicator... So, this approach is less than ideal.

I'm still looking for the best method (not necessarily a software that will do it for me) that will do it fast, not get interrupted, and provide good feedback on if it's working and how much longer it will take. (The TWRP method above checks the first 2 criteria, but the 3rd is woefully insufficient.

I'm thinking that the best way to back up the internal SD will be in recovery, otherwise something might be in use and will halt the process.

Any suggestions?

Commandline solutions are always best. You have better control over them. Use TWRP built-in terminal to run commands.
Simply 'cp' with verbose option "-v" is what fulfills your needs. 'rsync' is better if you want to save time by automatically skipping unchanged existing files. If you want to preserve file attributes and permissions, use 'tar'. Added compression can be achieved by 'xz' or '7za'. All of these commands are stable solutions, with high speed and ability to handle/resume broken/interrupted operations.
TWRP comes with busybox bundled. Busybox utilities have limited functionality and mostly suffice the need but rarely we face unexpected behavior. Instead you can use full static binaries of these commands.
Typing lengthy commands in TWRP shell terminal is somewhat challenging. Either use 'adb shell' or for repeated use, create a shell script and place it in internal memory or SD card. Or you can unpack TWRP image and save script in /sbin directly to run it just as a normal command. Another easy way is to create a flashable zip of your script. This way you can also see progress bar moving if you write a proper script for it.
Hope it helped.
The Following User Says Thank You to mirfatif For This Useful Post: [ View ] Gift mirfatif Ad-Free
5th January 2018, 02:09 PM |#9  
DrPhant0m's Avatar
Senior Member
Thanks Meter: 275
 
More
Quote:
Originally Posted by mirfatif

Commandline solutions are always best. You have better control over them. Use TWRP built-in terminal to run commands.
Simply 'cp' with verbose option "-v" is what fulfills your needs. 'rsync' is better if you want to save time by automatically skipping unchanged existing files. If you want to preserve file attributes and permissions, use 'tar'. Added compression can be achieved by 'xz' or '7za'. All of these commands are stable solutions, with high speed and ability to handle/resume broken/interrupted operations.
TWRP comes with busybox bundled. Busybox utilities have limited functionality and mostly suffice the need but rarely we face unexpected behavior. Instead you can use full static binaries of these commands.
Typing lengthy commands in TWRP shell terminal is somewhat challenging. Either use 'adb shell' or for repeated use, create a shell script and place it in internal memory or SD card. Or you can unpack TWRP image and save script in /sbin directly to run it just as a normal command. Another easy way is to create a flashable zip of your script. This way you can also see progress bar moving if you write a proper script for it.
Hope it helped.

That's a lot of help... But I lack the basic understanding and experience to make use of it all. I'll have to Google it a bit and look at some examples. Thanks!

UPDATE: I did a little research, and I succeeded in using "cp" to do a test move in TWRP (I had to use -r and -v), but even using -v didn't create a progress bar or any indication that files were being moved. It just finished and went to the next new line. Is this expected?

Also... my version of TWRP doesn't seem to have rsync available. When I try to use rsync in TWRP, I get
Code:
sh: rsync: not found
So it seems that TWRP's terminal doesn't have rsync. I'm using TWRP 3.0.2-1

So... I'm currently using the Termux app to do the cp operation. I'd prefer to use rsync, which is supported in Termux, however, unless I do "su" first, it says it doesn't have access to the destination folder. And, when I use "su" I can't use rsync. I get pretty much the same message as when I try to use it in TWRP... something like "rsync not found"

Does this mean that when Termux is using root, it can't use rsync? Does that make sense?

Any help?

Thanks!
6th January 2018, 05:52 PM |#10  
OP Senior Member
Flag Toba Tek Singh
Thanks Meter: 219
 
More
Quote:
Originally Posted by DrPhant0m

I did a little research, and I succeeded in using "cp" to do a test move in TWRP (I had to use -r and -v), but even using -v didn't create a progress bar or any indication that files were being moved. It just finished and went to the next new line. Is this expected?

'cp -r' copies recursively i.e. files/directories under directories and so on. So it's definitely required if you want to copy directories. 'cp -v' shows each file which is being copied, but not the progress during a single file copying. Check 'cp --help' for options.
Quote:

Also... my version of TWRP doesn't seem to have rsync available. When I try to use rsync in TWRP, I get

Code:
sh: rsync: not found
So it seems that TWRP's terminal doesn't have rsync. I'm using TWRP 3.0.2-1

TWRP uses busybox which doesn't have rsync built-in. You can get a copy of static (independently working) rsync binary from many sources like this. Aarch64 will be a bit faster. Check 'getrpop | grep ro.product.cpu' to find your CPU architecture if it's 64-bit or 32. When in TWRP, place binary in /sbin directory. Then do 'chmod 0777 /sbin/rsync' to make it executable. Now you can use rsync. 'rsync --help' will show you options and basic help. Do note, /sbin is on volatile filesystem i.e. it will be gone on reboot. Don't expect it to be permanently there. You can also use rsync from other locations like sd card but that will need to call binary with full path and filesystem may put restrictions on execution.
Quote:

So... I'm currently using the Termux app to do the cp operation. I'd prefer to use rsync, which is supported in Termux, however, unless I do "su" first, it says it doesn't have access to the destination folder. And, when I use "su" I can't use rsync. I get pretty much the same message as when I try to use it in TWRP... something like "rsync not found"

Does this mean that when Termux is using root, it can't use rsync? Does that make sense?

It's expected. When we do 'su' on Termux, it's environment is gone and PATH is set to /system/bin etc. So any binaries which Termux downloaded to /data/data/com.termux/files/usr/bin won't work. There are better options, but easiest is to use 'tsu' instead of 'su' on Termux. It will handle things for you to run Termux binaries in superuser mode. Do 'apt install tsu' when connected to internet. Once installed, simply execute 'tsu'. Now you can use Termux rsync binary.
Or use rsync static bianry instead as explained above. Copy rsync to /system/bin/ or /system/xbin/ etc. and set permissions. SELinux may interfere if it's set to "Enforcing". Do 'getenforce' to check and 'setenforce 0' to set it "Permissive".
The Following User Says Thank You to mirfatif For This Useful Post: [ View ] Gift mirfatif Ad-Free
16th January 2018, 05:36 AM |#11  
BillGoss's Avatar
Senior Member
Flag Sydney
Thanks Meter: 2,610
 
More
Quote:
Originally Posted by DrPhant0m

That's a lot of help... But I lack the basic understanding and experience to make use of it all. I'll have to Google it a bit and look at some examples. Thanks!

UPDATE: I did a little research, and I succeeded in using "cp" to do a test move in TWRP (I had to use -r and -v), but even using -v didn't create a progress bar or any indication that files were being moved. It just finished and went to the next new line. Is this expected?

Also... my version of TWRP doesn't seem to have rsync available. When I try to use rsync in TWRP, I get

So it seems that TWRP's terminal doesn't have rsync. I'm using TWRP 3.0.2-1

So... I'm currently using the Termux app to do the cp operation. I'd prefer to use rsync, which is supported in Termux, however, unless I do "su" first, it says it doesn't have access to the destination folder. And, when I use "su" I can't use rsync. I get pretty much the same message as when I try to use it in TWRP... something like "rsync not found"

Does this mean that when Termux is using root, it can't use rsync? Does that make sense?

Any help?

Thanks!

This reply is probably a bit late for you, but...
If you install tsu (pkg install tsu) in TermUX and use tsu rather than su, it'll work.
Tsu sets up the runtime context for su properly.

Sent from my OnePlus3T using XDA Labs
The Following User Says Thank You to BillGoss For This Useful Post: [ View ] Gift BillGoss Ad-Free
Post Reply Subscribe to Thread

Tags
adb, backup, backup methods, extract data, restore

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes