> ## Documentation Index
> Fetch the complete documentation index at: https://liaobots.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 旧域名数据迁移

> 从 Android APP 导出 IndexedDB 数据并恢复到新站点

# 📱 旧域名数据迁移

当网站域名失效或无法访问时，你可以通过此方法从 Android 手机 APP 中提取本地存储的 IndexedDB 数据，并导入到新站点。

***

## 0️⃣ 准备工作

### 电脑端

| 工具         | 说明                            |
| ---------- | ----------------------------- |
| **操作系统**   | Windows / macOS / Linux       |
| **adb 工具** | Android Debug Bridge          |
| **终端**     | 命令提示符 / PowerShell / Terminal |

#### 安装 adb

<Tabs>
  <Tab title="Windows">
    1. 下载 [SDK Platform Tools](https://developer.android.com/studio/releases/platform-tools)
    2. 解压到 `C:\platform-tools`
    3. 添加到系统环境变量（见下方详细步骤）
  </Tab>

  <Tab title="macOS">
    ```bash theme={null}
    brew install android-platform-tools
    ```
  </Tab>

  <Tab title="Linux">
    ```bash theme={null}
    sudo apt install adb
    ```
  </Tab>
</Tabs>

***

### Windows 配置环境变量

<Steps>
  <Step title="打开运行对话框">
    按 `Win + R`，输入 `sysdm.cpl`，点击确定

    <Frame>
      <img src="https://mintcdn.com/liaobots/TH469ZMeWtTsoUfC/images/export-indexeddb/run-sysdm.png?fit=max&auto=format&n=TH469ZMeWtTsoUfC&q=85&s=42a217dc48f69d3dd92c49dd713251df" alt="运行对话框" width="728" height="382" data-path="images/export-indexeddb/run-sysdm.png" />
    </Frame>
  </Step>

  <Step title="打开系统属性">
    选择「高级」标签页

    <Frame>
      <img src="https://mintcdn.com/liaobots/TH469ZMeWtTsoUfC/images/export-indexeddb/system-advanced.png?fit=max&auto=format&n=TH469ZMeWtTsoUfC&q=85&s=8a8ac36968bd1c3454303a4d79caacd7" alt="系统属性" width="749" height="840" data-path="images/export-indexeddb/system-advanced.png" />
    </Frame>
  </Step>

  <Step title="点击「环境变量」">
    <Frame>
      <img src="https://mintcdn.com/liaobots/TH469ZMeWtTsoUfC/images/export-indexeddb/env-button.png?fit=max&auto=format&n=TH469ZMeWtTsoUfC&q=85&s=c8322b9f2e9d56f4eb7c419d65d8861c" alt="环境变量按钮" width="755" height="851" data-path="images/export-indexeddb/env-button.png" />
    </Frame>
  </Step>

  <Step title="编辑 Path 变量">
    在「系统变量」中找到 `Path`，点击「编辑」

    <Frame>
      <img src="https://mintcdn.com/liaobots/TH469ZMeWtTsoUfC/images/export-indexeddb/edit-path.png?fit=max&auto=format&n=TH469ZMeWtTsoUfC&q=85&s=375b5bc21415e0b7ffa18cd1df44b732" alt="编辑Path" width="939" height="943" data-path="images/export-indexeddb/edit-path.png" />
    </Frame>
  </Step>

  <Step title="添加 adb 路径">
    点击「新建」，输入 `C:\platform-tools`，点击确定

    <Frame>
      <img src="https://mintcdn.com/liaobots/TH469ZMeWtTsoUfC/images/export-indexeddb/add-path.png?fit=max&auto=format&n=TH469ZMeWtTsoUfC&q=85&s=cdf48fcfd7dd4b908c144af1a240090f" alt="添加路径" width="829" height="797" data-path="images/export-indexeddb/add-path.png" />
    </Frame>
  </Step>
</Steps>

***

### 手机端

| 要求             | 说明                              |
| -------------- | ------------------------------- |
| **Android 手机** | 已安装目标 APP（如 `com.liaobots.app`） |
| **开启 USB 调试**  | 见下方步骤                           |
| **USB 数据线**    | 连接手机和电脑                         |

#### 开启开发者选项和 USB 调试

1. 打开「设置」→「关于手机」
2. 连续点击「版本号」7 次 → 成为开发者
3. 返回「设置」→「开发者选项」→ 打开「USB 调试」
4. 用 USB 数据线连接手机到电脑

***

## 1️⃣ 检查 adb 连接

### 验证 adb 安装

```bash theme={null}
adb version
```

显示版本号说明安装成功，例如：

```
Android Debug Bridge version 1.0.41
```

### 连接手机

```bash theme={null}
adb devices
```

<Warning>
  手机会弹出授权提示 → **点击「允许」**
</Warning>

输出示例：

```
List of devices attached
ABCDEF12345    device
```

<Check>显示 `device` 表示连接成功</Check>

***

## 2️⃣ 查找 IndexedDB 数据

### 进入 adb shell

```bash theme={null}
adb shell
```

### 切换到应用用户

```bash theme={null}
run-as com.liaobots.app
```

<Warning>
  此命令仅对 **debug 版本** APK 有效。正式版 APK 需要 root 权限。
</Warning>

### 导航到 IndexedDB 目录

```bash theme={null}
cd app_webview/Default/IndexedDB
ls
```

你会看到类似这样的输出：

```
https_liaobots.work_0.indexeddb.leveldb
https_liaobots1.work_0.indexeddb.leveldb
https_liaobots2.work_0.indexeddb.leveldb
```

<Frame>
  <img src="https://mintcdn.com/liaobots/TH469ZMeWtTsoUfC/images/export-indexeddb/adb-shell.png?fit=max&auto=format&n=TH469ZMeWtTsoUfC&q=85&s=0bae61df76f5882e7926ca08373e1ecc" alt="adb shell 操作" width="1619" height="530" data-path="images/export-indexeddb/adb-shell.png" />
</Frame>

<Check>这些 `.indexeddb.leveldb` 文件夹就是你要的数据</Check>

### 退出 adb shell

```bash theme={null}
exit
exit
```

***

## 3️⃣ 导出数据到电脑

在电脑终端（不是 adb shell）运行：

```bash theme={null}
adb exec-out run-as com.liaobots.app tar cf - app_webview/Default/IndexedDB > IndexedDB_backup.tar
```

<Frame>
  <img src="https://mintcdn.com/liaobots/TH469ZMeWtTsoUfC/images/export-indexeddb/export-cmd.png?fit=max&auto=format&n=TH469ZMeWtTsoUfC&q=85&s=6cc3f2af9b86fe80f4890ab98ee1d1f3" alt="导出命令" width="1650" height="219" data-path="images/export-indexeddb/export-cmd.png" />
</Frame>

这会在当前目录生成 `IndexedDB_backup.tar` 文件。

### 解压文件

<Tabs>
  <Tab title="Windows">
    ```bash theme={null}
    tar -xf IndexedDB_backup.tar
    ```
  </Tab>

  <Tab title="macOS / Linux">
    ```bash theme={null}
    tar -xf IndexedDB_backup.tar
    ```
  </Tab>
</Tabs>

解压后得到目录结构：

```
app_webview/
└── Default/
    └── IndexedDB/
        ├── https_liaobots.work_0.indexeddb.leveldb/
        ├── https_liaobots1.work_0.indexeddb.leveldb/
        └── ...
```

***

## 4️⃣ 恢复数据到新站点

1. 访问新站点的数据恢复页面（如 `/downloadjson`）
2. 点击「选择 IndexedDB 文件夹」
3. 选择解压得到的 `.indexeddb.leveldb` 文件夹

<Frame caption="选择 https_xxx.indexeddb.leveldb 文件夹">
  <img src="https://mintcdn.com/liaobots/TH469ZMeWtTsoUfC/images/export-indexeddb/select-folder.jpg?fit=max&auto=format&n=TH469ZMeWtTsoUfC&q=85&s=4a7fbd158889109de5d305312967b540" alt="选择文件夹" width="2266" height="554" data-path="images/export-indexeddb/select-folder.jpg" />
</Frame>

<Warning>
  注意选择的是 `.indexeddb.leveldb` 结尾的文件夹，不是 `.indexeddb.blob` 文件夹
</Warning>

4. 等待解析完成，下载 JSON 文件
5. 在新站点导入 JSON 文件即可恢复数据

***

## ❓ 常见问题

<AccordionGroup>
  <Accordion title="run-as 命令报错 'Package not debuggable'">
    说明 APK 是正式版，不是 debug 版。需要使用 debug 版 APK 或者 root 手机。
  </Accordion>

  <Accordion title="adb devices 显示 unauthorized">
    手机上没有点击「允许」授权。请检查手机屏幕上的授权弹窗。
  </Accordion>

  <Accordion title="导出的 tar 文件是空的">
    检查路径是否正确。可以先用 `adb shell` 进入手机确认文件存在。
  </Accordion>

  <Accordion title="Windows 上 tar 命令不存在">
    Windows 10 以上版本自带 tar。如果没有，可以使用 7-Zip 解压。
  </Accordion>
</AccordionGroup>

***

## 📝 命令速查表

| 步骤           | 命令                                                                                                   |
| ------------ | ---------------------------------------------------------------------------------------------------- |
| 检查 adb 版本    | `adb version`                                                                                        |
| 列出连接设备       | `adb devices`                                                                                        |
| 进入 shell     | `adb shell`                                                                                          |
| 切换应用用户       | `run-as com.liaobots.app`                                                                            |
| 查看 IndexedDB | `ls app_webview/Default/IndexedDB`                                                                   |
| 导出数据         | `adb exec-out run-as com.liaobots.app tar cf - app_webview/Default/IndexedDB > IndexedDB_backup.tar` |
| 解压           | `tar -xf IndexedDB_backup.tar`                                                                       |
