From patchwork Fri Feb 7 17:12:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Maggard X-Patchwork-Id: 3606911 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 74614C02E3 for ; Fri, 7 Feb 2014 17:12:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A26D220117 for ; Fri, 7 Feb 2014 17:12:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8040D2011D for ; Fri, 7 Feb 2014 17:12:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751287AbaBGRMY (ORCPT ); Fri, 7 Feb 2014 12:12:24 -0500 Received: from mail-pd0-f177.google.com ([209.85.192.177]:51179 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750993AbaBGRMU (ORCPT ); Fri, 7 Feb 2014 12:12:20 -0500 Received: by mail-pd0-f177.google.com with SMTP id x10so3343055pdj.8 for ; Fri, 07 Feb 2014 09:12:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=1RPQd1fwk1hBO/uFd+zdCmDQcKJbjJD8ZaUQ3q6ZvQ8=; b=NczHjsvUcgsdJz1CSa7JQcS040U3fdcrLdNWQw6+wEvvFo3xaTMieJ0N1cbwSpPpN6 mFAYI6XhBCzcdAhsgVVVcgTeQADNcgqna1Woj9jIrPm8PtSiHTdwQtrj2M/VJkybqNP/ cC0l0uLXN8Tmb87WRAjT2dG4aB1bSy6V1Mi/7AO9kMdoMf0X/E5Jhm0Xoi8zy+X5qzn9 oCfZZRtztJj5ZRbut9wDHLLXIGZBaFb+GFxo/ty2A50813Jbp3qpMnVkOBWUZFB48XpP BAB8T7WoMseJJpKezMAaDd76kcSCerRR6+BM6K/qcBKeKbwGyTvHFZgG6swREZ0olGZb dH5A== X-Received: by 10.68.197.99 with SMTP id it3mr20805574pbc.37.1391793139506; Fri, 07 Feb 2014 09:12:19 -0800 (PST) Received: from jmaggard-ThinkPad-W520.infrant-6.com ([209.249.181.1]) by mx.google.com with ESMTPSA id q7sm15430249pbc.20.2014.02.07.09.12.17 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Feb 2014 09:12:18 -0800 (PST) From: Justin Maggard To: linux-btrfs@vger.kernel.org Cc: Justin Maggard Subject: [PATCH] btrfs-progs: add dry-run option to restore command Date: Fri, 7 Feb 2014 09:12:03 -0800 Message-Id: <1391793123-4617-1-git-send-email-jmaggard10@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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 root objectid", "-d find dir", "-l list tree roots", + "-D dry run (only list files that would be recovered)", "--path-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;