From: Chris Mason <chris.mason@oracle.com>
To: Gustavo Sverzut Barbieri <barbieri@gmail.com>
Cc: Alexandre Oliva <oliva@lsd.ic.unicamp.br>, linux-btrfs@vger.kernel.org
Subject: Re: corrupted btrfs after suspend2ram uncorrectable with scrub
Date: Wed, 9 Nov 2011 09:27:39 -0500 [thread overview]
Message-ID: <20111109142739.GP4149@shiny> (raw)
In-Reply-To: <CANkykrDtHRDe0ve53dkxeNcCeTuWY0i1-8m1SR6BN8Md7F4qGQ@mail.gmail.com>
On Wed, Nov 09, 2011 at 12:19:58PM -0200, Gustavo Sverzut Barbieri wrot=
e:
> On Tue, Nov 8, 2011 at 3:20 PM, Chris Mason <chris.mason@oracle.com> =
wrote:
> > On Tue, Nov 08, 2011 at 03:08:41PM -0200, Gustavo Sverzut Barbieri =
wrote:
> >> On Tue, Nov 1, 2011 at 9:20 PM, Gustavo Sverzut Barbieri
> >> <barbieri@gmail.com> wrote:
> >> > On Tue, Nov 1, 2011 at 7:57 PM, Alexandre Oliva <oliva@lsd.ic.un=
icamp.br> wrote:
> >> >> Hi, Gustavo,
> >> >>
> >> >> On Nov =A01, 2011, Gustavo Sverzut Barbieri <barbieri@gmail.com=
> wrote:
> >> >>
> >> >>> =A0 btrfs csum failed ino 2957021 extent 85041815552 csum 6673=
10679
> >> >>> wanted 0 mirror 0
> >> >>
> >> >>> Is there any way to recover it? =A0:-S
> >> >>
> >> >> Did you try mounting without data checksums?
> >> >
> >> > Just tried to mount with -o nodatasum, no luck. Is that enough?
> >>
> >> Ideas? Should I give up and consider data lost? :-(
> >
> > We actually check the crcs even when mounted with nodatasum. =A0Can=
you
> > give the restore tool a shot from my current btrfs-progs git repo? =
=A0If
> > it can read it we can find a way to get the files off.
>=20
> Hi Chris,
>=20
> Fortunately it worked and I've restored, it misses symbolic links and
> executable permissions (or I did a mistake somewhere, like mounting)
> but overall it's all fine.
Great to hear you've pulled the files. Do you need the kernel patch fo=
r
symlinks etc?
>=20
> The attached patch was helpful to let me ignore stuff like developmen=
t
> files and caches. Speeds up the recovery :-)
Very nice, thanks.
-chris
>=20
> Thanks!
>=20
> --=20
> Gustavo Sverzut Barbieri
> --------------------------------------
> Mobile: +55 (19) 9225-2202
> Contact: http://www.gustavobarbieri.com.br/contact
> From dc57b73b08fefb21099cc6b171683daaffa04501 Mon Sep 17 00:00:00 200=
1
> From: Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
> Date: Mon, 8 Jan 2001 00:37:39 -0200
> Subject: [PATCH] restore: allow ignoring file name patterns and paths=
=2E
>=20
> Introduce two new command line switches that can be specified multipl=
e
> times:
>=20
> -e path-pattern
> -E file-name-pattern
>=20
> They are processed with fnmatch(), the first (-e) using FNM_PATHNAME
> flag on the whole path string, the second uses no flag and is applied
> only over the file or directory name.
>=20
> Example:
>=20
> restore -v \
> -e '*/.cache' -e '*/.thumbnails' \
> -e '*/Desktop/Pictures' \
> -E '*~' \
> /dev/sdb1 /tmp/home-restore
>=20
> will restore everything but files under ~/.cache, ~/.thumbnails and
> ~/Desktop/Pictures for every user (assume it's the mountpoint of
> /home), also ignoring every backup file (*~).
> ---
> restore.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++=
++--
> 1 files changed, 53 insertions(+), 2 deletions(-)
>=20
> diff --git a/restore.c b/restore.c
> index 250c9d3..bdb0c7f 100644
> --- a/restore.c
> +++ b/restore.c
> @@ -25,6 +25,7 @@
> #include <fcntl.h>
> #include <sys/stat.h>
> #include <zlib.h>
> +#include <fnmatch.h>
> #include "kerncompat.h"
> #include "ctree.h"
> #include "disk-io.h"
> @@ -40,6 +41,9 @@ static int get_snaps =3D 0;
> static int verbose =3D 0;
> static int ignore_errors =3D 0;
> static int overwrite =3D 0;
> +static char **exclude_paths =3D NULL;
> +static char **exclude_patterns =3D NULL;
> +static int dir_name_len =3D 0;
> =20
> static int decompress(char *inbuf, char *outbuf, u64 compress_len,
> u64 decompress_len)
> @@ -436,6 +440,27 @@ set_size:
> return 0;
> }
> =20
> +static int is_excluded(const char *path, const char *name)
> +{
> + char **itr;
> + if (exclude_paths) {
> + path +=3D dir_name_len;
> + for (itr =3D exclude_paths; *itr !=3D NULL; itr++) {
> + if (fnmatch(*itr, path, FNM_PATHNAME) =3D=3D=
0) {
> + return 1;
> + }
> + }
> + }
> + if (exclude_patterns) {
> + for (itr =3D exclude_patterns; *itr !=3D NULL; itr++=
) {
> + if (fnmatch(*itr, path, 0) =3D=3D 0) {
> + return 1;
> + }
> + }
> + }
> + return 0;
> +}
> +
> static int search_dir(struct btrfs_root *root, struct btrfs_key *key=
,
> const char *dir)
> {
> @@ -568,6 +593,11 @@ static int search_dir(struct btrfs_root *root, s=
truct btrfs_key *key,
> }
> ret =3D 0;
> }
> + if (is_excluded(path_name, filename)) {
> + if (verbose)
> + printf("Ignored %s\n", path_=
name);
> + goto next;
> + }
> if (verbose)
> printf("Restoring %s\n", path_name);
> fd =3D open(path_name, O_CREAT|O_WRONLY, 0644);
> @@ -636,6 +666,11 @@ static int search_dir(struct btrfs_root *root, s=
truct btrfs_key *key,
> location.objectid =3D BTRFS_FIRST_FREE_OBJECTID;
> }
> =20
> + if (is_excluded(path_name, filename)) {
> + if (verbose)
> + printf("Ignored %s\n", path_=
name);
> + goto next;
> + }
> if (verbose)
> printf("Restoring %s\n", path_name);
> =20
> @@ -672,7 +707,7 @@ next:
> =20
> static void usage()
> {
> - fprintf(stderr, "Usage: restore [-svio] [-t disk offset] <device> "
> + fprintf(stderr, "Usage: restore [-svio] [-e exclude-paths] [-E excl=
ude-name-patterns] [-t disk offset] <device> "
> "<directory>\n");
> }
> =20
> @@ -765,8 +800,15 @@ int main(int argc, char **argv)
> int opt;
> int super_mirror =3D 0;
> int find_dir =3D 0;
> + int exclude_paths_idx =3D 0;
> + int exclude_patterns_idx =3D 0;
> =20
> - while ((opt =3D getopt(argc, argv, "sviot:u:df:")) !=3D -1) {
> + if (argc > 1) {
> + exclude_paths =3D calloc(argc - 1, sizeof(char *));
> + exclude_patterns =3D calloc(argc - 1, sizeof(char *)=
);
> + }
> +
> + while ((opt =3D getopt(argc, argv, "sviot:u:df:e:E:")) !=3D -1) {
> switch (opt) {
> case 's':
> get_snaps =3D 1;
> @@ -806,6 +848,14 @@ int main(int argc, char **argv)
> exit(1);
> }
> break;
> + case 'e':
> + exclude_paths[exclude_paths_idx] =3D strdup(optarg);
> + exclude_paths_idx++;
> + break;
> + case 'E':
> + exclude_patterns[exclude_patterns_idx] =3D strdup(optarg);
> + exclude_patterns_idx++;
> + break;
> case 'd':
> find_dir =3D 1;
> break;
> @@ -855,6 +905,7 @@ int main(int argc, char **argv)
> break;
> dir_name[len - 1] =3D '\0';
> }
> + dir_name_len =3D strlen(dir_name);
> =20
> if (find_dir) {
> ret =3D find_first_dir(root, &key.objectid);
> --=20
> 1.7.7.1
>=20
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2011-11-09 14:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-01 18:38 corrupted btrfs after suspend2ram uncorrectable with scrub Gustavo Sverzut Barbieri
2011-11-01 21:57 ` Alexandre Oliva
2011-11-01 23:20 ` Gustavo Sverzut Barbieri
2011-11-08 17:08 ` Gustavo Sverzut Barbieri
2011-11-08 17:20 ` Chris Mason
2011-11-09 14:19 ` Gustavo Sverzut Barbieri
2011-11-09 14:27 ` Chris Mason [this message]
2011-11-09 14:29 ` Gustavo Sverzut Barbieri
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=20111109142739.GP4149@shiny \
--to=chris.mason@oracle.com \
--cc=barbieri@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=oliva@lsd.ic.unicamp.br \
/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