Arch Linux Timeshift 完整教程

什么是 Timeshift

Timeshift 是 Linux 下最流行的系统快照工具之一,原由 Tony George 开发,现为 Linux Mint Xapp 项目的一部分。

作用类似于:

  • Windows 系统还原
  • macOS Time Machine(仅系统部分)

可在以下情况快速回滚:

  • pacman 更新后系统损坏
  • 安装错误驱动导致无法进入桌面
  • 修改配置导致系统异常
  • 内核升级失败
  • 引导器损坏

注意: Timeshift 设计用于保护系统文件和设置,不是个人数据备份工具。默认排除 /home/ 用户数据,确保恢复时不会覆盖你的文档。

用户文件建议使用:

  • rsync / borg / restic / Syncthing

安装 Timeshift

sudo pacman -S timeshift

Timeshift 依赖 cron 进行定时调度,安装后启用:

sudo systemctl enable --now cronie.service

也可以使用 timeshift-systemd-timerAUR 替代 cronie。

验证安装:

timeshift --version

查看磁盘布局

lsblk -f

输出示例(ext4):

nvme0n1
├─nvme0n1p1 vfat
├─nvme0n1p2 ext4 /
└─nvme0n1p3 ext4 /home

Btrfs 示例:

nvme0n1
├─nvme0n1p1 vfat
└─nvme0n1p2 btrfs  /@  /@home

Timeshift Btrfs 模式要求 @@home 子卷布局,其他布局不兼容。


选择工作模式

RSYNC 模式(推荐新手)

适用于所有文件系统:ext4、xfs、f2fs、btrfs。

特点:通用、稳定、不依赖文件系统。

BTRFS 模式

仅适用于 Ubuntu 风格子卷布局(@@home)。

特点:创建快照秒级完成、占用空间极小、恢复速度快。

如果分区是 Btrfs 但没有 @/@home 布局,请先转换,参考 ArchWiki - Timeshift


首次配置

启动配置向导:

sudo timeshift-launcher

或者直接启动 GTK 界面:

sudo timeshift-gtk

首次运行会引导选择:

  1. 快照类型 — RSYNC 或 BTRFS
  2. 快照存储位置 — 默认存储在系统根分区 /timeshift,推荐存到独立数据盘或大容量非系统分区

推荐快照策略

Timeshift 支持五个快照层级:Hourly、Daily、Weekly、Monthly、Boot。

层级保留数量说明
Daily7最近 7 天
Weekly4最近 4 周
Monthly3最近 3 个月
Hourly0关闭
Boot0关闭

Boot 快照在系统启动 10 分钟后创建,适合频繁测试重启的场景。


推荐过滤器

Timeshift → Settings → Filters

排除以下目录(避免快照膨胀和污染恢复):

# 用户数据
/home/**

# 临时/运行时
/tmp/**
/var/tmp/**
/run/**
/proc/**
/sys/**
/dev/**

# 缓存/日志(可重新生成)
/var/cache/**
/var/log/**
/var/lib/systemd/coredump/**

# 挂载点
/mnt/**
/media/**

# 应用数据
/var/lib/docker/**
/var/lib/containerd/**
/var/lib/flatpak/**
/var/lib/libvirt/images/**
/var/lib/lxd/**

# 服务数据
/opt/**
/srv/**
/var/www/**
/var/spool/**
/var/mail/**

# 回收站
/.local/share/Trash/**

# Swap 文件
/swap.img

推荐 timeshift.json

配置文件位置:/etc/timeshift/timeshift.json

首次配置后自动生成,也可以复制模板 /etc/timeshift/default.json 后手动编辑。

{
  "backup_device_uuid" : "ebe7d1b8-80ce-4390-81ed-ee34dbf0e63d",
  "parent_device_uuid" : "",
  "do_first_run" : "false",
  "btrfs_mode" : "false",
  "include_btrfs_home_for_backup" : "false",
  "include_btrfs_home_for_restore" : "false",
  "stop_cron_emails" : "true",
  "schedule_monthly" : "true",
  "schedule_weekly" : "true",
  "schedule_daily" : "true",
  "schedule_hourly" : "false",
  "schedule_boot" : "false",
  "count_monthly" : "3",
  "count_weekly" : "4",
  "count_daily" : "7",
  "count_hourly" : "0",
  "count_boot" : "0",
  "date_format" : "%Y-%m-%d %H:%M:%S",
  "exclude" : [
    "/home/**",
    "/proc/**",
    "/sys/**",
    "/dev/**",
    "/run/**",
    "/tmp/**",
    "/var/tmp/**",
    "/mnt/**",
    "/media/**",
    "/var/cache/**",
    "/var/log/**",
    "/var/lib/systemd/coredump/**",
    "/swap.img",
    "/var/lib/docker/**",
    "/var/lib/containerd/**",
    "/var/lib/flatpak/**",
    "/var/lib/libvirt/images/**",
    "/var/lib/lxd/**",
    "/opt/**",
    "/srv/**",
    "/var/www/**",
    "/.local/share/Trash/**",
    "/var/spool/**",
    "/var/mail/**",
    "/.Trash-1000"
  ]
}

创建快照

手动创建:

sudo timeshift --create

添加备注:

sudo timeshift --create --comments "Before pacman -Syu"

查看所有快照:

sudo timeshift --list

脚本中使用建议加 --scripted 参数,避免交互提示。


删除快照

查看快照列表:

sudo timeshift --list

删除指定快照:

sudo timeshift --delete --snapshot '2026-06-18_12-00-01'

删除全部:

sudo timeshift --delete-all

系统恢复

图形界面恢复

sudo timeshift-launcher

选择快照 → Restore → 按向导完成。

命令行恢复

sudo timeshift --restore

按提示选择快照,或直接指定:

sudo timeshift --restore --snapshot '2026-06-18_12-00-01'

系统无法启动时恢复

方式一:Live 环境恢复(推荐)

用 Arch ISO 启动,安装 Timeshift:

sudo pacman -S timeshift

运行 Timeshift GUI 选择快照恢复即可,无需 chroot。

方式二:arch-chroot 恢复

sudo mount /dev/nvme0n1p2 /mnt
arch-chroot /mnt
timeshift --list
timeshift --restore
reboot

方式一更可靠,因为 Timeshift 在 chroot 环境下可能无法正确处理某些操作(如 EFI 分区挂载、GRUB 重装)。


GRUB 与 Btrfs 快照

如果使用 Btrfs 模式,可安装 grub-btrfs 让快照出现在 GRUB 启动菜单:

sudo pacman -S grub-btrfs inotify-tools

配置自动更新:

sudo systemctl edit --full grub-btrfsd

ExecStart 改为:

ExecStart=/usr/bin/grub-btrfsd --syslog --timeshift-auto

启用服务:

sudo systemctl enable --now grub-btrfsd

之后每次创建快照,GRUB 菜单自动多出一个"快照启动项",可直接启动进快照状态。


Wayland 问题

timeshift-launcher 在 Wayland 下会报 xhost: command not found,因为该命令需要以 root 权限连接 X 显示服务。

解决方法:

sudo pacman -S xorg-xhost
xhost +SI:localuser:root

这条命令赋予 root 用户访问当前 X 屏幕的权限。多用户系统需谨慎。

安装后即可正常启动 sudo timeshift-launcher


常用命令

操作命令
创建快照sudo timeshift --create --comments "备注"
查看快照sudo timeshift --list
恢复快照sudo timeshift --restore --snapshot "名称"
删除快照sudo timeshift --delete --snapshot "名称"
删除全部sudo timeshift --delete-all
检查配置sudo timeshift --check
查看配置cat /etc/timeshift/timeshift.json
查看版本timeshift --version

最佳实践

更新系统前:

sudo timeshift --create --comments "Before update"

安装 NVIDIA 驱动前:

sudo timeshift --create --comments "Before NVIDIA"

升级内核前:

sudo timeshift --create --comments "Before kernel upgrade"

习惯:

升级前创建快照 → 出问题恢复 → 继续工作