Android 10 backup from TWRP terminal - Android Q&A, Help & Troubleshooting

Hi all,
I'm tinkering with my OnePlus 6 and trying to backup so I can restore after I soft-brick it by removing bloatware.
I'm using OxygenOS 10.3.2 and seems that TWRP doesn't backup/restore as it should, it always bricks my phone whenever I restore /system or /data.
I'm trying to save and restore data via terminal at the moment, I mounted /system and I see I have access to dd.
Is it possible to just copy everything from /system and /data to /sdcard, move it to my pc, and whenever I brick the phone, just stock install OxygenOS 10.3.2 then TWRP and restore via terminal?
Anyone done this?
I presume the risk is low if I'm only touching /system and /data?
edit:
Managed to backup /system with DD but I don't know how to backup /data, as /data is the same device as /sdcard, and it would create a file equal to the whole partition size. I would not be able to store it on the same partition since /sdcard is basically a subfolder of /data.
Any way of backing up /data? on the same partition?
I would have tried with rsync then zip the whole thing and extract it on my pc. I know rsync keeps the file/folder permissions intact. But rsync is not available in TWRP recovery.

I tried to make a tar archive while inside /data, excluding the media folder, like this:
Code:
tar -pzcvf data.tar.gz --exclude=media *
The -p option should preserve SELinux attributes. I then copy data.tar.gz to /sdcard and pull it on my PC.
But, when I move it back, delete everything in /data except media folder, then unpack the archive and reboot, it goes into recovery.
I don't understand why wiping all files then putting them back from the archive breaks the system. What am I missing?
edit:
Apparently /data backup and restore work from TWRP modified by Mauronofrio, only the /system backup/restore is broken, but that can be done with DD from TWRP.
So my issues are solved at the moment.

mad_rock said:
I tried to make a tar archive while inside /data, excluding the media folder, like this:
Code:
tar -pzcvf data.tar.gz --exclude=media *
The -p option should preserve SELinux attributes. I then copy data.tar.gz to /sdcard and pull it on my PC.
But, when I move it back, delete everything in /data except media folder, then unpack the archive and reboot, it goes into recovery.
I don't understand why wiping all files then putting them back from the archive breaks the system. What am I missing?
edit:
Apparently /data backup and restore work from TWRP modified by Mauronofrio, only the /system backup/restore is broken, but that can be done with DD from TWRP.
So my issues are solved at the moment.
Click to expand...
Click to collapse
I'm not sure if -p is sufficient to also backup the selinux rights.
Have you tried the tar option --selinux ?
From the man1 page:
Code:
--selinux
Enable SELinux context support.

Related

[Q] is there a way to link messages/contacts to sdcard?

edit: take note, I am not asking on how to backup.
Having 17 thousand messages, don't want to delete any, of them.
I want messages on my inbox but memory consumed is on sdcard.
On The End 4.0 rom
tried
su
mount -o bind /data/data/com.android.providers.telephony /sdcard/data/sms
I think it's not working.
Any help there experts?
If you want to have a backup then use some SMS backup apps. Else, Titanium FTW.
Btw, what you're trying to do is just mounting. You can mount only images or partition storage in linux. Not a DIRECTORY.
Android uses SQLite database to store anything. If you want to have just a backup and you're sure about location of directory. Just pull with ADB, next time when you flash a ROM, you can use `adb remount` and push those database in same location to restore.
Rushyang said:
If you want to have a backup then use some SMS backup apps. Else, Titanium FTW.
Btw, what you're trying to do is just mounting. You can mount only images or partition storage in linux. Not a DIRECTORY.
Android uses SQLite database to store anything. If you want to have just a backup and you're sure about location of directory. Just pull with ADB, next time when you flash a ROM, you can use `adb remount` and push those database in same location to restore.
Click to expand...
Click to collapse
Hello, thank you for replying.
I am very well aware on how to backup. What Im asking is to link, having them on my inbox but memory consumed is sdcard instead of internal memory.
On sgs2, I was able to directory bind (by mounting) on gameloft games by mounting from internal memory to external memory.. I just forgot which commands I used.
Oh well, In that case I understood totally different what you were seeking for. Pardon me.
What you're seeking is "Attaching the filesystems" between directories through mount bind. (But there is not -o in modifiers there for creating such).
First backup your /data/data/com.android.providers.telephony safe place, which you won't be touching until Mount Bind process is successfully achieved.
Please consider I'm not responsible if you loose your 17k sms. Install SMS backup etc. But If you carefully follow these steps, I'm pretty sure nothing is serious.
Now,
1) Make directory in your SDCard, say
/sdcard/data/drigz08.telephony.original.source
2) Use app like root explorer to mount or just fire `adb remount` command if you've set up adb in your PC.
3) Move contents of /data/data/com.android.providers.telephony to /sdcard/data/drigz08.telephony.original.source
So now, all of your telephony directories data are moved. Now here comes the best part...
4) Bind those directories...
mount --bind /sdcard/data/drigz08.telephony.original.source /data/data/com.android.providers.telephony
Click to expand...
Click to collapse
step 4 will bind those directories in a way that from any path same contents are accessible, but new data will be store in sdcard only.
5) In case you want to change the path of source, or unbind directory..
mount -o remount,ro /data/data/com.android.providers.telephony
Click to expand...
Click to collapse
Let me know how it goes.
PS: I tested all of above under standard linux environment. Working fine.
did not work
drigz08 said:
did not work
Click to expand...
Click to collapse
Mount bind on new directory doesn't work or still mounted on com.android.....

