Project

General

Profile

RestoreApplicationInternalData » History » Revision 3

Revision 2 (Denis 'GNUtoo' Carikli, 10/28/2020 06:37 PM) → Revision 3/49 (Denis 'GNUtoo' Carikli, 10/28/2020 11:32 PM)

h1. RestoreApplicationInternalData 

 {{toc}} 

 h2. /!\ Warning: Draft 

 This article is in draft form and is being written: 
 * Everybody is welcome to contribute 
 * Some things might not be accurate yet, so beware before using the information contained in it. 

 h2. Introduction 

 In some case, it is useful to be able to restore internal applications data: 
 * You may want to move the data of an application from a device to another 
 * If some files like /data/system/packages.xml or /data/system/appops.xml get corrupted, applications can loose access to their data. This can make the launcher and other applications crash. 

 h2. Howto 

 TODO: 
 * Explain how to mount a full backup, and why not to restore full backup completely 
 * Explain how and why create a tarball of the application data 

 <pre> 
 $ adb shell "mount /dev/block/platform/dw_mmc/by-name/USERDATA /data" 
 </pre> 

 <pre> 
 $ adb shell 
 </pre> 

 <pre> 
 root@m0:/ # cd /data/data/                                                      
 root@m0:/data/data #  
 </pre> 

 <pre> 
 root@m0:/data/data # ls -lad org.smssecure.smssecure 
 __bionic_open_tzdata: couldn't find any tzdata when looking for localtime! 
 __bionic_open_tzdata: couldn't find any tzdata when looking for GMT! 
 __bionic_open_tzdata: couldn't find any tzdata when looking for posixrules! 
 drwxr-x--x 2 u0_a61 u0_a61 4096 2012-01-01 00:01 org.smssecure.smssecure 
 </pre> 

 Here the users and groups are @u0_a61@. 

 <pre> 
 root@m0:/data/data # mv org.smssecure.smssecure org.smssecure.smssecure.delme 
 </pre> 

 <pre> 
 root@m0:/data/data # tar tf /org.smssecure.smssecure.tar 
 ./org.smssecure.smssecure/ 
 ./org.smssecure.smssecure/lib -> /data/app/org.smssecure.smssecure-1/lib/arm 
 [...] 
 </pre> 

 <pre> 
 root@m0:/data/data # tar xpf /org.smssecure.smssecure.tar --numeric-owner 
 </pre> 

 <pre> 
 root@m0:/data/data # ls -ld org.smssecure.smssecure  
 __bionic_open_tzdata: couldn't find any tzdata when looking for localtime! 
 __bionic_open_tzdata: couldn't find any tzdata when looking for GMT! 
 __bionic_open_tzdata: couldn't find any tzdata when looking for posixrules! 
 drwxr-x--x 9 u0_a63 u0_a63 4096 2012-01-01 00:21 org.smssecure.smssecure 
 </pre> 

 <pre> 
 root@m0:/data/data # chown u0_a61:u0_a61 -R org.smssecure.smssecure             
 root@m0:/data/data #  
 </pre> 

 <pre> 
 root@m0:/data/data # rm -rf org.smssecure.smssecure.delme 
 root@m0:/data/data #  
 </pre> 

 <pre> 
 root@m0:/data/data # restorecon                                                 
 usage: restorecon [-D] [-F] [-R] [-n] [-v] FILE... 

 Restores the default security contexts for the given files. 

 -D 	 apply to /data/data too 
 -F 	 force reset 
 -R 	 recurse into directories 
 -n 	 don't make any changes; useful with -v to see what would change 
 -v 	 verbose: show any changes 

 restorecon: Needs 1 argument 
 </pre> 

 <pre> 
 root@m0:/data/data # restorecon -D -F -R -v /data/                            
 SELinux: Loaded file_contexts contexts from /file_contexts. 
 [...] 
 SELinux:    Relabeling /data/data/org.smssecure.smssecure from u:object_r:system_data_file:s0 to u:object_r:app_data_file:s0:c512,c768. 
 SELinux:    Relabeling /data/data/org.smssecure.smssecure/lib from u:object_r:system_data_file:s0 to u:object_r:app_data_file:s0:c512,c768. 
 [...] 
 </pre> 

 <pre> 
 root@m0:/data/data # cd  
 root@m0:/ # umount    /data/                                                      
 root@m0:/ #  
 </pre> 

 <pre> 
 root@m0:/ # sync 
 root@m0:/ # reboot 
 </pre>