Project

General

Profile

BackupTheDataPartition » History » Version 15

Denis 'GNUtoo' Carikli, 11/09/2020 08:19 PM
Import from BackupTheEFS

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 15 Denis 'GNUtoo' Carikli
h3. Setup ADB
18
19
Follow the instructions for [[ADB|setting up ADB on your computer]] so that you can access a root shell on your device.
20
21
*NOTE*: when prompted on your Replicant device, make sure that you check the box that says *Always allow from this computer* when you grant your computer USB debugging permissions. Otherwise, you will be unable to obtain root shell access on your Replicant device when you reboot it into the recovery OS to actually perform the backup.
22
23
*NOTE*: for security reasons, you may want to [[ADB#Revoking-all-computers-USB-debugging-permissions|revoke these non-expiring permissions]] once the backup is complete.
24
25
h3. Reboot into the recovery
26
27
To reboot in the recovery, you can follow the instructions in the [[RebootIntoTheRecovery]] wiki page.
28
29
h3. Title TBD
30 1 Denis 'GNUtoo' Carikli
31 9 Denis 'GNUtoo' Carikli
h4. Galaxy S III (GT-I9300)
32 1 Denis 'GNUtoo' Carikli
33
First, you need to make sure that the data partition is not mounted. 
34
35
To do that, you can run this command:
36
<pre>
37
adb shell "umount -l /data"
38
</pre>
39
40
If the /data partition was mounted, it will unmount it. This will look like that:
41
<pre>
42
$ adb shell "umount -l /data"
43
$ 
44
</pre>
45
46
If it was not mounted, it will instead show an error that we can ignore:
47
<pre>
48
$ adb shell "umount -l /data"
49
umount: /data: Invalid argument
50
</pre>
51
52
Once this is taken care of, we can backup the partition with the following command:
53
<pre>
54 10 Denis 'GNUtoo' Carikli
adb pull /dev/block/platform/dw_mmc/by-name/USERDATA ./USERDATA.img
55 1 Denis 'GNUtoo' Carikli
</pre>
56 10 Denis 'GNUtoo' Carikli
57
h2. Using the backup
58
59
h3. Restoring the partition
60
61
TODO
62
63
h3. Restoring individual application data.
64
65
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.
66
67
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:
68
<pre>
69
udisksctl loop-setup -f  USERDATA.img
70
</pre>
71
72
If that doesn't work you might need to use @sudo@ like that:
73
<pre>
74
sudo udisksctl loop-setup -f  USERDATA.img
75
</pre>
76
77
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.
78
79
If this works, it should produce an output that looks more or less like that:
80
<pre>
81
Mapped file USERDATA.img as /dev/loop0.
82
</pre>
83
84
Here you can see that it made the file content available in the @/dev/loop0@ partition.
85
86
We can then reuse this information to mount that partition. We can do that with the following command:
87
<pre>
88
udisksctl mount -b /dev/loop0 -o ro
89
</pre>
90
91
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.
92
93
The command above should produce an output that looks more or less like that:
94
<pre>
95
Mounted /dev/loop0 at /run/media/gnutoo/2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41
96
</pre>
97
98
It most probably change a bit from the output above as:
99
* Your username is probably not @gnutoo@.
100
* The @2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41@ is a randomly created identifier for the partition that is created when formatting it.
101
* Even @/run/media/@ can change depending on the GNU/Linux distribution and its version. For instance between Parabola and Trisquel 8 it is different.
102
103
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.
104
105
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.
106
107
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:
108
<pre>
109 12 Denis 'GNUtoo' Carikli
cd /data/data
110 10 Denis 'GNUtoo' Carikli
</pre>
111
112
You will then need to replace it by a command that looks like that:
113
<pre>
114
cd /run/media/gnutoo/2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41/data/
115
</pre>
116
117
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.
118
119
In addition you might not have the permissions to access the applications data. 
120
121 11 Denis 'GNUtoo' Carikli
For instance if you look at the permissions of the silence data you might have something that looks like that:
122
<pre>
123
$ ls -ld org.smssecure.smssecure/
124
drwxr-x--x 9 10063 10063 4096 26 oct.  19:44 org.smssecure.smssecure/
125
</pre>
126 1 Denis 'GNUtoo' Carikli
127 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.
128
129
In the output above, the first @10063@ is the user ID and the second @10063@ is the group id. 
130
131
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.
132
133 10 Denis 'GNUtoo' Carikli
To fix that you can become root with the following command:
134
<pre>
135
sudo su
136
</pre>
137
138 13 Denis 'GNUtoo' Carikli
Now you can then continue to follow the RestoreApplicationInternalData tutorial.
139 1 Denis 'GNUtoo' Carikli
140
h2. See also
141
142
* 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.