teejee2008 / timeshift

System restore tool for Linux. Creates filesystem snapshots using rsync+hardlinks, or BTRFS snapshots. Supports scheduled snapshots, multiple backup levels, and exclude filters. Snapshots can be restored while system is running or from Live CD/USB.
GNU Lesser General Public License v3.0
4.69k stars 282 forks source link

[Question] BTRFS-mode, /Home contains sytem & app config files by default #692

Open zilexa opened 3 years ago

zilexa commented 3 years ago

Ubuntu Budgie 20.10, BTRFS with @/ and @/Home subvolumes (defaults).

I previously used EXT4 and RSync-mode, excluding personal folders and temp folders:

    "/home/asterix/.cache/***",
    "/home/asterix/Documents/***",
    "/home/asterix/Downloads/***",
    "/home/asterix/Media/***",
    "/home/asterix/Music/***",
    "/home/asterix/Photos/***",
    "+ /home/asterix/**",
    "/root/**"

I restored rsync snapshots frequently and it worked perfectly: a fresh system while still having the latest versions of personal files and also personal files that were created after the first snapshot.

--> The rest of the /home folder actually contains lots of configuration files, for both the system GUI of the OS and for basically all applications. They cannot be considered personal files. Excluding the entire /home folder would not make sense if you need a complete system backup experience. That is why the rest of the /home folder is included.

With BTRFS, I cannot exclude these folders. This means, if I restore a BTRFS snapshot, I loose any new personal documents and get old version of existing personal documents.

I cannot imagine this is by design. Or is this really based on the assumption /home only contains personal files? Isn't that incorrect? I don't believe there is an Ubuntu distribution that does that. /home actually contains lots of important system and application files, it can even contain entire applications.

I love BTRFS, but this is quite a disturbing issue, loosing your actual personal files when restoring a snapshot.

wmutschl commented 3 years ago

You could create another btrfs subvolume, let's call it mydata and move your personal folders and temp folders there. Then, if you restore both @ and @home, you should get what you aim for, right?

In more detail, let's assume your btrfs root partition is sda3, then I would do something like this:

mount -o subvolid=5 /dev/sda3 /mnt
ls /mnt
# @ @home timeshift-btrfs
btrfs subvolume create /mnt/mydata
mv /mnt/@home/$USER/Documents /mnt/mydata/ # move any other data you would like to exclude to mydata
# symlink back into home
ln -s /mnt/mydata/Documents /mnt/@home/$USER/Documents

Alternatively, you could adjust the mount points in your fstab...

What I do: note that if you do snapshots of both @ and @home you are always on the save side. For example, if you then decide to restore to a certain point in time, timeshift does not delete the "bad" @ and @home subvolumes. So what I always do is to snapshot both @ and @home automatically, but restore @ only with timeshift. When I need some files from the past in @home, I simply mount my topvolume and copy these over.

zilexa commented 3 years ago

Thanks! I have been reading some more and indeed, creating subvolume(s) is the way to go. Now I guess there are 2 approaches.

  1. Your approach, create a single new subvolume @mydata (/mnt/data) with the personal folders to it, symlink those folders to the right location.
  2. Create a subvolume for each personal folder + .cache folder, 6 in total. This eliminates the need for symlinks.

In both cases, snapshot @ and @home, but not the newly created subvolume(s). I like (2) in this case as I only use symlinks when needed. And it seems when using BTRFS it is meant to exclude stuff via subvolumes.

What I don't understand: if you snapshot @, won't it include /mnt/mydata?

wmutschl commented 3 years ago

No, it won't include it as you have a flat btrfs subvolume structure, all is good then. Also nested subvolumes will be ignored. Anyways, you should differentiate between the btrfs root filesystem (which has always subvolid 5) and the root mount point of your system, which is mounted to a subvolume called @. This thread by @TomZ over at the old Manjaro forum helped me understand this, maybe it is of use to you as well: https://archived.forum.manjaro.org/t/btrfs-tips-and-tricks/71186/6

zilexa commented 3 years ago

Is there a reason you symlink?

# symlink back into home
ln -s /mnt/mydata/Documents /mnt/@home/$USER/Documents

Instead of just mounting those folders back into home? I read in an 5-year old comment when you move files between subvolumes, they will get physically copied because BTRFS treats subvolumes as seperate partitions. That would not be desirable and I would definitely go for symlinks.

Unless it is possible to mount a subfolder of a subvolume? I could not find this in any documentation, I doubt it is possible. Say your subvolume is @mydata, now I want to mount a folder inside @mydata: sudo mount -o subvol=/@mydata/Documents /dev/sda3 /home/Documents

wmutschl commented 3 years ago

The cleanest way is to mount the different subvolumes via your fstab.