mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
translated
This commit is contained in:
parent
dad0028edb
commit
02dac06d4c
@ -1,93 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Incremental backups with Btrfs snapshots)
|
||||
[#]: via: (https://fedoramagazine.org/btrfs-snapshots-backup-incremental/)
|
||||
[#]: author: (Alessio https://fedoramagazine.org/author/alciregi/)
|
||||
|
||||
Incremental backups with Btrfs snapshots
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
Snapshots are an interesting feature of Btrfs. A snapshot is a copy of a subvolume. Taking a snapshot is immediate. However, taking a snapshot is not like performing a _rsync_ or a _cp_, and a snapshot doesn’t occupy space as soon as it is created.
|
||||
|
||||
Editors note: From the [BTRFS Wiki][2] – A snapshot is simply a subvolume that shares its data (and metadata) with some other subvolume, using Btrfs’s COW capabilities.
|
||||
|
||||
Occupied space will increase alongside the data changes in the original subvolume or in the snapshot itself, if it is writeable. Added/modified files, and deleted files in the subvolume still reside in the snapshots. This is a convenient way to perform backups.
|
||||
|
||||
### Using snapshots for backups
|
||||
|
||||
A snapshot resides on the same disk where the subvolume is located. You can browse it like a regular directory and recover a copy of a file as it was when the snapshot was performed. By the way, a snapshot on the same disk of the snapshotted subvolume is not an ideal backup strategy: if the hard disk broke, snapshots will be lost as well. An interesting feature of snapshots is the ability to send them to another location. The snapshot can be sent to an external hard drive or to a remote system via SSH (the destination filesystems need to be formatted as Btrfs as well). To do this, the commands _btrfs send_ and _btrfs receive_ are used.
|
||||
|
||||
### Taking a snapshot
|
||||
|
||||
In order to use the _send_ and the _receive_ commands, it is important to create the snapshot as read-only, and snapshots are writeable by default.
|
||||
|
||||
The following command will take a snapshot of the _/home_ subvolume. Note the _-r_ flag for readonly.
|
||||
|
||||
sudo btrfs subvolume snapshot -r /home /.snapshots/home-day1
|
||||
|
||||
Instead of day1, the snapshot name can be the current date, like _home-$(date +%Y%m%d)_. Snapshots look like regular subdirectories. You can place them wherever you like. The directory _/.snapshots_ could be a good choice to keep them neat and to avoid confusion.
|
||||
|
||||
Editors note: Snapshots will not take recursive snapshots of themselves. If you create a snapshot of a subvolume, every subvolume or snapshot that the subvolume contains is mapped to an empty directory of the same name inside the snapshot.
|
||||
|
||||
### Backup using btrfs send
|
||||
|
||||
In this example the destination Btrfs volume in the USB drive is mounted as _/run/media/user/mydisk/bk_ . The command to send the snapshot to the destination is:
|
||||
|
||||
sudo btrfs send /.snapshots/home-day1 | sudo btrfs receive /run/media/user/mydisk/bk
|
||||
|
||||
This is called initial bootstrapping, and it corresponds to a full backup. This task will take some time, depending on the size of the _/home_ directory. Obviously, subsequent incremental sends will take a shorter time.
|
||||
|
||||
### Incremental backup
|
||||
|
||||
Another useful feature of snapshots is the ability to perform the send task in an incremental way. Let’s take another snapshot.
|
||||
|
||||
sudo btrfs subvolume snapshot -r /home /.snapshots/home-day2
|
||||
|
||||
In order to perform the send task incrementally, you need to specify the previous snapshot as a base and this snapshot has to exist in the source and in the destination. Please note the _-p_ option.
|
||||
|
||||
sudo btrfs send -p /.snapshot/home-day1 /.snapshot/home-day2 | sudo btrfs receive /run/media/user/mydisk/bk
|
||||
|
||||
And again (the day after):
|
||||
|
||||
sudo btrfs subvolume snapshot -r /home /.snapshots/home-day3
|
||||
|
||||
sudo btrfs send -p /.snapshot/home-day2 /.snapshot/home-day3 | sudo btrfs receive /run/media/user/mydisk/bk
|
||||
|
||||
### Cleanup
|
||||
|
||||
Once the operation is complete, you can keep the snapshot. But if you perform these operations on a daily basis, you could end up with a lot of them. This could lead to confusion and potentially a lot of used space on your disks. So it is a good advice to delete some snapshots if you think you don’t need them anymore.
|
||||
|
||||
Keep in mind that in order to perform an incremental send you need at least the last snapshot. This snapshot must be present in the source and in the destination.
|
||||
|
||||
sudo btrfs subvolume delete /.snapshot/home-day1
|
||||
|
||||
sudo btrfs subvolume delete /.snapshot/home-day2
|
||||
|
||||
sudo btrfs subvolume delete /run/media/user/mydisk/bk/home-day1
|
||||
|
||||
sudo btrfs subvolume delete /run/media/user/mydisk/bk/home-day2
|
||||
|
||||
Note: the day 3 snapshot was preserved in the source and in the destination. In this way, tomorrow (day 4), you can perform a new incremental _btrfs send_.
|
||||
|
||||
As some final advice, if the USB drive has a bunch of space, you could consider maintaining multiple snapshots in the destination, while in the source disk you would keep only the last one.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/btrfs-snapshots-backup-incremental/
|
||||
|
||||
作者:[Alessio][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/alciregi/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2020/08/butterfs-816x346.png
|
||||
[2]: https://btrfs.wiki.kernel.org/index.php/SysadminGuide#Snapshots
|
@ -0,0 +1,93 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Incremental backups with Btrfs snapshots)
|
||||
[#]: via: (https://fedoramagazine.org/btrfs-snapshots-backup-incremental/)
|
||||
[#]: author: (Alessio https://fedoramagazine.org/author/alciregi/)
|
||||
|
||||
使用 Btrfs 快照进行增量备份
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
快照是 Btrfs 的一个有趣的功能。快照是一个子卷的副本。生成快照是立即的。然而,生成快照与执行 _rsync_ 或 _cp_ 不同,快照并不是一创建就会占用空间。
|
||||
|
||||
编者注:来自 [BTRFS Wiki][2 ]:快照是一个简单的子卷,它使用 Btrfs 的 COW 功能与其他子卷共享其数据(和元数据)。
|
||||
|
||||
如果它是可写的,占用的空间将随着原始子卷或快照本身的数据变化而增加。子卷中已添加/修改的文件和已删除的文件仍然存在于快照中。这是一种方便的备份方式。
|
||||
|
||||
### 使用快照进行备份
|
||||
|
||||
快照保存在子卷所在的同一磁盘上。你可以像浏览普通目录一样浏览它,并按照生成快照时的状态恢复文件的副本。顺便说一下,在被快照子卷的同一磁盘上做快照并不是一个理想的备份策略:如果硬盘坏了,快照也会丢失。快照的一个有趣的功能是可以将快照发送到另一个位置。快照可以被发送到外部硬盘或通过 SSH 发送到远程系统(目标文件系统也需要格式化为 Btrfs)。要实现这个,需要使用命令 _btrfs send_ 和 _btrfs receive_。
|
||||
|
||||
### 生成快照
|
||||
|
||||
要使用 _send_ 和 _receive_ 命令,重要的是要将快照创建为只读,而快照默认是可写的。
|
||||
|
||||
下面的命令将对 _/home_ 子卷进行快照。请注意 _-r_ 标志为只读。
|
||||
|
||||
sudo btrfs subvolume snapshot -r /home /.snapshots/home-day1
|
||||
|
||||
快照的名称可以是当前日期,而不是 day1,比如 _home-$(date +%Y%m%d)_。快照看起来像普通的子目录。你可以把它们放在任何你喜欢的地方。目录 _/.snapshots_ 可能是一个不错的选择,以保持它们的整洁和避免混淆。
|
||||
|
||||
编者注:快照不会对自己进行递归快照。如果你创建了一个子卷的快照,子卷所包含的每一个子卷或快照都会被映射到快照里面的一个同名的空目录。
|
||||
|
||||
### 使用 btrfs send 进行备份
|
||||
|
||||
在本例中,U 盘中的目标 Btrfs 卷被挂载为 _/run/media/user/mydisk/bk_。发送快照到目标卷的命令是:
|
||||
|
||||
sudo btrfs send /.snapshots/home-day1 | sudo btrfs receive /run/media/user/mydisk/bk
|
||||
|
||||
这被称为初始启动,它相当于一个完整的备份。这个任务需要一些时间,取决于 _/home_ 目录的大小。显然,后续的增量发送只需要更短的时间。
|
||||
|
||||
### 增量备份
|
||||
|
||||
快照的另一个有用的功能是能够以增量的方式执行发送任务。让我们再来生成一个快照。
|
||||
|
||||
sudo btrfs subvolume snapshot -r /home /.snapshots/home-day2
|
||||
|
||||
为了执行增量发送任务,需要指定上一个快照作为基础,并且这个快照必须存在于源文件和目标文件中。请注意 _-p_ 选项。
|
||||
|
||||
sudo btrfs send -p /.snapshot/home-day1 /.snapshot/home-day2 | sudo btrfs receive /run/media/user/mydisk/bk
|
||||
|
||||
再来一次(之后一天):
|
||||
|
||||
sudo btrfs subvolume snapshot -r /home /.snapshots/home-day3
|
||||
|
||||
sudo btrfs send -p /.snapshot/home-day2 /.snapshot/home-day3 | sudo btrfs receive /run/media/user/mydisk/bk
|
||||
|
||||
### 清理
|
||||
|
||||
操作完成后,你可以保留快照。但如果你每天都执行这些操作,你可能最终会有很多快照。这可能会导致混乱,并可能会在你的磁盘上使用大量的空间。因此,如果你认为你不再需要一些快照,删除它们是一个很好的建议。
|
||||
|
||||
请记住,为了执行增量发送,你至少需要最后一个快照。这个快照必须存在于源文件和目标文件中。
|
||||
|
||||
sudo btrfs subvolume delete /.snapshot/home-day1
|
||||
|
||||
sudo btrfs subvolume delete /.snapshot/home-day2
|
||||
|
||||
sudo btrfs subvolume delete /run/media/user/mydisk/bk/home-day1
|
||||
|
||||
sudo btrfs subvolume delete /run/media/user/mydisk/bk/home-day2
|
||||
|
||||
注意:第 3 天的快照被保存在源文件和目标文件中。这样,明天(第 4 天),你就可以执行新的增量 _btrfs send_。
|
||||
|
||||
最后的建议是,如果 U 盘的空间很大,可以考虑在目标盘中保留多个快照,而在源盘中只保留最后一个快照。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/btrfs-snapshots-backup-incremental/
|
||||
|
||||
作者:[Alessio][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/alciregi/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://fedoramagazine.org/wp-content/uploads/2020/08/butterfs-816x346.png
|
||||
[2]: https://btrfs.wiki.kernel.org/index.php/SysadminGuide#Snapshots
|
Loading…
Reference in New Issue
Block a user