如何使用 TimeShift 备份和还原 Ubuntu Linux
备份 Timeshift
你是否曾经想过如何备份和还原 Ubuntu 或 Debian 系统？Timeshift 是一款自由开源工具，可让你创建文件系统的增量快照。你可以使用 RSYNC 或 BTRFS 两种方式创建快照。


![](/data/attachment/album/201911/27/235959fejmb080e7z0jnu0.jpg)


让我们深入研究并安装 Timeshift。在本教程，我们将安装在 Ubuntu 18.04 LTS 系统上。


### 在 Ubuntu / Debian Linux 上安装 TimeShift


TimeShift 尚未正式托管在 Ubuntu 和 Debian 仓库中。考虑到这一点，我们将运行以下命令来添加 PPA：



```
# add-apt-repository -y ppa:teejee2008/ppa
```

![Add timeshift repository](/data/attachment/album/201911/28/001558mvh2kqjmrzrkvs18.png)


接下来，使用以下命令更新系统软件包：



```
# apt update
```

成功更新系统后，使用以下 `apt` 命令安装 Timeshift：



```
# apt install timeshift
```

![apt install timeshift](/data/attachment/album/201911/28/001417qpv1v3yspypkl9vv.png)


### 准备备份存储设备


最佳实践要求我们将系统快照保存在系统硬盘之外的单独的存储卷上。对于本指南，我们将使用 16GB 闪存作为第二个驱动器，并在该驱动器上保存快照。



```
# lsblk | grep sdb
```

![lsblk sdb ubuntu](/data/attachment/album/201911/28/001421nrarp82frkrxjoqt.png)


为了将闪存用作快照的备份位置，我们需要在设备上创建一个分区表。运行以下命令：



```
# parted /dev/sdb  mklabel gpt
# parted /dev/sdb  mkpart primary 0% 100%
# mkfs.ext4  /dev/sdb1
```

![create partition table on drive ubuntu](/data/attachment/album/201911/28/001425rzbfdn9un4ioditt.jpg)


在 USB 闪存上创建分区表后，我们可以开始创建文件系统的快照！


### 使用 Timeshift 创建快照


要启动 Timeshift，使用应用程序菜单搜索 “Timeshift”。


![Access timeshift](/data/attachment/album/201911/28/001427b5swwersrye5lspd.jpg)


单击 Timeshift 图标，系统将提示你输入管理员密码。提供密码，然后单击验证。


![Authentication required](/data/attachment/album/201911/28/001431smjkwpzm46aa1c0m.jpg)


接下来，选择你喜欢的快照类型。


![Select rsync option](/data/attachment/album/201911/28/001431tfrfor6kizsis4os.jpg)


点击 “Next”。选择快照的目标驱动器。在这里，我的位置是标记为 `/dev/sdb` 的外部 USB 驱动器。


![Select snapshot location](/data/attachment/album/201911/28/001434m1kbo1q11q1qgqj1.png)


接下来，定义快照级别。级别是指创建快照的时间间隔。你可以选择每月、每周、每天或每小时的快照级别。


![Select snapshot levels](/data/attachment/album/201911/28/001437bcz28s8auc7zchf3.jpg)


点击 “Finish”。


在下一个窗口中，单击 “Create” 按钮开始创建快照。此后，系统将开始创建快照。


![Create snapshot](/data/attachment/album/201911/28/001439b32933jyj9z88m95.jpg)


最后，你的快照将显示如下：


![Snapshot created](/data/attachment/album/201911/28/001441qcqklak68c4cqcbk.jpg)


### 从快照还原 Ubuntu / Debian


创建系统快照后，现在让我们看看如何从同一快照还原系统。在同一个 Timeshift 中，单击快照，然后单击 “Restore” 按钮，如图所示。


![Restore snapshot](/data/attachment/album/201911/28/001444z3udab299qd39adi.jpg)


接下来，将提示你选择目标设备。保留默认选择，然后点击 “Next”。


![Select target device](/data/attachment/album/201911/28/001448ax09vvc0wzb96lz0.jpg)


恢复过程开始之前，Timeshift 将会试运行。


![Comparing files dry run](/data/attachment/album/201911/28/001454rico1n1p1112oi3p.jpg)


在下一个窗口中，点击 “Next” 按钮确认显示的操作。


![Confirm actions](/data/attachment/album/201911/28/001459iwaeriwejni8ra3b.jpg)


如图所示，你会看到警告和免责声明。点击 “Next” 初始化恢复过程。


此后，将开始还原过程，最后，系统之后将重新启动到快照定义的早期版本。


![Restoring snapshot](/data/attachment/album/201911/28/001507y44rsxkp7j90s1f7.png)


### 总结


如你所见，使用 TimeShift 从快照还原系统非常容易。在备份系统文件时，它非常方便，并允许你在系统故障时进行恢复。因此，不要害怕修改系统或弄乱系统。TimeShift 使你能够返回到一切运行平稳的时间点。




---


via: <https://www.linuxtechi.com/timeshift-backup-restore-ubuntu-linux/>


作者：[James Kiarie](https://www.linuxtechi.com/author/james/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


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


OK
Have you ever wondered how you can backup and restore your Ubuntu or Debian system ? TimeShift, a powerful backup and restore utility. TimeShift allows you to create system snapshots, providing an easy way to revert to a previous state in case of unexpected issues or system malfunctions. You can create a snapshot using either RSYNC or BTRFS.

With that. let’s delve in and install Timeshift. For this tutorial, we shall install timeshift on Ubuntu 22.04.

## Installing TimeShift on Ubuntu / Debian Linux

Timeshift is package is available in the default package repository (Universe) of Ubuntu and Debian system. So to install it, open the terminal and run following apt commands,

$ sudo apt update $ sudo apt install timeshift -y

## Preparing a Backup Storage Device

Best practice demands that we save the system snapshot on a separate storage volume, aside from the system’s hard drive. For this guide, we are using a 16 GB flash drive as the secondary drive on which we are going to save the snapshot.

# lsblk | grep sdb

For the flash drive to be used as a backup location for the snapshot, we need to create a partition table on the device. Run the following [parted command](https://www.linuxtechi.com/create-disk-partitions-parted-command-linux/):

# parted /dev/sdb mklabel gpt # parted /dev/sdb mkpart primary 0% 100% # mkfs.ext4 /dev/sdb1

After creating a partition table on the USB flash drive, we are all set to begin creating filesystem’s snapshots!

## Creating Ubuntu / Debian System Backup


To launch Timeshift, search timeshift from Activities,

Click on the Timeshift icon and the system will prompt you for the Administrator’s password. Provide the password and click on Authenticate.

Next, select your preferred snapshot type.

Click ‘**Next**’. Select the destination drive for the snapshot. In this case, my location is the external USB drive labeled as **/dev/sdb**

Next, define the snapshot levels. Levels refer to the intervals during which the snapshots are created. You can choose to have either monthly, weekly, daily, or hourly snapshot levels.

Click ‘Finish’

On the next Window, click on the ‘**Create**’ button to begin creating the snapshot. Thereafter, the system will begin creating the snapshot.

Finally, your snapshot will be displayed as shown

## Restoring Ubuntu / Debian from a Snapshot

Having created a system snapshot, let’s now see how you can restore your system from the same snapshot. On the same Timeshift window, click on the snapshot and click on the ‘**Restore**’ button as shown.

Next, you will be prompted to select the target device. leave the default selection and hit ‘**Next**’.

A dry run will be performed by Timeshift before the restore process commences.

In the next window, hit the ‘**Next**’ button to confirm actions displayed.

You’ll get a warning and a disclaimer as shown. Click ‘**Next**’ to initialize the restoration process.

Thereafter, the restore process will commence and finally, the system will thereafter reboot into an earlier version as defined by the snapshot.

#### Conclusion

As you have seen it quite easy to use TimeShift to restore your system from a snapshot. It comes in handy when backing up system files and allows you to recover in the event of a system fault. So don’t get scared to tinker with your system or mess up. TimeShift will give you the ability to go back to a point in time when everything was running smoothly.

Don BakerTimeshift by default does not backup the user /Home directory. You can enable that, but did not see that in your screenshots. Also for a full reinstall to a new disk it does not always get boot correct. It is awesome when it works as designed.

JasonIt doesn’t do that for a good reason. It’s meant as a system backup so that you can restore your system in the event something goes wrong but you still want to retain your personal data because it’s fine. The author recommends you not use it to backup your personal files but instead use another backup program.

Bramno support for external storage.

kimmeRead the “Preparing a backup storage device” part of this article?

GB GustafsonMissing: Suppose the system running TimeShift is unbootable. How to restore? This situation is an important use of the TimeShift snapshot.

The advice written above implies it is OK to run TimeShift on a broken OS. Kindly explain if that was the intent.

Expected: A full discussion for how to restore to a new bootable disk. If TimeShift does this reliably, then explain how.

Joe SFor clean install, disaster recovery, use Clonezilla to create an image of your system drive/partition after configuration of Timeshift. Use Timeshift and store your Timeshift backups on a different disk. If you crash your OS drive, restore from Clonezilla image and use Timeshift to bring OS back to latest working version.

JamesHi I’m a LInux newbie, I moved from Windows 10 to PopOS.

Question: When I use the commands:

# parted /dev/sdb mklabel gpt

# parted /dev/sdb mkpart primary 0% 100%

# mkfs.ext4 /dev/sdb1

Will that delete the drive I use? I have stuff on the drive I want to keep. Should I be using a empty from for the backup location?

Thank much

VicFicNope they are using the parted, a partition app, to partition the usb drive. No need to worry about your current drive.

TilmannHow to select a snapshot that is not made on this machine and is stored on an extern device ? That is impossible.

F DeveloperThanks buddy had some issues using the terminal but all is fine