Undeletable files

In the process of restoring some backups I ended up with a couple clockwork mod backup folders in the top of the /mnt/sdcard or /sdcard folder. These files store on the internal sdcard (not the removable micro sdcard) are effectively Undeletable. I have checked permissions and tried to remove them via astro and root explorer and when mounted on desktop and via adb shell commands (rm ...). Other files in the folder are removable but these backups refuse to budge.
Have restored to stock. Have restored via cwm. Absolutely refuse to shift and they are not small.
Any advice on ridding my s3 of these files would be welcome.
You checked files's permissions, but what was exactly the chmod applied ? Do you hack checked the owner ?
If these are folders, did you use the correct option of rm ( rm -f ) ?
As they're CWM backup files, you could use ROM Manger to get rid of them as well.
Use "rom janitor" from market to delete cwm backup files

[Q] Alternatives to Nandriod Backup?

Hello Guys,
Any idea, if we have any Alternatives to Nandriod Backup?
Drawbacks of Nandriod Backup as I know:
1. It does not backup EFS binary/image which contains IMEI details
2. It does not backup Modem binary/image which is useful to camp to the networks
FYI: I know there are tools like EFS Pro and kTool to backup EFS
I wonder if there is any tool which can dump my entire ROM's partition on to sdcard "as it is" and re-storable using CWM.
Please delete this thread
Please delete this thread. I am supposed to use Q & A section instead of General...
EDIT: Great, moved to Q & A section. Thanks Mod Hulk
Raghunan said:
Hello Guys,
Any idea, if we have any Alternatives to Nandriod Backup?
Drawbacks of Nandriod Backup as I know:
1. It does not backup EFS binary/image which contains IMEI details
2. It does not backup Modem binary/image which is useful to camp to the networks
FYI: I know there are tools like EFS Pro and kTool to backup EFS
I wonder if there is any tool which can dump my entire ROM's partition on to sdcard "as it is" and re-storable using CWM.
Click to expand...
Click to collapse
Found Alternative to Nandriod Backup
Guys, found some useful info @ forum.xda-developers.com/showthread.php?t=1667886
-------------------- backup
before messing with the partition table, everyone should make backups of all partitions that can be accessed.
-------------------- efs backup
The most important backup is the efs partition, which very crucial, it includes your IMEI number, bluetooth MAC etc., and without this individual information, your phone cannot be used as a phone again.
For most supported phones, you can do this via adb:
Code:
dd if=/dev/block/mmcblk0p1 of=/mnt/sdcard/efs.img
please look at forrest1971's thread for details about using adb.
If your phone uses another partition number for efs, then use this instead of the "1" in mmcblk0p1.
Perhaps you have to mount your sdcard first, to be able to save it there.
Then you should copy the backup to your PC (the recovery should have the option to mount usb).
-------------------- backup files from internal sd before repartitioning
the repartitioning will clear all data in the affected partitions, so all data in your big partition (internal sd etc.) will be lost.
You can try to backup your data, if the partition is accessible. The different methods below may have different success, depending which parts of your phone are usable.
* you can use aroma file manager, which is a full fledged gui file manager which starts standalone by being flashed in CWM. So it should be completely independent (sorry, I could not test it for this kind of backup myself).
For the following possibilities you should first ensure, you have a working recovery with working adb support.
Mount your external sd in recovery (which might be /emmc or /sdcard, please check), to be able to copy files.
* you can use QtAdb to copy files to your PC:
* you can use adb pull to copy any files or directory tree to your PC, e.g.:
adb pull /emmc/. emmc
* you can use tar from adb to archive files to a file on sdcard:
adb shell tar cvjf /sdcard/emmc.tar.bz2 /emmc/.
* you can use a copy command in adb shell to copy files to a folder in sdcard:
adb shell cp -ra /emmc/. /sdcard/emmc.backup
Note: you will loose file attributes and owner information if emmc is formatted with ext2/ext3/ext4, because vfat cannot handle these.
This may matter for system and some app related files.
Click to expand...
Click to collapse

