Restore Home Folder, full functionality

I broke my phone again. Damn slippery things. The screen is completely broken. Fortunately, I did a full backup of the complete /home partition the same day, and I had it restored with full functionality on a spare device (with a half broken screen) less than 24h later.

Backup

I created the backup - while the GUI was running - with this little script:

#!/bin/sh

backupdir="/home"
outputdir="/home/defaultuser/Downloads"
outfile="$outputdir/backup-$(date '+%Y%m%d%H%M').tar.gz"

echo "Will make a full backup of $backupdir, stored in $outputdir"

devel-su tar --totals --exclude="$outfile" -c -z -f "$outfile" "$backupdir"

echo "Backup saved as $outfile"

Restore

The destination device is a factory-reset SFOS device (doesn’t matter which one afaics, everything here is architecture- and hardware-agnostic), registered and updated to the same version as the one the backup came from (but maybe that’s irrelevant too, as long as the versions don’t differ too much I guess).

The gzipped tar backup is located on an inserted sdcard.

To avoid all sorts of trouble with the GUI running I boot into recovery and telnet into the device via USB, then open a shell.

cryptsetup open /dev/mapper/sailfish-home myhome
mount -m /dev/mapper/myhome /mnt/myhome
mount -m /dev/mmcblk1p1 /mnt/sdcard
cd /mnt/myhome
mv defaultuser defaultuser.bak
tar xcf ../sdcard/backup-nnnnnnnnnnnn.tar.gz home/defaultuser
mv home/defaultuser .
rmdir home
umount /mnt/*
cryptsetup close /dev/mapper/myhome
exit

You might have to check whether /dev/mmcblk1p1 is really the partition you want. Do so with fdisk -l.

As you can see we only restored the defaultuser part. I don’t think it would have made sense
to restore the other folders.

Now reboot in accordance with the docs. That’s it. I still need to reinstall software, but everything works: accounts, configurations, contacts, calendars, downloaded podcasts… it’s all there, except for Signal which I had to restore from its own backup.

After 1 or 2 reboots I deleted /home/defaultuser.bak.

12 Likes

If you are willing to do, also restore /var/lib/bluetooth to restore the BT list as well as the /var/lib/waydroid → /home/waydroid symlink and folders in case you had those

(there’s also some for AAS etc)

2 Likes

In retrospect I should’ve tried restoring all folders in /home (appsupport, system) except those related to packagemanagement (*zypp*). Ah well, next time.

1 Like

This time I have succesfully restored more folders under /home.

Replace the script in post #1 (after telnet) with this:

cryptsetup open /dev/mapper/sailfish-home myhome
mkdir /mnt/myhome /mnt/sdcard
mount /dev/mapper/myhome /mnt/myhome
mount /dev/mmcblk1p1 /mnt/sdcard
cd /mnt/myhome
tar xvf ../sdcard/backup-nnnnnnnnnnnn.tar.gz
for d in defaultuser appsupport-root .system .appsupport; do
    mv -v "$d" "$d.bak"
    mv -v "home/$d" .
done
rm -rf home
cd /
umount /mnt/*
cryptsetup close /dev/mapper/myhome
exit

Of course I have to reinstall apps, but they just pick up where I left on the previous device.

Except Signal - it works but has not fully adapted all messages, there’s a gap I cannot explain.

4 Likes

On my phone Xperia 10 III the --totals option for tar didn’t exist. Is there another tar package available?

2 Likes

That’s the limited busybox tar version. You could install gnu-tar, but it’s not necessary.

I currently cannot edit the OP; here’s a better/compatible version of the first script:

#!/bin/sh

backupdir="/home"
outdir="$(grep -wo '/run/media/defaultuser/[^ ]*' /etc/mtab)"
[ -z "$outdir" ] && outdir="/home/defaultuser/Downloads"
[ -w "$outdir" ] || { echo "Cannot write to $outdir"; exit 1; }

outfile="$outdir/backup-$(date '+%Y%m%d%H%M').tar.gz"

echo "Will make a full backup of $backupdir, stored in $outdir"

devel-su tar -v -c -z -f "$outfile" "$backupdir"

echo "Backup saved as $outfile"

and a better version of the second script is in my previous post.

1 Like