📜 ⬆️ ⬇️

Just backup btrfs

I have been looking at btrfs for a long time, I used it for about a year even on disks with various media data, but did not use the extended functionality of this remarkable file system.

But there was an update - two new SSDs, it was decided during the system transfer to switch to btrfs at the same time.
Everything is great - RAID0 for data RAID1 for metadata by means of the file system, compression on the fly, root in one sub-volume (subvolume), home folder in another, web sites in the third. All this is loaded directly from UEFI to the Linux EFI stub without GRUB and other downloaders, it works quickly and conveniently.
And so it came to snapshots, I wanted to use them for backup sub-volumes using the same btrfs driver.

The search yields several relevant solutions, but some solutions are too cumbersome (synchronization of backups through the network, creating some repositories, nested streams, etc.) and impose their architecture, others do not have an adequate backup rotation (you can specify only one spacing and number of copies in it).
')
The decision is made - to be a new tool!

And what happened?


It turned out a small PHP script that, when launched, reads a configuration from a simple JSON file of the form:

[ { "source_mounted_volume" : "/", "destination_within_partition" : "/backup/root", "date_format" : "Ym-d_H:i:s", "keep_snapshots" : { "hour" : 60, "day" : 24, "month" : 30, "year" : 48 } }, { "source_mounted_volume" : "/home", "destination_within_partition" : "/backup/home", "date_format" : "Ym-d_H:i:s", "keep_snapshots" : { "hour" : 120, "day" : 48, "month" : 60, "year" : 96 } } ] 

And creates a snapshot along the specified path, as well as when restarting it controls the number of snapshots, removing obsolete ones.

In this configuration example, we get the folder / backup, inside which will be separate folders for snapshots of the root and home folder. Snapshots are created only for reading, so we have direct access to any snapshot with preserving access rights and without danger of damaging the created snapshot.

Since btrfs supports CoW (Copy on Write), the location occupied by the snapshot is determined by the number and size of the modified files from the last snapshot. When deleting a snapshot, all files that are only in it are deleted anywhere else, freeing up free space.

Total we have instant access to any snapshot and saving of occupied space (which is doubly true in the presence of file system compression).

Plans


Add dropping the last snapshot (incrementally) additionally to another btrfs partition, otherwise it’s not quite a backup, but just a time machine.

It will be necessary to add in the readme the setting for creating snapshots before installing / removing / updating packages (there will already need the help of the community, since I use Ubuntu, and I don’t know how to do this for systems with RPM or something more exotic).

Would it be nice to create deb / rpm /? packages for popular (and not so) distributions, but I didn’t have to do this before, I don’t know what and how.

Perhaps something else tell me :)

Where to get


https://github.com/nazar-pc/just-backup-btrfs

I hope the article and the solution will be useful, share recipes for using btrfs in the comments.

Source: https://habr.com/ru/post/243727/


All Articles