Auto backup for Termux

Needless to say, Termux is an incredible tool for any Linux enthusiast. It is an Android terminal emulator, and has nothing to do with a virtualised or simulated installation. That is, with it we would be interacting directly with our Android device, but of course, with limited and restricted access outside the Termux installation directory and, above all, to the hardware.
Even so, with Termux we can tinker a lot creating scripts or installing packages as in any other machine.
The problem comes when you are constantly changing things and trying things out. That's when you realise, you've been installing packages for 2 hours and making so many changes that you don't know what you've done and you think, "why wouldn't I make a backup before to restore termux to a state before I messed up?".
That is why I have created a bash script for this task:
- Creates a backup (home directory included) of Termux.
- Searches for backups older than 7 days and deletes them.
- Sends a notification to the mobile when it finishes (OK or ERROR).
- Creates a .log record of the actions it performs.
- (extra) With Drive sync I synchronize the path of Termux to have everything in Drive.
You can see the project in my Github: b4shnhawx/termux-backup
USE CASE
The script itself is not very complicated. If you wish, you can format the date, name and path where the backups will be saved in the variables in lines 3 to 6.

crontab -e
In my case I want the backup to run every day at 5 AM.0 5 * * * bash /data/data/com.termux/files/home/scripts/termux_backup.sh
Comments