On LineageOS 23.0:

```bash
adb root
adb shell mv /data/data/com.termux/ /data/data/com.termux_bak/
adb uninstall com.termux
```

deletes `/data/data/com.termux_bak/`, why?
Aug 1, 3:54pm

The behavior you're observing is likely due to how Android's package manager (pm) and the adb uninstall command interact with the /data/data/<package> directory. Here's why /data/data/com.termux_bak/ might be deleted when running adb uninstall com.termux:


Why This Happens

  1. Android's Package Manager Behavior: When you run adb uninstall com.termux, the Android package manager (pm) removes:

    • The APK file associated with com.termux.
    • The entire /data/data/com.termux/ directory, including all its contents (files, subdirectories, etc.).
  2. Symbolic Links or Bind Mounts:

    • If /data/data/com.termux_bak/ was not a true copy but instead a symbolic link or bind mount pointing to /data/data/com.termux/, then moving the directory with mv would not create an independent copy. Instead, it would just create a new reference to the same data.
    • When adb uninstall runs, it removes the original /data/data/com.termux/ directory, which would also delete the data referenced by /data/data/com.termux_bak/ if it was a link or bind mount.
  3. Filesystem-Level Behavior:

    • On some Android devices (especially those with FUSE-based storage or dm-verity), the /data partition may use copy-on-write (CoW) or union filesystems. In such cases, moving a directory might not create a true independent copy, and the uninstallation could still affect the "moved" directory.
  4. Termux-Specific Behavior:

    • Termux's data directory (/data/data/com.termux/) might have special permissions or SELinux contexts that cause the entire directory tree to be treated as a single unit during uninstallation.

How to Properly Back Up /data/data/com.termux/

If you want to safely back up Termux's data before uninstalling, use one of these methods:

Method 1: Use tar to Create a True Copy

bash
adb shell "tar -czf /sdcard/termux_backup.tar.gz -C /data/data/ com.termux"
adb pull /sdcard/termux_backup.tar.gz
adb shell rm /sdcard/termux_backup.tar.gz
  • This creates a compressed archive of the directory, ensuring no links or mounts are preserved.

Method 2: Copy to External Storage

bash
adb shell cp -r /data/data/com.termux /sdcard/com.termux_bak
  • This ensures the data is copied to a separate filesystem (e.g., /sdcard), which is not affected by adb uninstall.

Method 3: Use rsync (if available)

bash
adb shell rsync -a /data/data/com.termux/ /sdcard/com.termux_bak/
  • This creates a recursive, independent copy of the directory.

Why mv Didn’t Work as Expected

  • mv on Android (especially in /data) might not behave like a traditional Unix mv. If the filesystem is FUSE-based or uses bind mounts, the move operation might not create a true independent copy.
  • The adb uninstall command forcefully removes the package's data directory, regardless of whether it was moved or linked.

Key Takeaway

Always copy (not move) data before uninstalling an app if you want to preserve it. Use tar, cp -r, or rsync to ensure a true backup. The mv command in /data may not work as expected due to Android's filesystem quirks.

Aug 1, 3:54pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more