summaryrefslogtreecommitdiff
path: root/cmds-restore.c
Commit message (Collapse)AuthorAge
* Btrfs-progs: rework open_ctree to take flags, add a new one V2Josef Bacik2013-11-07
| | | | | | | | | | | So I needed to add a flag to not try to read block groups when doing --init-extent-tree since we could hang there, but that meant adding a whole other 0/1 type flag to open_ctree_fs_info. So instead I've converted it all over to using a flags setting and added the flag that I needed. This has been tested with xfstests and make test. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: add -b to btrfsck to look at backup rootsJosef Bacik2013-11-07
| | | | | | | | | | In some cases the tree root is so hosed we can't get anything useful out of it. So add the -b option to btrfsck to make us look for the most recent backup tree root to use for repair. Then we can hopefully get ourselves into a working state. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: drop unused parameter from btrfs_item_nrRoss Kirk2013-10-16
| | | | | | | | | | Remove unused eb parameter from btrfs_item_nr, unused since introduced in 7777e63b425f1444d2472ea05a6b2b9cf865f35b Signed-off-by: Ross Kirk <ross.kirk@gmail.com> Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix magic return value in cmds-restore.cWang Shilong2013-10-16
| | | | | | Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix restore command leaving corrupted filesFilipe David Borba Manana2013-10-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When there are files that have parts shared with snapshots, the restore command was incorrectly restoring them, as it was not taking into account the offset and number of bytes fields from the file extent item. Besides leaving the recovered file corrupt, it was also inneficient as it read and wrote more data than needed (with each extent copy overwriting portions of the one previously written). The following steps show how to reproduce this corruption issue: $ mkfs.btrfs -f /dev/sdb3 $ mount /dev/sdb3 /mnt/btrfs $ perl -e '$d = "\x41" . ("\x00" x (1024*1024+349)); open($f,">","/mnt/btrfs/foobar"); print $f $d; close($f);' $ du -b /mnt/btrfs/foobar 1048926 /mnt/btrfs/foobar $ md5sum /mnt/btrfs/foobar f9f778f3a7410c40e4ed104a3a63c3c4 /mnt/btrfs/foobar $ btrfs subvolume snapshot /mnt/btrfs /mnt/btrfs/my_snap $ perl -e 'open($f, "+<", "/mnt/btrfs/foobar"); seek($f, 4096, 0); print $f "\xff"; close($f);' $ md5sum /mnt/btrfs/foobar b983fcefd4622a03a78936484c40272b /mnt/btrfs/foobar $ umount /mnt/btrfs $ btrfs restore /dev/sdb3 /tmp/copy $ du -b /tmp/copy/foobar 1048926 /tmp/copy/foobar $ md5sum /tmp/copy/foobar 88db338cbc1c44dfabae083f1ce642d5 /tmp/copy/foobar $ od -t x1 -j 8192 -N 4 /tmp/copy/foobar 0020000 41 00 00 00 0020004 $ mount /dev/sdb3 /mnt/btrfs $ od -t x1 -j 8192 -N 4 /mnt/btrfs/foobar 0020000 00 00 00 00 0020004 $ md5sum /mnt/btrfs/foobar b983fcefd4622a03a78936484c40272b /mnt/btrfs/foobar Tested this change with zlib, lzo compression and file sizes larger than 1GiB, and found no regression or other corruption issues (so far at least). Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: use NULL instead of 0Zach Brown2013-09-03
| | | | | | | | | These were mostly in option structs but there were a few gross string pointer arguments given as 0. Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: fix shadow symbolsZach Brown2013-09-03
| | | | | | | | | | | | | | | This fixes all the instances of warnings that symbols declared in blocks shadow symbols with the same name in surrounding scopes: cmds-device.c:341:22: warning: symbol 'path' shadows an earlier one cmds-device.c:285:14: originally declared here I just renamed or removed the risky shadow symbols instead of pulling their blocks out into functions. Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: mark static & remove unused from non-kernel codeEric Sandeen2013-09-03
| | | | | | | | Mark many functions as static, and remove any resulting dead code. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: drop unused parameter from btrfs_release_pathEric Sandeen2013-09-03
| | | | | | | | | | | | | | | Port of commit b3b4aa7 to userspace. parameter tree root it's not used since commit 5f39d397dfbe140a14edecd4e73c34ce23c4f9ee ("Btrfs: Create extent_buffer interface for large blocksizes") This gets userspace a tad closer to kernelspace by removing this unused parameter that was all over the codebase... Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: Update the usage strings of some cmdsQu Wenruo2013-08-09
| | | | | | | | | | | Update the usage strings of some cmds to keep the them consistent with the source. Also some minor changes are done to fit the man page syntax. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: restore can now recover file xattrsFilipe David Borba Manana2013-08-09
| | | | | | | | | | This change adds a new option to the restore command, named -x, that makes it restore file extented attributes too. This is an optional behaviour and it's disabled by default. Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: update usage message for cmds-restoreFilipe David Borba Manana2013-08-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Mention that a target path argument is mandatory unless the -l option is supplied. Also mention about the existence of the -l option, which was previously not announced. $ btrfs restore -v /dev/sdb3 usage: btrfs restore [options] <device> Try to restore files from a damaged filesystem (unmounted) -s get snapshots -v verbose -i ignore errors -o overwrite -t tree location -f <offset> filesystem location -u <block> super mirror -d find dir $ echo $? 129 After specifying a target path, the command works as expected: $ btrfs restore -v /dev/sdb3 files2/ Restoring files2/file1 Done searching $ echo $? 0 V2: Updated command synopsis by suggestion of Anand Jain. Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: restore: use long option for the path regexDavid Sterba2013-08-09
| | | | | | | | | | | Current way of specifying the path to match is not very comfortable, but the feature itself is very useful. Let's save the short option -m for a more user friendly syntax and keep a long option --path-regex with the current syntax. CC: Peter Stuge <peter@stuge.se> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: fix regexec to only work if we actually have a regexecJosef Bacik2013-08-09
| | | | | | | | | | We were unconditionally executing our regular expression, even though we may not have one, so check to make sure mreg is not null before calling regexec. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* restore: Add regex matching of paths and files to be restoredPeter Stuge2013-08-09
| | | | | | | | | | | | | | | | | | | The option -m is used to specify the regex string. -c is used to specify case insensitive matching. -i was already taken. In order to restore only a single folder somewhere in the btrfs tree, it is unfortunately neccessary to construct a slightly nontrivial regex, e.g.: restore -m '^/(|home(|/username(|/Desktop(|/.*))))$' /dev/sdb2 /output This is needed in order to match each directory along the way to the Desktop directory, as well as all contents below the Desktop directory. Signed-off-by: Peter Stuge <peter@stuge.se> Signed-off-by: Josef Bacik <josef@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-restore: deal with NULL returns from read_node_slotChris Mason2013-07-05
| | | | Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-restore: use the correct leafsize when reading the FS locationChris Mason2013-07-05
| | | | Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: pass properly formated key to read_fs_rootJosef Bacik2013-06-19
| | | | | | | | | | | We have a BUG_ON() in read_fs_root that expects key->offset == (u64)-1. Restore will just pass in the location it reads out of the inode if it has a subvol reference and pass that in, which doesn't have offset == (u64)-1, so it causes restore blow up. This was reported in bugzilla and this patch fixed the problem. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix compile warnings in i386 machineWang Shilong2013-05-10
| | | | | | | | | | | | | | | | | | | | | | | | See the warnings below: [CC] btrfs-list.o btrfs-list.c: In function 'filter_by_parent': btrfs-list.c:1183:34: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] [CC] cmds-subvolume.o cmds-subvolume.c: In function 'cmd_subvol_show': cmds-subvolume.c:917:5: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] [CC] cmds-restore.o cmds-restore.c: In function 'decompress_lzo': cmds-restore.c:116:10: warning: passing argument 4 of 'lzo1x_decompress_safe' from incompatible pointer type [enabled by default] In file included from cmds-restore.c:31:0: /usr/include/lzo/lzo1x.h:77:1: note: expected 'lzo_uint *' but argument is of type 'size_t *' Reported-by: Russell Coker <russell@coker.com.au> Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: make restore deal with really broken file systemsJosef Bacik2013-04-23
| | | | | | | | | | | | | | | | | All we need for restore to work is the chunk root, the tree root and the fs root we want to restore from. So to do this we need to make a few adjustments 1) Make open_ctree_fs_info fail completely if it can't read the chunk tree. There is no sense in continuing if we can't read the chunk tree since we won't be able to translate logical to physical blocks. 2) Use open_ctree_fs_info in restore, and if we didn't load a tree root or fs root go ahead and try to set those up manually ourselves. This is related to work I did last year on restore, but it uses the open_ctree_fs_info instead of my open coded open_ctree. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
* Btrfs-progs: give restore a list roots optionJosef Bacik2013-03-18
| | | | | | | | Since restore has the ability to open really really screwed up file systems, add a list roots option to it so we can still get the contents of the tree root on a horribly broken fs. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
* btrfs-progs: add lzo compression support to restoreJosef Bacik2013-03-18
| | | | | | This patch simply adds support to decompress lzo compressed extents in restore. Signed-off-by: Josef Bacik <josef@redhat.com>
* restore: Split output directory and btrfs-local path search_dir() parametersPeter Stuge2013-03-18
| | | | | | | | | | | | search_dir() recurses down the btrfs tree, and used to take the output path for every item (i.e. in the running system, output root directory concatenated with btrfs-local pathname) passed as the only path parameter. Moving the output root directory to a separate parameter and passing the btrfs-local pathname for each file and directory separately allows easy filtering based on the btrfs-local pathname. Signed-off-by: Peter Stuge <peter@stuge.se> Signed-off-by: Josef Bacik <josef@redhat.com>
* btrfs-progs: Fix error handling for failed reads in restore tool when ↵David Marcin2013-03-18
| | | | | | mirrors exist Signed-off-by: David Marcin <djmarcin@google.com>
* Btrfs-progs: try other mirrors on read failureJosef Bacik2013-03-18
| | | | | | | If we hit a bad disk and the read doesn't work, try other mirrors in case we have other disks with good copies. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
* Btrfs-progs: try other mirrors if decompression failsJosef Bacik2013-03-18
| | | | | | | This will make the restore program fall back on other mirrors if it fails to decompress an extent for whatever reason. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
* Btrfs-progs: add an option for specifying the root to restoreJosef Bacik2013-03-15
| | | | | | | | If the normal fs tree is hosed and the user has multiple subvolumes it's handy to be able to specify just one of the subvolumes to restore. It's also handy if a user only wants to restore say /home instead of his entire disk. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
* btrfs-progs: usage should match what is codedAnand Jain2013-03-03
| | | | Signed-off-by: Anand Jain <anand.jain@oracle.com>
* btrfs-progs: provide positive errno to strerror in cmd_restoreEric Sandeen2013-02-27
| | | | | | | check_mounted returns a negative errno, so it needs to be flipped again before passing to strerror. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
* Btrfs-progs: add restore command to btrfsIan Kumlien2013-02-12
| | | | | | | | Add 'btrfs restore' command which previously existed as a separate utility btrfs-restore. Signed-off-by: Ian Kumlien <pomac@demius.net> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: restore.c -> cmds-restore.cIan Kumlien2013-02-12
The btrfs-restore functionality will be integrated in btrs as "btrfs restore" Signed-off-by: Ian Kumlien <pomac@demius.net>