Some doubts of newcomers to snapper,I need some help

I try to use snapper for backup and restore. I have read quite a lot of documentation about snapper and I am now basically familiar with the operation process.
But there are still some doubts.

Restore command:

sudo snapper -c scvg009root undochange 1…0

In this command, I know that 1 is the snapshot I chose, so what does 0 mean?

  1. reading the official documentation I know that snapper will automatically exclude certain directories, so can I manually specify some directories that need to be excluded? If so, what do I need to do?

3.I use systemctl to execute snapper-cleanup.timer, do I still need to set it in the configuration file?

#btrfs qgroup for space aware cleanup algorithms

If needed, how do I set it?

Generally you would use that command to restore a file or a set of files. If you try to use that to restore your whole root subvolume it will fail.

Restores of an entire volume need to done manually but it is a fairly simple process.

In this case, 1 is the snapshot you are restoring from and 0 is the snapshot you are restoring to

This is not exactly true. Snapper is taking a snapshot of the of the subvolume(s) you tell it to and nothing else. In your case, you have probably set it to take a snapshot of your root subvolume. You can create as many configurations as you want. For example, it would be wise to also take snapshots of your /home subvolume if you have one.

Yes. The timer checks the setting in the configuration file.

sudo snapper -c scvg009root set-config "TIMELINE_CLEANUP=yes NUMBER_CLEANUP=yes"

Thank you, or I still don’t know how to manually exclude a directory, such as /home/music, from this folder. Normal snapper will back up all the directories under the home folder, but what if I want to exclude this directory?

Does it mean that 1 is the snapshot and 0 is the destination.

snapshots aren’t backups, you snapshot an entire subvolume. If you want to exclude that directory, you need to put it in it’s own subvolume. This is actually pretty easy to do if you need instructions let me know.


When snapper backs up /directory, it excludes home directory. So I configured the home directory separately, but snapper backs up the whole home directory when it backs up home, but I want to exclude some directories, for example: music directory.

When I take a snapshot with snapper, I’ll have many copies of the snapshot, but the destination is 0, right! That means

sudo snapper -c scvg009root undochange 1…0

0,This is always the same.

Hmm…not exactly. I believe 0 is always the current, in-use subvolume. However you can’t always restore files to the running root so there will times when you need to boot off of something else and do the restore. In that case, you would need to exercise caution in what 0 actually represents.

One word of caution is be careful with the official documentation. Some of it is suse-specific.

Another important note is that what snapper is actually doing is creating btrfs snapshots so even without snapper being available you can still restore data.

I’m still confused, let’s say I have five snapshots with numbers 1/2/3/4/5
What is the difference between sudo snapper -c scvg009root undochange 5…4 and sudo snapper -c scvg009root undochange 4…0?

This restores data from snapshot 5 to the running system. I strongly suspect this command will either fail or produce unexpected results because you probably can’t overwrite your running root in it’s entirety.

This takes data from snapshot 5 and restores it to snapshot 4. I suspect this will also fail since 4 is a readonly snapshot. However, I have never actually tried it and it is theoretically possible snapper converts it to a rw snapshot first but I doubt it.

Also, I can’t really imagine a practical use case. Why would you want to copy data from one snapshot to another?

This restores data from snapshot 4 to the running system. As with your first example, I suspect this will fail for the same reason.

I think the important thing to consider is in most normal cases your snaphots won’t be identical. Usually snapshots 4 & 5 would be from different points in time and have some differences.

It might also be useful to read the docs for btrfs snapshots as understanding what snapshots are might make this easier to understand conceptually.

It is worth noting that even though I use snapper I have never used the undochange command to restore data. I usually just restore it by hand.

@dalto I create 2 texts named test1 and test2 in snapshot 4, before creating snapshot 5 I delete test1 and then create snapshot 5, then restore with sudo snapper -c scvg009root undochange 4…5, I will find that both texts are there, when I use sudo snapper -c scvg009root undochange 5…4, only test2 is there. c scvg009root undochange 5…4, only test2 is there, apparently test1 was deleted by me since it was before I did snapshot 5. So it didn’t show up either when I restored from 5 to 4.

