Btrfs-progs: add restore command to btrfs

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>
This commit is contained in:
Ian Kumlien 2013-02-08 01:37:02 +01:00 committed by David Sterba
parent 1b1e07190f
commit e43cc46155
4 changed files with 34 additions and 22 deletions

View File

@ -9,7 +9,8 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
send-stream.o send-utils.o qgroup.o raid6.o
cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o
cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
cmds-restore.o
CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
-Wuninitialized -Wshadow -Wundef
@ -18,8 +19,7 @@ DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@
INSTALL = install
prefix ?= /usr/local
bindir = $(prefix)/bin
LIBS=-luuid -lm
RESTORE_LIBS=-lz
LIBS=-luuid -lm -lz
ifeq ("$(origin V)", "command line")
BUILD_VERBOSE = $(V)
@ -38,7 +38,7 @@ MAKEOPTS = --no-print-directory Q=$(Q)
progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \
btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \
btrfs-find-root btrfs-restore btrfstune btrfs-show-super
btrfs-find-root btrfstune btrfs-show-super
# Create all the static targets
static_objects = $(patsubst %.o, %.static.o, $(objects))
@ -95,10 +95,6 @@ btrfs-find-root: $(objects) find-root.o
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o btrfs-find-root find-root.o $(objects) $(LDFLAGS) $(LIBS)
btrfs-restore: $(objects) restore.o
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o btrfs-restore restore.o $(objects) $(LDFLAGS) $(LIBS) $(RESTORE_LIBS)
btrfsctl: $(objects) btrfsctl.o
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS)

View File

@ -247,6 +247,7 @@ const struct cmd_group btrfs_cmd_group = {
{ "device", cmd_device, NULL, &device_cmd_group, 0 },
{ "scrub", cmd_scrub, NULL, &scrub_cmd_group, 0 },
{ "check", cmd_check, cmd_check_usage, NULL, 0 },
{ "restore", cmd_restore, cmd_restore_usage, NULL, 0 },
{ "inspect-internal", cmd_inspect, NULL, &inspect_cmd_group, 0 },
{ "send", cmd_send, cmd_send_usage, NULL, 0 },
{ "receive", cmd_receive, cmd_receive_usage, NULL, 0 },

View File

@ -37,6 +37,7 @@
#include "version.h"
#include "volumes.h"
#include "utils.h"
#include "commands.h"
static char path_name[4096];
static int get_snaps = 0;
@ -673,12 +674,6 @@ next:
return 0;
}
static void usage()
{
fprintf(stderr, "Usage: restore [-svio] [-t disk offset] <device> "
"<directory>\n");
}
static struct btrfs_root *open_fs(const char *dev, u64 root_location, int super_mirror)
{
struct btrfs_root *root;
@ -756,7 +751,26 @@ out:
return ret;
}
int main(int argc, char **argv)
const char * const cmd_restore_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",
"-r <num> root objectid",
"-c ignore case in regular expression",
"-m <regexp> regular expression to match",
"-l list roots",
NULL
};
int cmd_restore(int argc, char **argv)
{
struct btrfs_root *root;
struct btrfs_key key;
@ -813,15 +827,12 @@ int main(int argc, char **argv)
find_dir = 1;
break;
default:
usage();
exit(1);
usage(cmd_restore_usage);
}
}
if (optind + 1 >= argc) {
usage();
exit(1);
}
if (optind + 1 >= argc)
usage(cmd_restore_usage);
if ((ret = check_mounted(argv[optind])) < 0) {
fprintf(stderr, "Could not check mount status: %s\n",

View File

@ -93,8 +93,8 @@ extern const struct cmd_group replace_cmd_group;
extern const char * const cmd_send_usage[];
extern const char * const cmd_receive_usage[];
extern const char * const cmd_check_usage[];
extern const char * const cmd_restore_usage[];
int cmd_subvolume(int argc, char **argv);
int cmd_filesystem(int argc, char **argv);
@ -108,6 +108,10 @@ int cmd_receive(int argc, char **argv);
int cmd_quota(int argc, char **argv);
int cmd_qgroup(int argc, char **argv);
int cmd_replace(int argc, char **argv);
int cmd_restore(int argc, char **argv);
int cmd_select_super(int argc, char **argv);
int cmd_dump_super(int argc, char **argv);
int cmd_debug_tree(int argc, char **argv);
/* subvolume exported functions */
int test_issubvolume(char *path);