summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Kumlien <pomac@demius.net>2013-02-08 01:37:02 +0100
committerDavid Sterba <dsterba@suse.cz>2013-02-12 23:46:15 +0100
commite43cc461550130494194201037590a2b1f0f6880 (patch)
tree2ab08a012acda54d7c60773ec219401d9a3b937d
parent1b1e07190f84440ab7806453f4744aef6c27b46e (diff)
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>
-rw-r--r--Makefile12
-rw-r--r--btrfs.c1
-rw-r--r--cmds-restore.c37
-rw-r--r--commands.h6
4 files changed, 34 insertions, 22 deletions
diff --git a/Makefile b/Makefile
index 7a679d00..e83cf5b0 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/btrfs.c b/btrfs.c
index a7dc50d8..691adef2 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -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 },
diff --git a/cmds-restore.c b/cmds-restore.c
index 5cdb8443..12b21881 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -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",
diff --git a/commands.h b/commands.h
index ddb636f7..15c616d5 100644
--- a/commands.h
+++ b/commands.h
@@ -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);