Skip to content

Instantly share code, notes, and snippets.

@nutrino
Created January 27, 2025 00:02
Show Gist options
  • Select an option

  • Save nutrino/0542fa8d73c2f82953a378734b32b480 to your computer and use it in GitHub Desktop.

Select an option

Save nutrino/0542fa8d73c2f82953a378734b32b480 to your computer and use it in GitHub Desktop.

Revisions

  1. nutrino created this gist Jan 27, 2025.
    46 changes: 46 additions & 0 deletions wear_os_backup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    adb shell pm list packages -3 > wear-os-packages-out.txt

    mkdir ~/wear-os-backup
    #!/bin/zsh

    set -x

    BACKUP_DIR=~/wear-os-backup
    PACKAGE_LIST_FILE=~/wear-os-packages-out.txt

    ADB_PATH=~/Library/Android/sdk/platform-tools/adb

    # Create a backup directory
    mkdir -p "$BACKUP_DIR"

    # Backup APKs (including split APKs)
    while read -r line; do
    package="${line#package:}" # Remove "package:" prefix

    echo "Processing package: $package"

    # Get all APK paths for the package
    apk_paths=$($ADB_PATH shell pm path "$package" 2>/dev/null | sed 's/package://')

    echo "$apk_paths"

    # Check if APK paths exist
    if [ -z "$apk_paths" ]; then
    echo " Warning: No APKs found for $package. Skipping..."
    continue
    fi

    # Create a subdirectory for the package (to avoid filename collisions)
    package_dir="$BACKUP_DIR/$package"
    mkdir -p "$package_dir"

    # Pull all APKs for this package
    echo "$apk_paths" | while read -r apk_path; do
    echo " Pulling: $apk_path"
    $ADB_PATH pull "$apk_path" "$package_dir/"
    if [ $? -ne 0 ]; then
    echo " Error: Failed to pull $apk_path"
    fi
    done

    done < $PACKAGE_LIST_FILE