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
}
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",
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",
static struct option long_options[] = {
{ "path-regex", 1, NULL, 256},
+ { "dry-run", 0, NULL, 'D'},
{ NULL, 0, NULL, 0}
};
"-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):",
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) {
case 'l':
list_roots = 1;
break;
+ case 'D':
+ dry_run = 1;
+ break;
case 'c':
match_cflags |= REG_ICASE;
break;
mreg = &match_reg;
}
+ if (dry_run)
+ printf("This is a dry-run, no files are going to be restored\n");
+
ret = search_dir(root, &key, dir_name, "", mreg);
out: