diff mbox

btrfs-progs: add dry-run option to restore command

Message ID 1391793123-4617-1-git-send-email-jmaggard10@gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Justin Maggard Feb. 7, 2014, 5:12 p.m. UTC
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.
---
 cmds-restore.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

David Sterba Feb. 14, 2014, 4:34 p.m. UTC | #1
On Fri, Feb 07, 2014 at 09:12:03AM -0800, Justin Maggard wrote:
> 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.

Ok, makes sense. I suggest to add the long option --dry-run as well. The
-D option sounds like "no data", so I'm ok to keep it as you've
proposed.

Please resend the patch and add your Signed-off-by line.
--
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
diff mbox

Patch

diff --git a/cmds-restore.c b/cmds-restore.c
index 1748262..5116af0 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",
@@ -1108,6 +1114,7 @@  const char * const cmd_restore_usage[] = {
 	"-r <rootid>	 root objectid",
 	"-d              find dir",
 	"-l              list tree roots",
+	"-D              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 +1142,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 +1198,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;