LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > marozsas
User Name
Password

Notices


Rate this Entry

a snapper/btrfs exercise

Posted 07-09-2022 at 09:37 AM by marozsas
Updated 07-09-2022 at 04:24 PM by marozsas
Tags btrfs, exercise

// this is a comment
// if you need to replay this exercise you have to remove previous snapper configs:
// 1) edit /etc/sysconfig/snapper and remove appropriate entry
// 2) remove the file /etc/snapper/configs/test
//

// create a BTRFS on the spare disk
# mkfs.btrfs -f -L 'Test disk' /dev/sdh1
// lines removed for clarity
// ...
ID SIZE PATH
1 931.51GiB /dev/sdh1

// create a mount point and mount the btrfs on it
# mkdir /mnt/test
# mount /dev/sdh1 /mnt/test/

// verify there is no subvolumes yet
# btrfs subvolume list /mnt/test/
# // no output
// create a base folder to do our tests
# mkdir /mnt/test/myroot

// list the current snapper configurations
# snapper list-configs
Config | Subvolume
-------+----------
root | /
#

// create a snapper config
# snapper -c test create-config /mnt/test
# snapper list-configs
Config | Subvolume
-------+----------
root | /
test | /mnt/test
#

// verify that there is a .snapshots subvolume created by snapper
# btrfs subvolume list /mnt/test/
ID 256 gen 8 top level 5 path .snapshots
#

// and there is the current snapshot
# snapper -c test list
# | Type | Pre # | Date | User | Cleanup | Description | Userdata
---+--------+-------+------+------+---------+-------------+---------
0 | single | | | root | | current |
#

// create a initial snapshot the represent this currently empty FS
# snapper -c test create --description "Initial state"
# snapper -c test list
# | Type | Pre # | Date | User | Cleanup | Description | Userdata
---+--------+-------+--------------------------+------+---------+---------------+---------
0 | single | | | root | | current |
1 | single | | Sat Jul 9 14:31:56 2022 | root | | Initial state |


// lets modify the FS by creating some folders and dummy files
# mkdir /mnt/test/myroot/folder_{A,B,C,D}
# touch /mnt/test/myroot/folder_{A,B,C,D}/file_{1..9}
# tree /mnt/test/myroot
/mnt/test/myroot
├── folder_A
│** ├── file_1
│** ├── file_2
│** ├── file_3

// lines removed for clarity

└── folder_D

// lines removed for clarity

├── file_7
├── file_8
└── file_9

4 directories, 36 files
#

// lets create a snapshot before making changes
# snapper -c test create --description "before delete some files and folders"
# rm /mnt/test/myroot/folder_{A,B,C,D}/file_{1..5}
# tree /mnt/test/myroot/
/mnt/test/myroot/
├── folder_A
│** ├── file_6
│** ├── file_7
│** ├── file_8
│** └── file_9
├── folder_B
│** ├── file_6
│** ├── file_7
│** ├── file_8
│** └── file_9
├── folder_C
│** ├── file_6
│** ├── file_7
│** ├── file_8
│** └── file_9
└── folder_D
├── file_6
├── file_7
├── file_8
└── file_9

4 directories, 16 files
#

// lets make more changes but before, another snapshot
# snapper -c test create --description "before create files xxx"
# touch /mnt/test/myroot/folder_{A,B}/xxx_{1..5}
# tree /mnt/test/myroot
/mnt/test/myroot
├── folder_A
│** ├── file_6
│** ├── file_7

// lines removed for clarity

│** ├── xxx_1
│** ├── xxx_2
│** ├── xxx_3

// lines removed for clarity

├── file_8
└── file_9

4 directories, 26 files
#
// create a final snapshot
# snapper -c test create --description "done"

// lets check the list of snapshots and
// the list of the subvolumes created so far
# snapper -c test list
# | Type | Pre # | Date | User | Cleanup | Description | Userdata
---+--------+-------+--------------------------+------+----------+--------------------------------------+---------
0 | single | | | root | | current |
1 | single | | Sat Jul 9 17:58:08 2022 | root | | Initial state |
2 | single | | Sat Jul 9 17:59:53 2022 | root | | before delete some files and folders |
3 | single | | Sat Jul 9 18:00:00 2022 | root | timeline | timeline |
4 | single | | Sat Jul 9 18:00:10 2022 | root | | before create files xxx |
5 | single | | Sat Jul 9 18:00:31 2022 | root | | done |
# btrfs subvolume list /mnt/test/
ID 256 gen 17 top level 5 path .snapshots
ID 257 gen 10 top level 256 path .snapshots/1/snapshot
ID 258 gen 13 top level 256 path .snapshots/2/snapshot
ID 259 gen 14 top level 256 path .snapshots/3/snapshot
ID 260 gen 15 top level 256 path .snapshots/4/snapshot
ID 261 gen 16 top level 256 path .snapshots/5/snapshot
# btrfs subvolume get-default /mnt/test
ID 5 (FS_TREE)
#

// use snapper to check the difference between snapshots 5 (the current state) and 2 (just after creating the initial structure)
# snapper -c test list
# | Type | Pre # | Date | User | Cleanup | Description | Userdata
---+--------+-------+--------------------------+------+----------+--------------------------------------+---------
0 | single | | | root | | current |
1 | single | | Sat Jul 9 17:58:08 2022 | root | | Initial state |
2 | single | | Sat Jul 9 17:59:53 2022 | root | | before delete some files and folders |
3 | single | | Sat Jul 9 18:00:00 2022 | root | timeline | timeline |
4 | single | | Sat Jul 9 18:00:10 2022 | root | | before create files xxx |
5 | single | | Sat Jul 9 18:00:31 2022 | root | | done |
kimera:~ # snapper -c test status 5..2
+..... /mnt/test/myroot/folder_A/file_1
+..... /mnt/test/myroot/folder_A/file_2
+..... /mnt/test/myroot/folder_A/file_3
// lines removed for clarity
-..... /mnt/test/myroot/folder_B/xxx_3
-..... /mnt/test/myroot/folder_B/xxx_4
-..... /mnt/test/myroot/folder_B/xxx_5
+..... /mnt/test/myroot/folder_C/file_1
+..... /mnt/test/myroot/folder_C/file_2
// lines removed for clarity
+..... /mnt/test/myroot/folder_D/file_5
#

// use snapper to roolback to snapshot 2
# # snapper -c test undochange 2..5
create:20 modify:0 delete:10
kimera:~ # tree /mnt/test/myroot/
/mnt/test/myroot/
├── folder_A
│ ├── file_1
│ ├── file_2
│ ├── file_3
// lines removed for clarity
├── file_7
├── file_8
└── file_9

4 directories, 36 files
// done
Posted in Uncategorized
Views 328 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 05:55 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration