answered
2018-01-11 00:27:53 +0200
Table of Contents:
This answer contains of the following chapters:
- Disclaimer
- HowTo backup
- HowTo restore the backup
- Backup recovery test
- Inspecting the backup file
- About SailfishX partition layout
Disclaimer
(!) These commands worked for my SailfishX device F5121 with SailfishOS 2.1.3.7. They are not guaranteed to work for all SailfishX devices! (!)
(!) Please be carefull, using these commands! I guess, you can do heavy damage to your SailfishX device or your data if something goes wrong. And I can not guarantee that these commands are correct in all use cases. Use this information at own risk. (!)
HowTo backup
Step 1: Insert SD card
Insert an SD card into your SailfishX device, large enough to hold your backup data. In my case, my "system data" partition is filled with 1.5 GB of data and my "user data" is filled with 3.8 GB of data. In my test scenario, I ended up with a compressed backup image of 6.0 GB.
In these instructions, I use a 16 GB SD card with one single partition, formatted with a ext4 filesystem.
(!) Don't forget to format your SD card with a filesystem that is capable of holding single files large than 4 GB. Using FAT32 as filesystem will let the dd ... | gzip ...
process fail with "gzip: short write". (!)
Step 2: Enter recovery mode according to my other HowTo at Answer 177584 on Question 169302 "XperiaX recovery mode"
Step 3: Mount SD card
In the recovery shell type:
mkdir /mnt/sdcard
mount /dev/mmcblk1p1 /mnt/sdcard/
mmcblk1p1
means "first partition on the SD card. mmcblk1p2
would be second partition....
OPTIONAL: Typing ls -lh /mnt/sdcard/
should now display the contents of your SD card.
OPTIONAL: You can check with df -h
if there is enough space free on your mounted SD card partition.
Step 4: Backup your partition to SD card
Type the command:
dd if=/dev/mmcblk0p51 | gzip > /mnt/sdcard/backup.img.gz
I personally don't use backup.img.gz
as filename, but sailfishx-backup-mmcblk0p51-yyyy-mm-dd.img.gz
and replace yyyy-mm-dd
with the current date to document the date the backup has been created.
This command will read every single bit from partition mmcblk0p51
(see later for information about partitions), pipe those bits to the compression program gzip
and finally write those compressed bytes to the backup file backup.img.gz
on your SD card.
This process takes about 59 minutes in my case, but heavily depends on the amount of data to write and writing speed of your SD card. The output should look like:
43409408+0 records in
43409408+0 records out
22225616896 bytes (20.7GB) copied, 3518.607151 seconds, 6.0MB/s
Please check, that your number of records and bytes are identical to mine to ensure everything went fine. Time and writing speed will vary.
If you get gzip: short write
, your backup failed. See section "Insert SD card" above.
Just to be sure, type the command
sync
to flush the filesystem buffer and make sure everything has been written to your SD card.
Step 5: Unmount your SD card
Type the following commands to unmount your SD card again:
cd /
umount /mnt/sdcard/
Step 6: Exiting recovery mode
Now you can exit recovery mode, as described in Answer 177584 on Question 169302 "XperiaX recovery mode"
Step 7: Remove your SD card
As last step, I would recommend to shut down the SailfishX device once more and remove the backup SD card. Otherwise this backup won't help in cases like losing your SailfishX device. ;)
Then you are done! Congratulations! :)
HowTo restore the backup
Step 1, 2 and 3: Preparations
Insert your SD card with your backup file in your SailfishX device and do steps 2 and 3 from chapter "HowTo backup".
Step 4: Restore from SD card
In step 4 instead of dd ... | gzip ...
do this:
gzip -d -c backup.img.gz | dd of=/dev/mmcblk0p51
Replace backup.img.gz
with the name of your backup file.
The device identifier /dev/mmcblk0p51
is very crutial: If you use a wrong one, this command might destroy a partition of your SailfishX device, which contains import data like firmware, drivers, etc.. You might be able to "brick" your device with this command!
This process will read your backup file backup.img.gz
, decompress the bits and pipe them to dd
, which will write them to the internal partition mmcblk0p51
of your SailfishX device.
The restore process should output the same number of records and bytes as the backup process (time and writing speed will vary):
43409408+0 records in
43409408+0 records out
22225616896 bytes (20.7GB) copied, 1058.962191 seconds, 20.0MB/s
Surprisingly the restore process is about 3 times faster than the backup process. (I guess compressing is the bottleneck.)
Now lets do a
sync
again, to make sure all data has been flushed to the internal storage of your SailfishX device.
Steps 5, 6 and 7: Back to normal
Proceed with steps 5, 6 and 7 as described in chapter "HowTo backup".
Backup recovery test
Since a backup method is useless, unless you have tested it, I performed the following process:
- create a backup according to the instructions above
- changed some data on my SailfishX device
- restore the backup (of point 1) according to the instructions above
- check whether the changes (of point 2) have been reverted
Data I have changed and checked:
- modify address book
- delete existing and add new notes
- delete existing calendar events and add new ones
- settings:
- change developer password
- turn off mobile data
- disable display flip cover
- change usb mode from "charge" to "always ask"
- delete existing and add new pictures
- jolla apps:
- uninstall installed jolla app
- update installed jolla app
- uninstall installed android app
- revert the unlock sound hack
- jolla app settings:
- add new alarm
- disable "request SMS delive report"
- android app settings:
- change Threema color theme
- disable Threema start at boot time
- add new favorite POV to OsmAnd
- delete music file A and renamed music file B
=> All changes have been perfectly reverted by restoring the backup. :)
Inspecting the backup file
If you want to know, which data is contained in your backup file (created in backup step 4), or want to extract some file directly from the backup file, you can do the following on a linux PC (I use Debian, but it surely will work with other distros, too):
Step 1: install necessary programs:
apt-get install lvm2
Step 2: unzip your backup file:
gzip -d -k backup.img.gz
Step 3: setup loop device
If loop0
is already in use on your PC, use the next free device name like loop1
, loop2
, .... You can list used device names with cat /proc/mounts | grep /dev/loop
.
losetup /dev/loop0 backup.img
Step 4: start logical volume manager
Update: This step seems to be obsolete in Debian Stretch and does not work. The service is no longer available in Debian Stretch.
systemctl start lvm2
Step 5: check logical volume manager
Now you can list your logical volume groups with:
vgdisplay
You should see something like:
--- Volume group ---
VG Name sailfish
System ID
Format lvm2
...
Step 6: mount the partitions of the backup
mkdir /mnt/sailfish
mkdir /mnt/sailfish/root
mkdir /mnt/sailfish/home
mount /dev/sailfish/home /mnt/sailfish/home/
mount /dev/sailfish/root /mnt/sailfish/root/
Now you should be able to access your data at /mnt/sailfish/home/
and /mnt/sailfish/root/
.
E.g.:
ls -lh /mnt/sailfish/home/
Step 7: umount the partitions again
I you are done with inspecting and/or extracting, you can unmount the partitions again with:
umount /mnt/sailfish/home/
umount /mnt/sailfish/root/
I you like, you can remove the directories, too:
rmdir /mnt/sailfish/home
rmdir /mnt/sailfish/root
rmdir /mnt/sailfish
Step 8: shutdown logical volume manager
To be honest, I have no clue, whether if have to cleanly shutdown the logical volume manager in some way. Nor do I know, how to do it. But I guess a clean system shutdown will handle this correctly.
Hints are welcome
Thanks to:
About SailfishX partition layout
A few words about SailfishX partition layout:
fdisk -l
does not work very well in the recovery mode used in the steps above. So please don't use it.
A better way to get partition information in recovery mode is:
cat /proc/partitions
This will list a partition layout which is quite identical to using the following command in SailfishX normal operation mode (use option -O
to get a lot of output):
lsblk
Output of lsblk ...
is something like:
NAME KNAME FSTYPE SIZE MOUNTPOINT LABEL
...
├─mmcblk0p51 mmcblk0p51 LVM2_member 20.7G
│ ├─sailfish-root dm-0 ext4 2.5G / root
│ └─sailfish-home dm-1 ext4 18.3G /opt/alien/home home
└─mmcblk0p52 mmcblk0p52 ext4 7.3G /fimage fimage
@DrYak wrote a few word about those partitions. Please see his comment to this answer.
dd last mmcblk0pX
coderus ( 2018-01-02 01:41:53 +0200 )editwould love to have that, too.
Moo-Crumpus ( 2018-01-02 10:53:47 +0200 )editi'm really honored that the mighty coderus himself is replying to my question, but as i said: im too noobie to execute this wihitout further more precise and noobproof instruction.
please enlight me, coderus. спасибо
toba ( 2018-01-02 22:58:24 +0200 )edit