Skip to content

Improve backup and restore scripts - #303

Open
sylirre wants to merge 4 commits into
termux:masterfrom
sylirre:improve-termux-backup
Open

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

Conversation

@sylirre

@sylirre sylirre commented Apr 23, 2026

Copy link
Copy Markdown
Member

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 2 times, most recently 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

sylirre commented Apr 25, 2026

Copy link
Copy Markdown
Member Author

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

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.

Support advanced Termux file system layouts allowed by rules from
https://github.com/termux/termux-packages/blob/22641beab1a72fea849590e1b4b514d5720655b5/scripts/properties.sh#L917-L930
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.

Support advanced Termux file system layouts allowed by rules from
https://github.com/termux/termux-packages/blob/22641beab1a72fea849590e1b4b514d5720655b5/scripts/properties.sh#L917-L930
@sylirre
sylirre force-pushed the improve-termux-backup branch from ac219e4 to 47fee6a Compare September 19, 2026 23:28
* termux-backup: select $PREFIX contents only after permissions have
  been fixed and refuse to continue if a directory on the path to $HOME
  is not accessible. Previously 'nullglob' silently dropped contents of
  such directories from the archive.

* termux-restore: do not alter permissions of files under $HOME when
  only $PREFIX is being restored.

* termux-restore: pass --no-wildcards so $HOME path is always matched
  literally by --exclude.
@sylirre
sylirre marked this pull request as ready for review September 20, 2026 00:08
@sylirre
sylirre force-pushed the improve-termux-backup branch from cb208b9 to 00187cd Compare September 20, 2026 00:22
@sylirre

sylirre commented Sep 20, 2026

Copy link
Copy Markdown
Member Author

backup/restore updated to handle different file system layouts.

…ected structure

Prevents removal of files and directories that shouldn't be removed
during cleanup.
@sylirre
sylirre force-pushed the improve-termux-backup branch from 00187cd to 330427c Compare September 20, 2026 00:45
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