Project

General

Profile

BackupTheDataPartition » History » Version 14

Denis 'GNUtoo' Carikli, 11/09/2020 08:15 PM
update status

1 1 Denis 'GNUtoo' Carikli
h1. How to backup the data partition
2
3
{{toc}}
4
5
h2. /!\ Warning: Draft
6
7
This article is in draft form and is being written:
8
* Everybody is welcome to contribute
9
* Some things might not be accurate yet, so beware before using the information contained in it.
10
11 3 Denis 'GNUtoo' Carikli
h2. What does the data partition contains?
12 1 Denis 'GNUtoo' Carikli
13 8 Denis 'GNUtoo' Carikli
See [[DataPartition]] for more details.
14 1 Denis 'GNUtoo' Carikli
15
h2. Howto
16
17
TODO: 
18 14 Denis 'GNUtoo' Carikli
* Go in the recovery
19 1 Denis 'GNUtoo' Carikli
20 9 Denis 'GNUtoo' Carikli
h4. Galaxy S III (GT-I9300)
21 1 Denis 'GNUtoo' Carikli
22
First, you need to make sure that the data partition is not mounted. 
23
24
To do that, you can run this command:
25
<pre>
26
adb shell "umount -l /data"
27
</pre>
28
29
If the /data partition was mounted, it will unmount it. This will look like that:
30
<pre>
31
$ adb shell "umount -l /data"
32
$ 
33
</pre>
34
35
If it was not mounted, it will instead show an error that we can ignore:
36
<pre>
37
$ adb shell "umount -l /data"
38
umount: /data: Invalid argument
39
</pre>
40
41
Once this is taken care of, we can backup the partition with the following command:
42
<pre>
43 10 Denis 'GNUtoo' Carikli
adb pull /dev/block/platform/dw_mmc/by-name/USERDATA ./USERDATA.img
44 1 Denis 'GNUtoo' Carikli
</pre>
45 10 Denis 'GNUtoo' Carikli
46
h2. Using the backup
47
48
h3. Restoring the partition
49
50
TODO
51
52
h3. Restoring individual application data.
53
54
Here we will use the @udisksctl@ command instead of the more classical @mount@ and @losetup@ as it integrates better with graphical environments like Gnome or KDE.
55
56
As the partition backup is now in a file, to access its data we will make it available as a partition again. This can be done with the following command:
57
<pre>
58
udisksctl loop-setup -f  USERDATA.img
59
</pre>
60
61
If that doesn't work you might need to use @sudo@ like that:
62
<pre>
63
sudo udisksctl loop-setup -f  USERDATA.img
64
</pre>
65
66
Or you may also need to verify that your current users has the right to read and write the file that contains the partition (here USERDATA.img) file.
67
68
If this works, it should produce an output that looks more or less like that:
69
<pre>
70
Mapped file USERDATA.img as /dev/loop0.
71
</pre>
72
73
Here you can see that it made the file content available in the @/dev/loop0@ partition.
74
75
We can then reuse this information to mount that partition. We can do that with the following command:
76
<pre>
77
udisksctl mount -b /dev/loop0 -o ro
78
</pre>
79
80
The @-o ro@ option will make sure that the partition is mounted in read only mode. This will make sure that we don't accidentally change its content.
81
82
The command above should produce an output that looks more or less like that:
83
<pre>
84
Mounted /dev/loop0 at /run/media/gnutoo/2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41
85
</pre>
86
87
It most probably change a bit from the output above as:
88
* Your username is probably not @gnutoo@.
89
* The @2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41@ is a randomly created identifier for the partition that is created when formatting it.
90
* Even @/run/media/@ can change depending on the GNU/Linux distribution and its version. For instance between Parabola and Trisquel 8 it is different.
91
92
You can write down the location of the directory where this partition is mounted (here @/run/media/gnutoo/2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41@) as we will need it later on.
93
94
Now that this partition is mounted, we will be able to use the RestoreApplicationInternalData tutorial to make a backup of the data of a specific application and restore it.
95
96
To do that, locate the following command in the [[RestoreApplicationInternalData#Backuping-Silences-data-from-the-old-device|Backuping Silence's data from the old device]] section of the RestoreApplicationInternalData wiki page:
97
<pre>
98 12 Denis 'GNUtoo' Carikli
cd /data/data
99 10 Denis 'GNUtoo' Carikli
</pre>
100
101
You will then need to replace it by a command that looks like that:
102
<pre>
103
cd /run/media/gnutoo/2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41/data/
104
</pre>
105
106
In the command above, you'll need to replace @/run/media/gnutoo/2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41/@ by the location of the directory where the partition is mounted.
107
108
In addition you might not have the permissions to access the applications data. 
109
110 11 Denis 'GNUtoo' Carikli
For instance if you look at the permissions of the silence data you might have something that looks like that:
111
<pre>
112
$ ls -ld org.smssecure.smssecure/
113
drwxr-x--x 9 10063 10063 4096 26 oct.  19:44 org.smssecure.smssecure/
114
</pre>
115 1 Denis 'GNUtoo' Carikli
116 11 Denis 'GNUtoo' Carikli
See the [[RestoreApplicationInternalData#How-to-find-which-directory-holds-the-internal-data-of-an-application|How to find which directory holds the internal data of an application]] section in the RestoreApplicationInternalData wiki page for more details to understand why @org.smssecure.smssecure@ directory has the Silence application's data.
117
118
In the output above, the first @10063@ is the user ID and the second @10063@ is the group id. 
119
120
This is because Android sandboxes applications as part of their security model: each applications run in their own user and group ID. The result is that theses are most likely present on your phone but not on your GNU/Linux computer.
121
122 10 Denis 'GNUtoo' Carikli
To fix that you can become root with the following command:
123
<pre>
124
sudo su
125
</pre>
126
127 13 Denis 'GNUtoo' Carikli
Now you can then continue to follow the RestoreApplicationInternalData tutorial.
128 1 Denis 'GNUtoo' Carikli
129
h2. See also
130
131
* The [[BackupsResearch]] page has information on why the backup is done this way. It might also be useful to read and contribute to it if you intend to change the way the backups are done.