What happens to your apps if your phone breaks? Phones have become an essential part in our daily interactions with banks, social networks, entertainment, and what not. Losing or breaking a phone has never been more nervewrecking. Especially with apps that use local only storage with limited or no means of backup. Backing up data on Android is becoming harder, even for advanced users.
A decade ago, there were still viable options available for power users. Apps like Titanium Backup come to mind. But Android is being locked down tighter every year, because of financial regulations and trusted computing requirements. This mindset of turning phones into walled gardens where even a power user shall have no access is trickling down to forks such as LineageOS as well.
Modern versions of LineageOS, 18.1 as of the moment of writing, do no longer provide a practical way for applications to gain root. Backup applications such as Titanium Backup no longer work. There are much more intrusive methods such as Magisk and boot image patching available in order to get these backup apps to work, but this is far from ideal and may come with considerable risk.
There are backup options available today in Android distributions, but many apps now downright refuse access to any of their data. Without judging, all of this is done in the name of security, regulations and preventing malicious abuse. But as a result, these backup methods as well as the apk backup
and apk restore
commands no longer provide a proper full way of backing up app data. They are next to useless for backup purposes.
In the meantime, a lot of seemingly shady backup apps have sprung up. Some of them need root access and consist of odd scripts. In short, none of them can be trusted.
So why not back things up manually? This quick 'n dirty guide to get you started!
Currently, the /data
partition is still accessible through a adb shell with root privileges, which can be gained with adb root
by only changing some non-intrusive settings on the phone. This means that app APKs and data can in fact be backed up and restored as before, without any external tools, by using a adb-capable host machine.
Something can be said about the security implications of supplying root to apps on the phone.. that's all understandable, as long as they don't take root on our phone away from adb!
Some things to keep in mind:
- Some apps may not respond well to their data being restored on a different machine, such as Signal. These apps will typically crash immediately when started. For example, some apps may encrypt their data using a keychain on the phone which makes it very difficult to restore things.
- Use
adb logcat
to debug any issues with apps.
Download all app APKs from phone to current directory.
Bash:
for APP in $(adb shell pm list packages -3 -f)
do
adb pull $( echo ${APP} | sed "s/^package://" | sed "s/base.apk=/base.apk /").apk
done
Powershell:
foreach ($APP in $(adb shell pm list packages -f -3)) {Invoke-Expression $($APP.replace('package:','adb pull ').replace('base.apk=','base.apk ')+'.apk')}
Upload all APKs in current directory to phone.
Bash:
for APP in *.apk
do
adb install ${APP}
done
Batch:
for /f %f in ('dir /b .') do adb install %f
Make sure adb has root access.
Host:
adb root
Upload backup_data.sh
bash script.
Host:
adb push backup_data.sh /data/data/ && adb shell chmod 755 /data/data/backup_data.sh
Host
adb shell ls /data/data/
Assuming /data/data/_backup
as location on phone for tarballs, though this can be changed.
Backup specific app:
Host
adb shell bash /data/data/backup_data.sh /data/data/_backup com.google.android.apps.authenticator2
Assuming /data/data/_backup
as location on phone for tarballs, though this can be changed.
Host
adb pull /data/data/_backup
Upload restore_data.sh
bash script.
Host:
adb push restore_data.sh /data/data/ && adb shell chmod 755 /data/data/restore_data.sh
Host
adb push _backup /data/data/
Restore specific app:
Host
adb shell bash /data/data/restore_data.sh /data/data/_backup com.google.android.apps.authenticator2
Restore all apps from /data/data/_backup
:
Host:
adb shell cd /data/data/_backup && for f in *.tar.bz2; do bash /data/data/restore_data.sh /data/data/_backup ${f%.data.tar.bz2}; done;
Host
rm -rf /data/data/_backup