By default the Android Google Authenticator App does not provide a possibility to backup and restore the database, but this could be archived manually.
If one add a lot of accounts for two factor authentication (2FA) onto the Google Authenticator, its not intended to reinstall the device or migrate the codes to a second device.
1. Prepare connection
First of all, a rooted rooted device is required for the following steps. Also the “Developer options” should be active, with “USB debugging” and “OEM unlocking” turned on.
Run the following command from your computer, which is connected by USB with your device:
computer$ adb devices
and confirm the security question at the device.
2. Backup database
Next connect to the device and copy the database to the download folder, because a normal user could access the database at this location:
computer$ adb shell
device$ su
device# cp /data/data/com.google.android.apps.authenticator2/databases/databases /storage/emulated/0/Download/
If the database is used at a second android user account, i.e. for a non-rooted environment, the database is located at a different location (change “11” to your account id):
device# cp /data/user/11/com.google.android.apps.authenticator2/databases/databases /storage/emulated/0/Download/
Finlay the database could be downloaded to the computer:
computer$ adb pull /storage/emulated/0/Download/databases .
3. Restore database
For restoring the database to the new installed or second device the steps are reversed:
computer$ adb push databases /storage/emulated/0/Download/
computer$ adb shell
device$ su
device# mv /storage/emulated/0/Download/databases /data/data/com.google.android.apps.authenticator2/databases/
Check the permission and set them to the correct one:
device# ls -la /data/data/com.google.android.apps.authenticator2/databases/
drwxrwx--x 2 u0_a165 u0_a165 4096 2018-09-18 21:00 . drwx------ 7 u0_a165 u0_a165 4096 2018-09-18 21:00 .. -rw-rw---- 1 root sdcard_rw 16384 2018-09-18 21:00 databases
device# chown u0_a165:u0_a165 /data/data/com.google.android.apps.authenticator2/databases/databases
Now run the Google Authenticator App and check that the database is successfully used with the backup-ed database. If it does not work at the first try:
- Delete the databases-shm and databases-wal database files from the directory
- Exit the Google Authenticator App from the App-Details and try to open it again
That’s it.
4. Optional: view the sqlite database
If you want to see the content of the database, just use the following commands:
computer$ sudo apt install sqlite3
computer$ sqlite3 ./databases
sqlite> .tables
accounts android_metadata
sqlite> select * from accounts;