Ask Your Question
1

Can't restore a btrfs snapshot

asked 2015-01-07 12:05:24 -0600

Daniel01 gravatar image

updated 2015-01-07 13:55:06 -0600

I have created a snapshot of my home folder with the sudo btrfs subvolume snapshot /home /home/user/snap Now I want to restore it so i did a sudo mv /home/snap /home but it only added the snapshot in the /home folder. How ca I rollback?

edit retag flag offensive close merge delete

Comments

You want to mount your snapshots at boot and not move/copy them.

sudhirkhanger gravatar imagesudhirkhanger ( 2015-01-07 14:01:54 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-01-07 15:16:54 -0600

baoboa gravatar image

updated 2015-01-08 17:40:46 -0600

a snapshot create a new subvolume

btrfs subvolume show /home
btrfs subvolume show /home/snap

i suppose /home is the btrfs root

the snapshot you create is just the state of /home at the time you done it , both the root and the snapshot have independent life after that.

to avoid trouble i would do the following commands as root at init level 3 ( CRT+ALT+F2 -> root login -> # init 3 -> switch -> # init 5 )

in your fstab , if your snapshot is called "snap"

modify this line

UUID=XXXXXXX /home btrfs defaults 1 2

by this

UUID=XXXXXXX /home btrfs defaults,subvol=snap 1 2

i would recommend a reboot but this should work too (or complain ;) )

 mount -o remount /home 

edit:

after reading your comment i say

  • you should not work directly with the btrfs root of your fs
  • here is a example how to do it, for more look at this this link
dd if=/dev/zero of=my_fs bs=1024 count=30720
losetup /dev/loop0 my_fs
mkfs -t btrfs /dev/loop0
mkdir /mnt/tmp_mount
mount /dev/loop0 /mnt/tmp_mount
btrfs subvolume create  /mnt/tmp_mount/master
mkdir /mnt/home
mount -t btrfs -o subvol=master /dev/loop0 /mnt/home
btrfs subvolume snapshot /mnt/tmp_mount/master /mnt/tmp_mount/snap`date -I`
umount /mnt/tmp_mount

#to roll back
mount /dev/loop0 /mnt/tmp_mount
umount /mnt/home
btrfs subvolume delete  /mnt/tmp_mount/master
btrfs subvolume snapshot /mnt/tmp_mount/snap-XXXXXX  /mnt/tmp_mount/master
umount /mnt/tmp_mount
mount -o subvol=master /dev/loop0  /mnt/home
edit flag offensive delete link more

Comments

I want to write a gui for a small part of the btrfs utility ( work in progress https://github.com/stoiandan/TimeTraveler ) that is why I need these, is there a more real time option I really think there must be a way to simply move the snapshot to /home as snapper is suse does?

Daniel01 gravatar imageDaniel01 ( 2015-01-08 06:52:02 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-01-07 12:05:24 -0600

Seen: 612 times

Last updated: Jan 08 '15