@dalto Following up on the earlier question:When snapper backs up /directory, it excludes home directory. So I configured the home directory separately, but snapper backs up the whole home directory when it backs up home, but I want to exclude some directories, for example: music directory.

It doesn’t actually. It takes a snapshot of the entirety of the subvolume mounted at /. If your /home was in that subvolume, it would also be in the snapshot. However, your /home is probably in it’s own subvolume which is why it isn’t included.

So if you want to not have your music directory in your snapshots, you need to create a separate subvolume for it and mount it as your music directory.

I only created a / partition and boot when partitioning
I read the official documentation and it says that snapper does not back up the home directory by default, unless a new configuration is created specifying the home directory to be backed up.
If I hang the music directory as a subdirectory, is this a complicated process?

That information is suse specific. It doesn’t apply in general.

First, a subvolume is totally different than a subdirectory.

But no, it isn’t complicated. If you share your /etc/fstab I can give you the commands to do it.

@dalto The forum doesn’t allow me to upload fstab, so I need to post it, right?

Yes, paste the contents in and then format it as a code block either by highlighting it and using the </> in the format bar at the top of the post or by surrounding it in code tags. There are several acceptable formats for this:

contents of /etc/fstab here
contents of /etc/fstab here
contents of /etc/fstab here
# /etc/fstab: static file system information.
# Use 'blkid' to print the universally unique identifier for a device; this may
# be used with UUID= as a more robust way to name devices that works even if
# disks are added and removed. See fstab(5).
# <file system>             <mount point>  <type>  <options>  <dump>  <pass>
UUID=7SCC-BF3D                            /boot/efi      vfat    umask=0077 0 2
UUID=16232a3c-ab91-4ff5-93e3-321595a3d492 /              btrfs   subvol=/@,defaults,noatime,space_cache,autodefrag 0 1
UUID=16232a3c-ab91-4ff5-93e3-321595a3d492 /home          btrfs   subvol=/@home,defaults,noatime,space_cache,autodefrag 0 2
UUID=16232a3c-ab91-4ff5-93e3-321595a3d492 /var/cache     btrfs   subvol=/@cache,defaults,noatime,space_cache,autodefrag 0 2
UUID=16232a3c-ab91-4ff5-93e3-321595a3d492 /var/log       btrfs   subvol=/@log,defaults,noatime,space_cache,autodefrag 0 2
UUID=0731c85c-ae83-4dee-b797-55f28e99b317 swap           swap    defaults,noatime 0 0

About the snapshot problem just now, I did an interesting little experiment:
Snapshot #10 has 2 new texts, snapshot #11 has 1 deleted text

sudo snapper -c scvg009home undochange 10…11
reate:26 modify:2 delete:0
sudo snapper -c scvg009home undochange 10…0
create:0 modify:1 delete:0
sudo snapper -c scvg009home undochange 10…11
create:26 modify:2 delete:0

When I restored snapshot #11 with snapshot #10 both texts were there, but when I restored snapshot #10 with snapshot #11, one text was missing (this text was deleted before I created snapshot #11)

The basic process is mount the root of the btrfs volume, create the subvolume, move the existing data, mount it where it belongs.

Here we go:

sudo mkdir /mnt/btrfs
sudo mount UUID=16232a3c-ab91-4ff5-93e3-321595a3d492 /mnt/btrfs -o subvolid=5
sudo btrfs subvolume create /mnt/btrfs/@music

If you don’t have any existing data in Music you can skip this part, it copies the data and then deletes the old data

sudo rsync -aAXHv ~/Music/ /mnt/btrfs/@music
sudo rm -r ~/Music/*

Now you need to add the following line to /etc/fstab, replace username with your actual username

UUID=16232a3c-ab91-4ff5-93e3-321595a3d492 /home/username/Music          btrfs   subvol=/@music,defaults,noatime,space_cache,autodefrag 0 0

Lastly, you test the mount

sudo mount /home/username/Music

Thank you very much, I’m going to try it!

So it seems that the subvolumes of btrfs are, in fact, virtualized on a partition. You can understand it like this