Skip to content

Improve backup and restore scripts#303

Draft
sylirre wants to merge 2 commits into
termux:masterfrom
sylirre:improve-termux-backup
Draft

Improve backup and restore scripts#303
sylirre wants to merge 2 commits into
termux:masterfrom
sylirre:improve-termux-backup

Conversation

@sylirre
Copy link
Copy Markdown
Member

@sylirre sylirre commented Apr 23, 2026

Drop piped input and output in favor of maintaining versatile backup options. Breaking change but I don't think that removed pipe feature will be a big deal.

@sylirre sylirre force-pushed the improve-termux-backup branch from 24748bd to bd9904d Compare April 23, 2026 19:30
sylirre added 2 commits April 23, 2026 19:45
Major update for the backup script:

* Backup home and usr by default
* Support selective backup mode: either only home or only usr

Support for piped output was dropped to maintain consistency with
upcoming changes to termux-restore script.
Major changes implied by updating termux-backup script:

* Support restoring both home and usr at user discretion
* Restore only usr by default
* Support disabling --recursive-unlink tar behavior

Support for piped input was dropped. It is not possible to seek piped
tarball, therefore no reliable way to detect its contents and we can't
make guesses because dealing with user data.
@sylirre sylirre force-pushed the improve-termux-backup branch from bd9904d to ac219e4 Compare April 23, 2026 19:45
@agnostic-apollo
Copy link
Copy Markdown
Member

Should probably check if home or prefix are under each other, like if rootfs equals prefix .../files and home is at .../files/home.

https://github.com/termux/termux-packages/blob/22641beab1a72fea849590e1b4b514d5720655b5/scripts/properties.sh#L923

@robertkirkman
Copy link
Copy Markdown
Member

Thank you!

It's a good timing, I needed to back up and a restore a really large 42 GB Termux installation. I tested this PR by backing up and restoring from this PR version and everything worked great.

I used this from my Termux home folder:

~ $ termux-backup --home --packages /storage/emulated/0/termux_backup.tar.gz

Something I would like to note is that it was not able to back up my .suroot folder (this is the secret home folder of the system root user in Termux, since while we say Termux is a "single user system", technically reality is more complicated because people who have root do have access to that second user, so Termux is a "single user system except when it isn't").

Any files I might have wanted to save from my root projects are not backed up by that. "projects" is quite general and could include many settings or data, for example the Bash History file of the root user in Termux. I saw errors like this:

tar: ./home/.suroot/.bashrc: Cannot open: Permission denied

I wondered, if I were to use sudo su, cd $HOME and then use the command termux-backup --home /storage/emulated/0/termux_suroot_backup.tar.gz, would that be expected to create another backup, of just my root home folder? I didn't really want to post this without at least trying it on myself to see what would happen, and what happened is actually that my entire home folder was backed up, but this time including .suroot without failing to include it, which is pleasant.

I think there is only a minor difference between what I as a user expected, and what happened, which is that I thought --home would only back up my .suroot folder if run as root, which could save space in my backup if I want to do it this way, by first backing up my termux user home folder, then my root user home folder separately. If trying to infer the desired home folder from the $HOME variable would be bad for some reason, then you don't need to do that, I am just wondering whether it could work like that.

@sylirre sylirre marked this pull request as draft April 25, 2026 19:31
@sylirre
Copy link
Copy Markdown
Member Author

sylirre commented Apr 25, 2026

It back ups only original Termux prefix and home. It won't let override these directories through environment variables.

.suroot will get automatically excluded if can't be read by tar

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants