If you installed Termux (a free Android terminal emulator and Linux environment application) from the Google Play store and then found out that it’s a different release which likely differs from and lags behind the official release which is distributed over F-Droid or you are reinstalling Termux for any reason, you may be looking for instructions on how to back up and restore your Termux environment (which generally gets deleted along with all of your files when you uninstall the app).
While the official instructions (which I personally learned how to do this from) are posted on the Termux wiki, if you are looking for a quick guide to follow (provided you understand I am not responsible if you lose any data), here is what I do on my devices to back up and fully restore everything exactly as I had it.
In your current Termux
If you hadn't done so already, make sure to set up storage access by running:
$ termux-setup-storage
Now, just to be sure everything will go smoothly, run:
$ ls -l /sdcard/
$ ls -l /data/data/com.termux/files/
You should see home/
and usr/
under ../../files/
.
If everything looks good, proceed with making a full backup:
$ tar -czf /sdcard/termux-backup.tar.gz -C /data/data/com.termux/files ./home ./usr
Make sure the backup exists and looks reasonable:
$ ls -lh /sdcard/termux-backup.tar.gz
You can now safely uninstall Termux from your device.
Once you launch your new Termux
Set up storage access:
$ termux-setup-storage
Restore all the backed up files:
$ tar -zxf /sdcard/termux-backup.tar.gz -C /data/data/com.termux/files --recursive-unlink --preserve-permissions
Open a new session and make sure that everything is there and looks just like you had it.
If everything looks good, it’s safe to delete the backup:
$ rm -v /sdcard/termux-backup.tar.gz