Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fedora - Recover your files from Btrfs snapshots

#1
Recover your files from Btrfs snapshots

As you have seen in a previous article, Btrfs snapshots are a convenient and fast way to make backups. Please note that these articles do not suggest that you avoid backup software or well-tested backup plans. Their goals are to show a great feature of this file system, snapshots, and to inspire curiosity and invite you to explore, experiment and deepen the subject. Read on for more about how to recover your files from Btrfs snapshots.

A subvolume for your project


Let’s assume that you want to save the documents related to a project inside the directory $HOME/Documents/myproject.

As you have seen, a Btrfs subvolume, as well as a snapshot, looks like a normal directory. Why not use a Btrfs subvolume for your project, in order to take advantage of snapshots? To create the subvolume, use this command:

btrfs subvolume create $HOME/Documents/myproject

You can create an hidden directory where to arrange your snapshots:

mkdir $HOME/.snapshots

As you can see, in this case there’s no need to use sudo. However, sudo is still needed to list the subvolumes, and to use the send and receive commands.

Now you can start writing your documents. Each day (or each hour, or even minute) you can take a snapshot just before you start to work:

btrfs subvolume snapshot -r $HOME/Documents/myproject $HOME/.snapshots/myproject-day1

For better security and consistency, and if you need to send the snapshot to an external drive as shown in the previous article, remember that the snapshot must be read only, using the -r flag.

Note that in this case, a snapshot of the /home subvolume will not snapshot the $HOME/Documents/myproject subvolume.

How to recover a file or a directory


In this example let’s assume a classic error: you deleted a file by mistake. You can recover it from the most recent snapshot, or recover an older version of the file from an older snapshot. Do you remember that a snapshot appears like a regular directory? You can simply use the cp command to restore the deleted file:

cp $HOME/.snapshots/myproject-day1/filename.odt $HOME/Documents/myproject

Or restore an entire directory:

cp -r $HOME/.snapshots/myproject-day1/directory $HOME/Documents/myproject

What if you delete the entire $HOME/Documents/myproject directory (actually, the subvolume)? You can recreate the subvolume as seen before, and again, you can simply use the cp command to restore the entire content from the snapshot:

btrfs subvolume create $HOME/Documents/myproject
cp -rT $HOME/.snapshots/myproject-day1 $HOME/Documents/myproject

Or you could restore the subvolume by using the btrfs snapshot command (yes, a snapshot of a snapshot):

btrfs subvolume snapshot $HOME/.snapshots/myproject-day1 $HOME/Documents/myproject

How to recover btrfs snapshots from an external drive


You can use the cp command even if the snapshot resides on an external drive. For instance:

cp /run/media/user/mydisk/bk/myproject-day1/filename.odt $HOME/Documents/myproject

You can restore an entire snapshot as well. In this case, since you will use the send and receive commands, you must use sudo. In addition, consider that the restored subvolume will be created as read only. Therefore you need to also set the read only property to false:

sudo btrfs send /run/media/user/mydisk/bk/myproject-day1 | sudo btrfs receive $HOME/Documents/
mv Documents/myproject-day1 Documents/myproject
btrfs property set Documents/myproject ro false

Here’s an extra explanation. The command btrfs subvolume snapshot will create an exact copy of a subvolume in the same device. The destination has to reside in the same btrfs device. You can’t use another device as the destination of the snapshot. In that case you need to take a snapshot and use the send and receive commands.

For more information, refer to some of the online documentation:

man btrfs-subvolume
man btrfs-send
man btrfs-receive


https://www.sickgaming.net/blog/2020/10/...snapshots/
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Fedora - Contribute at the Fedora Test Week for Kernel 5.9 xSicKxBot 0 4 Today, 12:22 AM
Last Post: xSicKxBot
  Fedora - Announcing the release of Fedora 33 Beta xSicKxBot 0 29 09-29-2020, 09:01 PM
Last Post: xSicKxBot
  Fedora - Now available: Fedora on Lenovo laptops! xSicKxBot 0 27 09-25-2020, 07:51 PM
Last Post: xSicKxBot
  Fedora - Incremental backups with Btrfs snapshots xSicKxBot 0 50 09-15-2020, 01:20 PM
Last Post: xSicKxBot
  Fedora - Ankur Sinha: How do you Fedora? xSicKxBot 0 46 09-11-2020, 02:22 PM
Last Post: xSicKxBot
  Fedora - Contribute at the Fedora Test Week for Btrfs xSicKxBot 0 68 08-26-2020, 01:20 PM
Last Post: xSicKxBot
  Fedora - Btrfs Coming to Fedora 33 xSicKxBot 0 75 08-24-2020, 01:28 PM
Last Post: xSicKxBot
  Fedora - Configure Fedora to practice and compose music xSicKxBot 0 63 08-22-2020, 12:44 PM
Last Post: xSicKxBot
  Fedora - Contribute at the Fedora Kernel and GNOME test days xSicKxBot 0 76 08-18-2020, 02:42 PM
Last Post: xSicKxBot
  Fedora - Create a wifi hotspot with Raspberry Pi 3 and Fedora xSicKxBot 0 90 08-12-2020, 12:36 PM
Last Post: xSicKxBot

Forum Jump:

Become a Patron!
[-]
Upcoming Events

[-]
Latest Threads
Xbox Wire - Xbox Insider Release Notes –...
Last Post: xSicKxBot
Today 02:31 PM
» Replies: 0
» Views: 2
News - Video: The lighting technology of...
Last Post: xSicKxBot
Today 02:30 PM
» Replies: 0
» Views: 3
News - Talking Point: What Are You Playi...
Last Post: xSicKxBot
Today 02:22 PM
» Replies: 0
» Views: 2
News - Of Course Scalpers Are Already Li...
Last Post: xSicKxBot
Today 02:22 PM
» Replies: 0
» Views: 2
News - Xbox Could Offer Streaming Stick ...
Last Post: xSicKxBot
Today 02:21 PM
» Replies: 0
» Views: 3
(Indie Deal) FREE Ghost Sweeper, ? NBA 2...
Last Post: xSicKxBot
Today 08:16 AM
» Replies: 0
» Views: 4
(Free Game Key) BigFish Game of Your Cho...
Last Post: xSicKxBot
Today 08:16 AM
» Replies: 0
» Views: 5
News - Random: Not Everyone Is Happy Wit...
Last Post: xSicKxBot
Today 08:15 AM
» Replies: 0
» Views: 3
News - Xbox Could Offer Streaming Stick ...
Last Post: xSicKxBot
Today 08:15 AM
» Replies: 0
» Views: 4
microStudio Game Engine Hands-On
Last Post: xSicKxBot
Today 12:22 AM
» Replies: 0
» Views: 6

[-]
Twitter

[-]
Sponsored
Get the Deal of the Week at RefurBees.com

Copyright © SickGaming.net 2012-2020