Simple backup once more...



  • ... so most of us running a phone as daily are doing this for quite some time now. I get more and more uncomfortable with the fact that there is no good backup solution. Guess itΒ΄s a topic not as sexy as making Apps that rock, but still πŸ™‚

    Also if you want to swap devices this becomes a problem: You should not do backups while UT is running but use recovery for that. So, lets see what we can do:

    • My old approach was to only back up the user folder while UT was running, and using rsync+ssh to upload it. This works, but skips a few files that might be important, and you would have to reinstall all apps afterwards.
    • You can adb pull both folders from data: /data/system-data and /data/user-data - thats a proven method but its super-slooooow.
    • So what we need is to reduce the number of bytes on the wire, since the adb connection istnΒ΄t that great. Can we do this? πŸ™‚

    Turns out we can. First boot into recovery mode. Then taking a backup is as simple as that. make a script (thats your homework now) that:

    • creates a destination folder for the backup, or clears it out if it exists
    • calls this command adb exec-out "tar -czf - /data/user-data 2> /dev/null" > user-data.tgz
    • Same for system-data

    Restore script: Needs to be tested, but everyone with a spare device can try to:

    • Clear out destination on phone with a confirmation with rm -rf
    • Reverse the script operation with adb exec-in "tar -xzf - -C /" < user-data.tgz
    • Same for system-data

    I am calling on all shell script Ninjas, can you wrap this nicely, with error checks and confirmations? And maybe make it cmdline based, and also with a small menu?
    Bonus points: Identify device serial with adb and create separate backup folders per device. The whole family can share one backup place then πŸ˜‰



  • Note: I found that the Halium-7.1 recovery produces incomplete tgz files and this needs to be investiagted. TWRP recovery seems to work fine though. Very strange.


  • Administrators

    While that is a nifty and compact solution, it has some issues. For one, adb exec-in and exec-out are janky as fuck. It does very very weird things with error handlings, resulting often in unexpected silently corrupted files. Would absolutely not recommend. That, and the fact that there's no tar on windows, is why i proposed taring on the device and pulling for installer integration. Another angle has been started here.



  • Some, like me, need a nooby proof solution, if possible.
    Something like boot in recovery, launch ubports software on PC, then connect phone, click backup, choose what and where to backup, then validate and... voila!



  • I concur with @Keneda and no doubt so will the majority of newcommers to the platform who have moved away from Android or Apple and have grown accustomed to an easy way to back up.



  • @Keneda If it would be that easy to implement we would have implemented it already πŸ˜‰



  • @Flohack
    I get symlink errors with pull user-data, but I found this solution and it works:

    Consider this my "log" how I've transferred data from phone to phone (worked between two nexus 5 devices) without SD card
    I hope it will be helpful for somebody - but I've basically used combination of two methods described before plus some man pages
    NOTE: both devices have ubports image installed and are prepared for adb access ()

    SOURCE DEVICE
    After connecting source device on PC commands in terminal as follows:

    Reboot phone into recovery: adb reboot recovery
    Acquire root: adb root
    Activate shell: adb shell (command prompt will change to # sign)
    Backup system-data (this will also create log files, that can be examined for possible errors) :
    tar -czpv -f /system-data.tgz /data/system-data/ >/system-data.out 2>/system-data.err
    NOTE: I've just put these files into root directory and it went just fine πŸ˜‰ and pulled just one file into connected computer since adb has much better chance to transfer one big file without errors than many small ones
    logout from shell to your terminal (Ctrl+D)
    NOTE: I am assuming computer is linux with root access etc.
    this sub-step can be done before step 3
    5.1 go to directory where backup data are to be stored in PC (using cd and mkdir commands)
    transfer data from phone to PC adb pull /system-data.tgz
    6.1 it is good idea to have logs copied too adb pull /system-data.out and adb pull /system-data.err but it is not necessary
    steps 3. to 6. repeat but with user-data instead of system-data excluding .cache folder
    (so commands will look like tar -czpv -f /user-data.tgz /data/user-data/ --exclude='data/user-data/phablet/.cache' >/user-data.out 2>/user-data.err, adb pull /user-data.tgzetc.)
    NOTE: data which can be transferred by MTP should be moved that way since process of packing can take quite long for user data and may even stop/fail (e.g. not stopping process, just waiting and overheating battery, because all outputs are transferred to log files) if there is not enough space for package
    DESTINATION DEVICE
    Reboot phone into recovery: adb reboot recovery
    Acquire root: adb root
    Push archived data from PC to phone (root folder) adb push ./system-data.tgz / and adb push ./user-data.tgz /
    NOTE: in case of failure pushing both files and then unpacking both in adb shell it is possible to work the process "per partes" so following steps 4. and 5. will be done after each push and removing archive from phone (rm ./system-data.tgz in adb shell and then returning by Ctrl+D to PC shell)
    Activate shell: adb shell (command prompt will change to # sign)
    Extract archives tar -xzv -f /system-data.tgz and tar -xzv -f /user-data.tgz
    Restart phone, unplug, recharge (battery will be probably rather low πŸ˜… ) check data and switch SIM card πŸ˜€
    PS:
    After finishing and documenting the process, I'we found out that WiFi settings has not been transferred to destination device 😐 those must be somewhere in .cache folder then (I don't really mind, messages, apps, contacts and other settings are quite enough for me).

    It's form this thread:

    https://forums.ubports.com/topic/1683/migrate-data-from-device-to-device/21?_=1595872454998


Log in to reply