如何在 Ubuntu 上使用 ADB 备份 Android 数据
Android 备份 ADB
![](/data/attachment/album/201702/25/143411eas98czpbbaxaawq.jpg)


备份 Android 系统上的应用数据、文本信息等等是非常乏味的，有时还很昂贵。电子市场的许多应用都承诺可以备份数据，但效果不佳或者需要付昂贵费用。你是否知道有一种更好的方法可以来做这件事，并且在你的电脑上就可以完成？


Android 自带一套开发工具。有许多种开发工具，但人们最为感兴趣的项目是 ADB（或者叫做 <ruby> Android 调试桥 <rt>  Android Debug Bridge </rt></ruby>）。它允许用户通过命令行直接访问任何 Android 设备。有了这个工具，一切皆有可能 - 包括备份整个 Android 设备。在这篇文章中，将讨论如何在 Ubuntu 系统上完成这件事。


**注**：这篇教程是针对 Ubuntu Linux 系统的。不过， ADB 在 Windows 系统和 Mac 上也是可用的，也可以在这些平台上对 Android 数据进行备份。[下载针对 Windows 和 Mac 的 ADB 版本。](https://developer.android.com/studio/command-line/adb.html)


### 安装 ADB 并启用 USB 调试


打开一个终端窗口，然后输入下面的命令来安装 ADB，它将与 Android 进行会话。



```
sudo apt install adb

```

![](/data/attachment/album/201702/25/143421owihmhmxoszmxm2g.jpg)


在系统上安装好 ADB 工具以后，需要在 Android 内部启动调试。首先打开 Android 的<ruby> 设置 <rt>  Settings </rt></ruby>区域。然后一直滚动到底部找到“<ruby> 关于手机 <rt>  About Phone </rt></ruby>”并点击。这将打开“<ruby> 电话状态 <rt>  Phone status </rt></ruby>”页。在这一页面上再次滚动到底部，找到“<ruby> 版本号 <rt>  Build number </rt></ruby>”并点击七次，从而启动开发者模式。


![](/data/attachment/album/201702/25/143440yhhj2hyjcjqjh23b.jpg)


为了进入<ruby> 开发者设置 <rt>  Developer Settings </rt></ruby>，按设备上的返回键返回上一页面。在“设置”中将会出现一个新的选项：“<ruby> 开发者选项 <rt>  Developer options </rt></ruby>”。点击它进入开发者设置区域。滚动页面直到看到 “<ruby> Android 调试 <rt>  Android debugging </rt></ruby>”（或它的一些其他名称），点击它启用设置。


### 备份


使用 ADB 创建一个备份就如同运行一个命令一样简单。首先，用一根与 Android 设备匹配的 USB 线将 Android 设备连接到电脑上。然后打开终端运行下面的命令：



```
adb start-server

```

这将启动 ADB 服务器。运行这个命令时，要快速解锁 Android 设备，因为 ADB 将强制出现一个确认窗口，必须选择接受后才可继续。


![](/data/attachment/album/201702/25/143507y116f5151mfkh511.jpg)


要启动备份进程，打开终端，然后执行下面的备份命令。该命令将读取 Android 上的文本信息以及其他应用数据，然后存入加密文件中。



```
adb backup -apk -shared -all -f backup-file.adb

```

![](/data/attachment/album/201702/25/143519b8vennfan8eaegaa.jpg)


当运行备份命令时，Android 会在启动备份进程前提示用户查看 Android 并设置加密文件的密码。请输入一个强壮而容易记住的密码。然后，点击“备份我的数据”按钮。备份过程将会花费一定时间。备份完成以后，在目录 `/home/username/` 中会出现一个叫做 `backup-file.adb` 的文件。


### 恢复备份


要恢复备份，首先启用 ADB 服务器（像上面提到的一样），然后运行下面这个命令来还原备份数据：



```
adb restore backup-file.adb

```

![](/data/attachment/album/201702/25/143547gqeio7iz4f7l3qo3.jpg)


再次转到 Android， 因为 ADB 将提示用户输入密码。这次，不是创建一个密码，而是需要输入之前创建的那个密码。在点击 “<ruby> 恢复我的数据 <rt>  restore my data </rt></ruby>” 以后，恢复进程就开始了。耐心点，因为这可能需要一定时间。


### 结论


没有多少 Android 用户知道这样备份数据，但是 ADB 的确很强大。利用它甚至可以获得对设备的 root 访问。事实上，利用这个工具还可以做很多的事情，需要更多的文章来讨论它。


你还知道 ADB 可以用来干什么吗？请在下面的评论区告知我们！




---


via: <https://www.maketecheasier.com/back-up-android-data-adb-ubuntu/>


作者：[Derrik Diener](https://www.maketecheasier.com/author/derrikdiener/) 译者：[ucasFL](https://github.com/ucasFL) 校对：[jasminepeng](https://github.com/jasminepeng)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![](https://www.maketecheasier.com/assets/uploads/2017/02/adb-feature-image.jpg)

Backing up app data, text messages and the like in Android can be incredibly tedious, and sometimes costly too. Many apps on the Play Store promise to back up your data but are hit and miss or cost an arm and a leg. Did you know that there’s a better way to do this and that it can all be done on your computer?

Android comes with a set of development tools. There are many, but the main item of interest is known as ADB (or Android Debug Bridge). It allows a user to gain direct command-line access to any Android device. With this tool anything is possible – including backing up an entire Android device! Here’s how to do it on Ubuntu.

**Note**: this tutorial is done with a focus on Ubuntu Linux. However, ADB is available on Windows and macOS, and the backup process can be on those platforms as well. [Download for windows and Mac](https://developer.android.com/studio/command-line/adb.html).

## Installing ADB and Enabling USB Debugging

Open a terminal window and enter this command to install the ADB tool that will interact with Android.

sudo apt install adb

![adb-install-adb-ubuntu adb-install-adb-ubuntu](https://www.maketecheasier.com/assets/uploads/2017/02/adb-install-adb-ubuntu.jpg)

With the ADB tool installed on the system, debugging will need to be enabled inside of Android. Start by opening the Settings area of Android. Scroll all the way to the bottom to find “About Phone” and select it. This opens a “Phone status” page. On this page scroll to the bottom again, find “Build number’ and tap on it seven times. This will enable Developer Mode.

![adb-about-phone adb-about-phone](https://www.maketecheasier.com/assets/uploads/2017/02/adb-about-phone.jpg)

To get to Developer Settings, press the Back button on the device to go back a page. A new option in settings will appear: “Developer options.” Tap on it to enter the developer settings area. Scroll through till you see “Android debugging” (or some variation of it), and tap it to enable the setting.

## Backing Up

Creating a backup with ADB is as simple as running one command. First, take the USB cable that corresponds with the Android device, and plug it into the PC. Then, go to a terminal and enter the following:

adb start-server

This will start the Android Debugging Bridge server. With this command running, quickly unlock the Android device, as ADB will force a confirmation window that must be accepted to continue.

![adb-all-usb-debugging adb-all-usb-debugging](https://www.maketecheasier.com/assets/uploads/2017/02/adb-all-usb-debugging.jpg)

To start the backup process, go to the terminal and enter this backup command. It’ll take text messages and other bits of app data, and store it into an encrypted file.

adb backup -apk -shared -all -f backup-file.adb

![adb-full-backup adb-full-backup](https://www.maketecheasier.com/assets/uploads/2017/02/adb-full-backup.jpg)

Running the backup command will prompt the user to look at Android and set a password for the file before Android will run the backup procedure. Enter a strong, memorable password. Then, select the “back up my data” button. The backup may take some time, but when it is finished, a file named “backup-file.ab” will be in “/home/username/.”

## Restoring

To restore the backup, enable the ADB server (like mentioned above) and run this command to restore the data.

adb restore backup-file.ab

![adb-full-restore adb-full-restore](https://www.maketecheasier.com/assets/uploads/2017/02/adb-full-restore.jpg)

Once again, go to Android, as ADB will prompt the user to enter a password. This time, instead of creating a password, all that is required is entering the one created from earlier. After that select “restore my data,” and the restoration process will begin. Be patient, as this may take a bit of time.

## Conclusion

Not many Android users know this, but ADB is incredibly powerful. It can be used for more than gaining root access on a device. In fact, there are so many things that can be done with this tool, it’d take more than one article to cover all of it!

What tricks do you know with ADB? Let us know below!

Our latest tutorials delivered straight to your inbox