Problem with sdcard backup

Hi!
I wanted to reformat my internal sdcard to ext4 today to enable trimming (it should also help the /data partition, because it is on the same physical flash storage, right?).
To back up my data I thought about packing everything into a TAR archive to also save all permissions (for example of the ./Android/data/ folder). But now I have the following problem:
if I browse through /storage/sdcard0, I see all the permissions and the correct owners, but I dont have access to .android_secure. I am using a adb root shell, how can I not have access to this?!
if I browse through /mnt/media_rw/sdcard0, I have access to .android_secure, but all the file owners are set to "media_rw", which is not what I want to backup, I need the correct owner info to correctly restore the data later.
Could you please help me to answer these questions?:
As I understand, FAT doesnt support permissions, so how does android emulate the permissions in the ./Android/data folder?
How can I see the same folder (my internal sdcard) with different file owners? Is it mounted twice with special options?
How can I backup my whole sdcard (with owner/group info & permissions & file access dates) to restore everything 1:1 after reformating to ext4?
How do I reformat my sdcard to ext4? (which block device comes after "mkfs.ext4"?)
Thank you very much!!
GridLockFour said:
Hi!
I wanted to reformat my internal sdcard to ext4 today to enable trimming (it should also help the /data partition, because it is on the same physical flash storage, right?).
To back up my data I thought about packing everything into a TAR archive to also save all permissions (for example of the ./Android/data/ folder). But now I have the following problem:
if I browse through /storage/sdcard0, I see all the permissions and the correct owners, but I dont have access to .android_secure. I am using a adb root shell, how can I not have access to this?!
if I browse through /mnt/media_rw/sdcard0, I have access to .android_secure, but all the file owners are set to "media_rw", which is not what I want to backup, I need the correct owner info to correctly restore the data later.
Could you please help me to answer these questions?:
As I understand, FAT doesnt support permissions, so how does android emulate the permissions in the ./Android/data folder?
How can I see the same folder (my internal sdcard) with different file owners? Is it mounted twice with special options?
How can I backup my whole sdcard (with owner/group info & permissions & file access dates) to restore everything 1:1 after reformating to ext4?
How do I reformat my sdcard to ext4? (which block device comes after "mkfs.ext4"?)
Thank you very much!!
Click to expand...
Click to collapse
I'm not sure the answer to some of that, but you don't need ext4 for trimming(EDIT: although I don't know whether android enables trim on FAT) and /data is already ext4 by default. The /data partition is separate to /sdcard0
Most if not all gains from trimming would be made from trimming /system, /data, /cache, and /preload(if you use touchwiz based rom or stock)

Access User Data in Recovery Backup

Hi,
I have a Wiko Lenny 3 phone and need to recover the pictures. The unlock code is lost, the touchscreen doesn't work anymore. My ideas so far:
1. I used the "Backup user data" feature of the stock recovery to a SD card.
Since I cannot upload an image until I have 10 posts, the recovery is like
"
Android Recovery
alps/full_v3702/v3702
6.0/MRA58K/1453981211
user/release-keys
Volume down to move highlight;
enter Volume up key to select.
----------------------------------------
Reboot system now
Reboot to bootloader
Apply update from ADB
Apply update from SD card
Wipe data/factory reset
Wipe cache partition
Backup user data ---> this is what I used
Restore user data
Root integrity check
Mount /system
View recovery logs
Power off
----------------------------------------
SD card free space: 29564MB
User data allocated: 11893MB
backup file: userdata_20190929_172118.backup
Backup user data complete.
"
But how to access the data? Tutorials which I found didn't help (merging the files in Linux, remove 512 Bytes and rename to zip to be able to extract "some" data: it isn't recognized as zip file). Is it possible to restore this user data to a virtual device somehow to access the data?
2. Removing the code: Following a German instruction (I'm not allowed to link it, sorry).
ADB doesn't recognize the device. Probably because USB debugging is turned off and I cannot turn it on without unlocking the device.
I don't do this very often, so my knowledge about ADB and Android is limited.
Does someone have a helping hint? Thank you in advance!
Regards
Martin
Martin_2 said:
Hi,
I have a Wiko Lenny 3 phone and need to recover the pictures. The unlock code is lost, the touchscreen doesn't work anymore. My ideas so far:
1. I used the "Backup user data" feature of the stock recovery to a SD card.
Since I cannot upload an image until I have 10 posts, the recovery is like
"
Android Recovery
alps/full_v3702/v3702
6.0/MRA58K/1453981211
user/release-keys
Volume down to move highlight;
enter Volume up key to select.
----------------------------------------
Reboot system now
Reboot to bootloader
Apply update from ADB
Apply update from SD card
Wipe data/factory reset
Wipe cache partition
Backup user data ---> this is what I used
Restore user data
Root integrity check
Mount /system
View recovery logs
Power off
----------------------------------------
SD card free space: 29564MB
User data allocated: 11893MB
backup file: userdata_20190929_172118.backup
Backup user data complete.
"
But how to access the data? Tutorials which I found didn't help (merging the files in Linux, remove 512 Bytes and rename to zip to be able to extract "some" data: it isn't recognized as zip file). Is it possible to restore this user data to a virtual device somehow to access the data?
2. Removing the code: Following a German instruction (I'm not allowed to link it, sorry).
ADB doesn't recognize the device. Probably because USB debugging is turned off and I cannot turn it on without unlocking the device.
I don't do this very often, so my knowledge about ADB and Android is limited.
Does someone have a helping hint? Thank you in advance!
Regards
Martin
Click to expand...
Click to collapse
Martín only way you could access them pictures is if you had twrp
([emoji3590]09-09-18[emoji3590])
Thanks. Is it possible to flash TWRP without losing data and without access via ADB?
Martin_2 said:
Thanks. Is it possible to flash TWRP without losing data and without access via ADB?
Click to expand...
Click to collapse
If your phone has twrp available and it's a Samsung you can flash it and you won't be able to do a twrp backup without formatting data to have data partition mountable in twrp to flash decrypt zip to do a backup however you don't need to format to be able to mount system partition once system is mounted you can use the twrp file explorer to delete files to delete your screen lock so you can enter the phone
([emoji3590]09-09-18[emoji3590])
PoochyX said:
If your phone has twrp available and it's a Samsung you can flash it and you won't be able to do a twrp backup without formatting data to have data partition mountable in twrp to flash decrypt zip to do a backup however you don't need to format to be able to mount system partition once system is mounted you can use the twrp file explorer to delete files to delete your screen lock so you can enter the phone
([emoji3590]09-09-18[emoji3590])
Click to expand...
Click to collapse
It's a Wiko Lenny 3, no Samsung. Sorry, I don't get it without punctuation.
Do I get it right, that
- If TWRP is available for my phone I can flash it, but I need to format all my data (no option)
- I can flash a "decrypt zip" to do a backup (what is it, where do I get it?)
- I can mount the system partition and can use the TWRP file explorer to delete files (how can I mount it?)
Thanks.
Problem solved, I could access all the data in the backup from the stock recovery!
This is how it worked:
In short: Make a backup of all user files in the stock recovery to a MicroSD card, put it to a Linux desktop, merge the backup files by skipping the first 512 bytes of each file, copy the merged file to Windows, extract it with 7zip.
In long:
1. I put an empty 32GB FAT32 formatted MicroSD card in the MicroSD slot of the Wiko Lenny 3
2. I used "Backup user data" from the Stock Recovery (see my first post). It took a few minutes until ~12GB of user data were written to the card. The stock recovery told me when it was done.
3. I copied all files (6 files, userdata_20190929_172118.backup to userdata_20190929_172118.backup5) to a Linux environment (Linux Mint 19.2)
4. The rest is explained in this video: https://www.youtube.com/watch?v=cY4cKKimEFU. If it is offline, I will explain here.
Do not use something like "cat userdata_yyyymmdd_HHMMSS.backup* > userdata_yyyymmdd_HHMMSS.backup" to merge all files into one because it will add the unnessesary 512 bytes header of all .backup files to the merged file. Instead copy all content except the first 512 bytes to another file and append the content from the other files to it, also by skipping the first 512 bytes.
5. This command will copy the content of the first file "userdata_20190929_172118.backup" to a new file "img.ext4":
Code:
dd if=userdata_20190929_172118.backup skip=512 bs=128k iflag=nocache,skip_bytes oflag=nocache,append conv=notrunc of=img.ext4
6. Repeat using the same command to append the content of all other files to the file "img.ext4" by skipping the first 512 bytes. Be sure to increase the number of the source file extention in the command. Next one therefore is:
Code:
dd if=userdata_20190929_172118.backup1 skip=512 bs=128k iflag=nocache,skip_bytes oflag=nocache,append conv=notrunc of=img.ext4
7. Repeat with all files
8. Copy the file "img.ext4" to a NTFS formatted USB stick or an external hard drive and go on with a Windows environment. The reason is that Linux will prevent opening some important folders
9. Install 7zip
10. Extract the file "img.ext4" with 7zip. If you are searching for pictures, you will find them in the subfolder "\media\0\DCIM\Camera"
Martin_2 said:
Problem solved, I could access all the data in the backup from the stock recovery!
This is how it worked:
In short: Make a backup of all user files in the stock recovery to a MicroSD card, put it to a Linux desktop, merge the backup files by skipping the first 512 bytes of each file, copy the merged file to Windows, extract it with 7zip.
In long:
1. I put an empty 32GB FAT32 formatted MicroSD card in the MicroSD slot of the Wiko Lenny 3
2. I used "Backup user data" from the Stock Recovery (see my first post). It took a few minutes until ~12GB of user data were written to the card. The stock recovery told me when it was done.
3. I copied all files (6 files, userdata_20190929_172118.backup to userdata_20190929_172118.backup5) to a Linux environment (Linux Mint 19.2)
4. The rest is explained in this video:
. If it is offline, I will explain here.
Do not use something like "cat userdata_yyyymmdd_HHMMSS.backup* > userdata_yyyymmdd_HHMMSS.backup" to merge all files into one because it will add the unnessesary 512 bytes header of all .backup files to the merged file. Instead copy all content except the first 512 bytes to another file and append the content from the other files to it, also by skipping the first 512 bytes.
5. This command will copy the content of the first file "userdata_20190929_172118.backup" to a new file "img.ext4":
Code:
dd if=userdata_20190929_172118.backup skip=512 bs=128k iflag=nocache,skip_bytes oflag=nocache,append conv=notrunc of=img.ext4
6. Repeat using the same command to append the content of all other files to the file "img.ext4" by skipping the first 512 bytes. Be sure to increase the number of the source file extention in the command. Next one therefore is:
Code:
dd if=userdata_20190929_172118.backup1 skip=512 bs=128k iflag=nocache,skip_bytes oflag=nocache,append conv=notrunc of=img.ext4
7. Repeat with all files
8. Copy the file "img.ext4" to a NTFS formatted USB stick or an external hard drive and go on with a Windows environment. The reason is that Linux will prevent opening some important folders
9. Install 7zip
10. Extract the file "img.ext4" with 7zip. If you are searching for pictures, you will find them in the subfolder "\media\0\DCIM\Camera"
Click to expand...
Click to collapse
I have the exact same problem with an older 2017 ALCATEL Pixi Unite A466BG. The code is lost and there's some photos we need off of it. I followed these instructions but when I got the img.ext4 file on Windows and tried extracting it with 7zip, I got an error that "ext4" is not an archive file.
I was hoping to see if anyone else had ideas of possibly why 7zip wasn't recognizing it? I had 3 backup files to merge (backup, backup1, backup2).

Categories

Resources