If you often uninstall Termux for testing purposes, you need to know how to back up Termux’s files so you can quickly restore them after reinstalling. Root privileges are not required.
Referenced from the Termux WiKi
1. Back up Termux files#
Besides personal use, Termux backup archives can also be provided to other people, which is the so-called “recovery package”.
- Get storage permission
termux-setup-storage- Create a backup archive. This command backs up the data in Termux’s external directories, not including proot-distro. If the Termux data takes up 10GB of space, the backup takes about 10 minutes and the archive size is about 5GB.
tar -zcf /sdcard/termux-backup.tar.gz -C /data/data/com.termux/files ./home ./usrWithout root privileges, you can only use the proot-distro backup command to back up Proot-distro data separately:
proot-distro backup --output /sdcard/debianbackup.tar.gz debianIf you have root privileges, the following version of the command can back up the data inside Proot-distro’s internal directories into a single file as well, with no need to use proot-distro backup.
pkg install tsu
sudo tar -zcf /sdcard/termux-backup.tar.gz -C /data/data/com.termux/files ./home ./usr2. Restore Termux backup files#
Restoring a Termux backup does not require root privileges.
- First get storage permission
termux-setup-storage- Suppose the backup file is located at
internal storage/termux-backup.tar.gz; restore it and restore permissions. After running this command, the data will be overwritten.
tar -zxf /sdcard/termux-backup.tar.gz -C /data/data/com.termux/files --recursive-unlink --preserve-permissions- Enter
exitto quit Termux. Reopen the app and the files will be back.
To restore the separately backed-up Proot-distro, run:
proot-distro restore /sdcard/debianbackup.tar.gz
