I needed to restore my Whatsapp messages without having a proper whatsapp backup, in cloud or local, just a TWRP data partition backup (without userdata, thanks to encryption and some other unrelated problems), so, having only data/data/com.whatsapp directory with the unencrypted databases and files to work with, the usual solutions discussed here weren't an option. In my case, fully replacing the com.whatsapp folder and changing its permissions, as some other sources recommend, resulted in Whatsapp crashing for reasons I ignore. Such info was on the right track and after trying all kind of stuff I finally was able to restore my messages. My steps were as follows, hopefully it works for you too:
Requirements:
If Whatsapp crashes after launching it, you wrote a wrong user/group when changing permissions. Whatsapp overwrites the contents of com.whatsapp before crashing, so you'll need to reinstall Whatsapp and start again. The user/group will be a different one each time you install it.
Requirements:
- A backup of /data/data/com.whatsapp, it should have the databases and files subdirectories.
- Rooted Android phone with Whatsapp uninstalled.
- Basic terminal usage knowledge. (Should be possible to do it with a decent enough file browser but I won't cover it, feel free to adapt it)
- Locate the different data.ext4.win### files in the TWRP backup.
- Rename them adding .tar at the end of the name and open them with Winrar/7zip.
- If the .tar contains another data.ext4.win###, extract it and repeat the process.
- Once you have access to the actual contents inside the files, locate the file which has the data/data/com.whatsapp directory.
- Extract that com.whatsapp directory.
- Copy your backup of com.whatsapp directory to your phone (I will use /sdcard/com.whatsapp as example).
- Install Whatsapp but DO NOT RUN IT. Try to use the same version. (Probably works between versions to some extent)
- Install an Android terminal emulator and launch it. (Tested with termux)
- Elevate, enter /data/data and show the permissions of the installed Whatsapp com.whatsapp directory:
Code:$ su # cd /data/data # ls -ld com.whatsapp
- You'll see something similar to:
Code:drwx------ 10 u0_a117 u0_a117 4096 2020-03-09 17:28 com.whatsapp
- Take note of the user/group, will have u0_a# format. (In my case will be u0_a117)
- Enter into that directory:
Code:# cd com.whatsapp
- Copy files and databases directories from your transferred com.whatsapp copy in step 1 to your install location. (Don't forget the final space and dot)
Code:# cp -R /sdcard/com.whatsapp/databases . # cp -R /sdcard/com.whatsapp/files .
- Change both directories owner and group to the one seen in step 5.
Code:# chown -R u0_a117:u0_a117 databases # chown -R u0_a117:u0_a117 files
- Check the permissions to be 100% sure that the user/group are correct.
Code:# ls -lad *es
- Launch Whatsapp.
- Whatsapp will ask you to configure your phone number. Once you're done, you'll see your messages right there.
If Whatsapp crashes after launching it, you wrote a wrong user/group when changing permissions. Whatsapp overwrites the contents of com.whatsapp before crashing, so you'll need to reinstall Whatsapp and start again. The user/group will be a different one each time you install it.