public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Massimo B." <massimo.b@gmx.net>
To: Laurent Lauden <laurent.lauden@laposte.net>, linux-btrfs@vger.kernel.org
Subject: Re: undelete files
Date: Mon, 17 Dec 2018 12:38:04 +0100	[thread overview]
Message-ID: <1545046684.2140.29.camel@gmx.net> (raw)
In-Reply-To: <98a3ae94-d6ed-b7ba-34eb-61b9f2db33e8@laposte.net>

Hello,

I had a similar issue. On OpenSuse I deleted /.snapshots/ and was not aware that
/.snapshots/1/snapshot/ is the default subvolume representing my root file
system.
So I had no snapshot left, all ro subvolumes have been deleted before, and the
default subvolume had big parts deleted before I cancelled the rm -rfv. I kept a
copy of the STDOUT listing the deleted files and switched off the power of that
filesystem immediately, no sync or umount.
There have been no additional writes, so I was quite sure the data must still be
there.

I booted a live version of the OpenSuse TW. However btrfsprogs are missing the
important btrfs-find-root, so I compiled the progs from the very recent github
revision.

After I played with the btrfs restore and --path-regex I had no success, finding
some of the files that have been deleted.
I found a copy of the btrfs-undelete script and played with that:
https://gist.github.com/Changaco/45f8d171027ea2655d74

I learned how to traverse the root-ids to older generations, but the script
found absolutely none of the deleted files.
I modified the script to use btrfs-find-root -a which found some more root-ids
but still no success, for instance:

# btrfs-undelete /dev/mapper/_root "/@/.snapshots/1/snapshot/etc/cron.daily/1btrk.cron" /mnt/usb/rescue
Trying root 88866816... (329/332)
Trying root 66764800... (330/332)
Trying root 66600960... (331/332)
Trying root 60571648... (332/332)
Didn't find '@/.snapshots/1/snapshot/etc/cron.daily/1btrk.cron'

I did not trust the obscure --path-regex.

I also reproduced what the script does, using regular expressions like
'^/(|@(|/.snapshots(|/1(|/snapshot(|/etc(|/cron.daily(|/1btrbk.cron)))))))$'

However I did some btrfs restore --dry-run and grepped the known files myself,
until I found older root-ids containing almost all of the missing files with
meta-data. The snippets I like to share here:

# btrfs-find-root -a /dev/mapper/_root |grep Well |cut -d '(' -f 1 |awk '{print $3}' | while read -r rootid ; do echo "### rootid: $rootid"; btrfs restore -t $rootid -Dvi /dev/mapper/_root /mnt/usb/rescue/;done 2>/dev/null |grep -e "### rootid" -e "1btrbk.cron"

### rootid: 245530624
### rootid: 245022720
### rootid: 244760576
### rootid: 242139136
### rootid: 242892800
### rootid: 241942528
### rootid: 209518592
### rootid: 144097280
### rootid: 147816448
Restoring /mnt/usb/rescue/@/.snapshots/1/snapshot/etc/cron.daily/1btrbk.cron
### rootid: 123863040
Restoring /mnt/usb/rescue/@/.snapshots/1/snapshot/etc/cron.daily/1btrbk.cron

Best regards,
Massimo

  reply	other threads:[~2018-12-17 11:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-04 16:47 undelete files Laurent Lauden
2018-12-17 11:38 ` Massimo B. [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-12-29 22:22 Undelete files Adrian Bastholm
2018-12-30  4:11 ` Duncan
2018-12-30  5:44   ` Duncan
     [not found] <20181229225140.08d397fb@ws>
2018-12-30  8:58 ` Jesse Emeth
2019-01-02  2:48   ` Duncan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1545046684.2140.29.camel@gmx.net \
    --to=massimo.b@gmx.net \
    --cc=laurent.lauden@laposte.net \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox