Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fedora - Incremental backups with Btrfs snapshots

#1
Incremental backups with Btrfs snapshots

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 – 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.



https://www.sickgaming.net/blog/2020/09/...snapshots/
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Fedora - Fedora 33 is officially here! xSicKxBot 0 4 Yesterday, 09:34 PM
Last Post: xSicKxBot
  Fedora - Contribute at the Fedora Test Week for Kernel 5.9 xSicKxBot 0 6 10-25-2020, 12:22 AM
Last Post: xSicKxBot
  Fedora - Incremental backup with Butterfly Backup xSicKxBot 0 7 10-22-2020, 01:01 AM
Last Post: xSicKxBot
  Fedora - Recover your files from Btrfs snapshots xSicKxBot 0 45 10-05-2020, 07:17 PM
Last Post: xSicKxBot
  Fedora - Announcing the release of Fedora 33 Beta xSicKxBot 0 41 09-29-2020, 09:01 PM
Last Post: xSicKxBot
  Fedora - Now available: Fedora on Lenovo laptops! xSicKxBot 0 32 09-25-2020, 07:51 PM
Last Post: xSicKxBot
  Fedora - Ankur Sinha: How do you Fedora? xSicKxBot 0 48 09-11-2020, 02:22 PM
Last Post: xSicKxBot
  Fedora - Contribute at the Fedora Test Week for Btrfs xSicKxBot 0 71 08-26-2020, 01:20 PM
Last Post: xSicKxBot
  Fedora - Btrfs Coming to Fedora 33 xSicKxBot 0 78 08-24-2020, 01:28 PM
Last Post: xSicKxBot
  Fedora - Configure Fedora to practice and compose music xSicKxBot 0 66 08-22-2020, 12:44 PM
Last Post: xSicKxBot

Forum Jump:

Become a Patron!
[-]
Upcoming Events

[-]
Latest Threads
(Indie Deal) Tropico 6, Assassin's Creed...
Last Post: xSicKxBot
Today 04:41 PM
» Replies: 0
» Views: 3
gRPC performance improvements in .NET 5
Last Post: xSicKxBot
Today 04:40 PM
» Replies: 0
» Views: 2
News - Season of the Hunt
Last Post: xSicKxBot
Today 04:40 PM
» Replies: 0
» Views: 2
News - Rumour: Hyrule Warriors: Age Of C...
Last Post: xSicKxBot
Today 04:39 PM
» Replies: 0
» Views: 2
News - It’s Been Three Years Since We Fi...
Last Post: xSicKxBot
Today 04:39 PM
» Replies: 0
» Views: 2
Xbox Wire - This Week on Xbox: October 1...
Last Post: xSicKxBot
Today 04:39 PM
» Replies: 0
» Views: 2
News - Master your grasp of player psych...
Last Post: xSicKxBot
Today 04:38 PM
» Replies: 0
» Views: 2
News - PlayStation’s new (web) store, ge...
Last Post: xSicKxBot
Today 04:38 PM
» Replies: 0
» Views: 2
News - The Rapid Blaster Deco Is Firing ...
Last Post: Derrickcott
Today 09:53 AM
» Replies: 2
» Views: 806
Mobile - Crash Bandicoot: On the Run som...
Last Post: xSicKxBot
Today 09:46 AM
» Replies: 0
» Views: 2

[-]
Twitter

[-]
Sponsored
Get the Deal of the Week at RefurBees.com

Copyright © SickGaming.net 2012-2020