Use btrfs snapshot as backup solution

What am I thinking is:

I have sdd and hdd.

I would like to have / and /home as separate partitions on SDD
HDD is going to be backup drive.

Installation - architect

Lets say that there is a big update for manjaro.
I would like to create snapshot (probably read only) of / on my HDD
Assume that something during update goes wrong.

First thing that came to my mind is tu use rsync
example:
rsync -aAXv /......./backup/ /

  1. Can it work?

  2. Any better way?

  3. While m-a installation there is an option to do something with root and home (@/, @home). Don't remember the name but If I'm correct it mounts root and home as subvolumes. Is it necessary to my "backup" solution?

  4. If I'm correct btrfs COW works like that:
    I have /data/subvolume1 with files f1, f2, f3...
    When I create snapshot of subvolume1 on HDD there are no f1,...,f3 copy on HDD until I change or delete them from subvolume1.
    So during system update I'll not have a real backup on my HDD but only files that were changed during an update.
    So I can't just copy files from snapshot to root because It's not an exact copy. This is where rsync idea came.

I'm using btrfs as well, but not with subvolumes. I've got a very elaborate partition table with individual partitions for various branches of the filesystem hierarchy ─ I've reordered them below in partition order and I've omitted the tmpfs entries

Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda1      vfat      511M  280K  511M   1% /boot/efi
/dev/sda2      ext4      488M  119M  334M  27% /boot
/dev/sda3      btrfs     1.0G   37M  881M   5% /
/dev/sda4      btrfs      22G  7.7G   14G  36% /usr
/dev/sda5      btrfs     512M   17M  435M   4% /usr/local
/dev/sda6      btrfs     2.0G   17M  1.8G   1% /opt
/dev/sda8      btrfs     400G   60G  340G  15% /srv
/dev/sda9      btrfs     450G  1.8G  447G   1% /home
/dev/sda11     btrfs      20G  2.6G   18G  14% /var

Other than that, my setup is somewhat similar in that I have my system installed on an SSD and that I use a HDD for backups.

The tool I use for making backups is TimeShift ─ it's in the repository, and it's the preferred backup tool for Manjaroos. :wink:

It can do the btrfs snapshot thing, or it can use rsync. I've set it up for the latter, and I only make backups manually ─ no scheduling. Works like a charm, and timeshift can also be used from the command line if need be. :wink:

I'm aware of timeshift but if I remember it can do snapshots only on the same disk (I may by wrong). Rsync works good.
And do you have COW on home enabled?

Timeshift with rsync would save to the HDD in incremental snapshots as that is what I use myself on removable drives. I'm not sure about btrfs mode.

2 Likes

Yes, I have not disabled copy-on-write anywhere. And it stores the backups on a partition on my HDD (/dev/sdb2).

1 Like

I use it too, but it is not really a backup solution.
From dev.:
If you need a tool to backup your documents and files please take a look at the excellent [BackInTime](https://github.com/bit-team/backintime) application which is more configurable and provides options for saving user files.
If this volume die, no backup :wink: .
Next I use


with btrfs.

My try to restore a backup from hdd btrfs-system with rsync back to ssd with btrfs failed. (???)
I still have to do some research, but at least my /home is in "security" with all its data ( you must set filter for backup /home in timeshift - rsync -).

(Nothing is safe except death, I know :wink: )

Just my 2 cents:

I do rsync backups of root and home to a ZFS raid with

rsync -aAxXhH /source /dest

And because /dest is on a ZFS filesystem I do frequent snapshots of /dest. This gives me a history of system backups. And the rsync command creates a identical copy of /source. Which makes /dest a drop-in replacement for /source

The only thing that needs manual attention in case you have to do a full restore are the directories /dev, /proc, /srv and /sys,

1 Like

A snapshot is not a backup, but btrfs snapshots can be "backupped" with the commands btrfs send and btrfs receive; for a more comfortable solution there is btrbk in AUR.

For the rest, as mbod said.
My rsync parameters are -avhi --progress --delete btw.

1 Like

I'm completely aware of this.
Backup is backup. I thought about snapshots more like an additional insurance before system update for example.

Apart from the fact that I am not an expert of manjaro archtect I do not give help by private messages.
Sorry :slight_smile:

You made may day, I searched for this :slight_smile:

2 Likes

Well snapshots can be used for backups as I mentioned above.
I think @TomZ uses that solution so he might give you more info (in public of course).

EDIT: also read this, if you haven't done so:

A bit further down, TomZ explains how to use the send/receive commands.

1 Like

I think there are multiple things a backup allows us to do, and when we talk about snapshots, we need to be a little more specific.

Backups should allow us to:

  1. Return to prior point in time - access older versions of files
  2. Return to prior point in time - recover deleted files
  3. Recover from hardware failure
  4. Recover from a catastrophic loss such as a break-in

snapshots on a single machine do an excellent job at numbers 1 and 2. Not only are can you take a snapshot in very little time, but they are space efficient in most cases so you can afford to keep many recent snapshots. They are also very easy to access and restore.

To achieve #3, you need to get your snapshots to a different location. This can be accomplished with snapshot replication as @torvic describes above. Simply replicate your snapshots to another machine/drive. Not only will that give you a second copy of your data, it will provide a copy of all your snapshots so you have the ability to recover point-in-time data. Again, this is very time and space efficient.

snapshots + snapshot replication should be better than an rsync replica in most cases. The only disadvantage is that you need the same file system on both side. i.e. you need your source and target file system to be btrfs.

3 Likes

Spot on.

I mean you use btrfs because of its advanced features and it makes sense to make use of them.
There are a few tools in the repos/AUR that can help with that (snapper, snap-pac, btrbk, bedup, etc.), but the best way to "learn" btrfs is to read the official Wiki and the manpages.

2 Likes

Thanks for the ping @torvic, I do indeed use snapshots and btrfs send every day and it has served me well over the months.

My backup script does essentially the following:

  1. Create a snapshot of @ and @home, which takes less than a second
  2. An incremental backup of both snapshots to my second internal drive HDD via btrfs send / receive
  3. A backup via Borg to my file server

Steps 2 and 3 are optional. Given that 1 is instant and 2 is usually done in minutes that's what I will do before every OS update.

And aside from Borg I am not using any helper tools such as Timeshift, want to stay in control, hence I use straight forward btrfs commands.

4 Likes