From: Justin Maggard <jmaggard10@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Justin Maggard <jmaggard10@gmail.com>
Subject: [PATCH v2] btrfs-progs: add dry-run option to restore command
Date: Fri, 14 Feb 2014 10:40:47 -0800 [thread overview]
Message-ID: <1392403247-3627-1-git-send-email-jmaggard10@gmail.com> (raw)
Sometimes it is useful to see what btrfs restore is going to do
before provisioning enough external storage to restore onto.
Add a dry-run option so we can see what files and paths are found
by restore, without actually restoring any data.
Signed-off-by: Justin Maggard <jmaggard10@gmail.com>
---
cmds-restore.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/cmds-restore.c b/cmds-restore.c
index 1748262..26792a8 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -53,6 +53,7 @@ static int verbose = 0;
static int ignore_errors = 0;
static int overwrite = 0;
static int get_xattrs = 0;
+static int dry_run = 0;
#define LZO_LEN 4
#define PAGE_CACHE_SIZE 4096
@@ -801,6 +802,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
}
if (verbose)
printf("Restoring %s\n", path_name);
+ if (dry_run)
+ goto next;
fd = open(path_name, O_CREAT|O_WRONLY, 0644);
if (fd < 0) {
fprintf(stderr, "Error creating %s: %d\n",
@@ -873,7 +876,10 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
printf("Restoring %s\n", path_name);
errno = 0;
- ret = mkdir(path_name, 0755);
+ if (dry_run)
+ ret = 0;
+ else
+ ret = mkdir(path_name, 0755);
if (ret && errno != EEXIST) {
free(dir);
fprintf(stderr, "Error mkdiring %s: %d\n",
@@ -1090,6 +1096,7 @@ out:
static struct option long_options[] = {
{ "path-regex", 1, NULL, 256},
+ { "dry-run", 0, NULL, 'D'},
{ NULL, 0, NULL, 0}
};
@@ -1105,9 +1112,10 @@ const char * const cmd_restore_usage[] = {
"-t <location> tree location",
"-f <offset> filesystem location",
"-u <block> super mirror",
- "-r <rootid> root objectid",
+ "-r <rootid> root objectid",
"-d find dir",
"-l list tree roots",
+ "-D|--dry-run dry run (only list files that would be recovered)",
"--path-regex <regex>",
" restore only filenames matching regex,",
" you have to use following syntax (possibly quoted):",
@@ -1135,7 +1143,7 @@ int cmd_restore(int argc, char **argv)
regex_t match_reg, *mreg = NULL;
char reg_err[256];
- while ((opt = getopt_long(argc, argv, "sxviot:u:df:r:lc", long_options,
+ while ((opt = getopt_long(argc, argv, "sxviot:u:df:r:lDc", long_options,
&option_index)) != -1) {
switch (opt) {
@@ -1191,6 +1199,9 @@ int cmd_restore(int argc, char **argv)
case 'l':
list_roots = 1;
break;
+ case 'D':
+ dry_run = 1;
+ break;
case 'c':
match_cflags |= REG_ICASE;
break;
--
1.7.9.5
next reply other threads:[~2014-02-14 18:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-14 18:40 Justin Maggard [this message]
2014-02-14 18:59 ` [PATCH v2] btrfs-progs: add dry-run option to restore command David Sterba
2014-02-14 19:16 ` Justin Maggard
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=1392403247-3627-1-git-send-email-jmaggard10@gmail.com \
--to=jmaggard10@gmail.com \
--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;
as well as URLs for NNTP newsgroup(s).