Skip to content

Instantly share code, notes, and snippets.

@renjieliu
Last active December 18, 2024 20:44
Show Gist options
  • Save renjieliu/bc002fb0f5f4b606b73c8a0d10a2795f to your computer and use it in GitHub Desktop.
Save renjieliu/bc002fb0f5f4b606b73c8a0d10a2795f to your computer and use it in GitHub Desktop.
Migrate Termux setup from Device A to Device B

Follow below steps to migrate the setup of Termux from Device A to Device B

Step 0. To get the MicroSD card ID

For termux, ~/storage folder contains a bunch of the soft links

external-n is the one pointing to the MicroSD card or the OTG USB Drive, using realpath ~/storage/external-1, can get the physical path on the MicroSD card. The XXXX-YYYY part is the MicroSD card UUID

Other links, such as dcim, movies, music, they are pointing to the folders on the phone internal storage, using realpath ~/storage/dcim can find the physical location of the folder

  • Most of the time, the internal storage are something like /storage/emulated/0
  • The microSD card would be something like /data/XXXX-YYYY/Android.data/com.termux/files

Step 1. Backup termux on device A and run below command one by one.

  • cd /data/data/com.termux/files
  • tar -zcvf ./termux-backup_20211031.tar.gz home usr
  • mv ./termux-backup_20211031.tar.gz /storage/[Device A ID]/Android/data/com.termux/files/termux-backup_20211031.tar.gz

Step 2. Restore the setup of Termux on Device B.

  • Use a bluetooth keyboard to connect to the device B
  • Open the termux app
  • Grant the storage permission to the MicroSD card with command termux-setup-storage, and click "Allow"
  • Go to the termux root folder with cd /data/data/com.termux/files
  • Using the first part of the instruction to get the [Device B ID], the MicroSD ID usually looks like XXXX-YYYY
  • Copy the backup file to the termux root folder: cp /storage/[Device B ID]/Android/data/com.termux/files/termux-backup_20211031.tar.gz .
  • Override the current home and usr folder with tar -zxvf ./termux-backup.tar.gz home && tar -zxvf termux-backup.tar.gz usr

Restart the Termux and see if all the setup are in place on device B.

Replace any script/soft link using the /storage/[Device A ID] to /storage/[Device B ID]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment