diff --git a/scan.c b/scan.c index aa5ee5c5..f4bb007a 100644 --- a/scan.c +++ b/scan.c @@ -111,9 +111,11 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, /* do a safety check to ensure that the common ext4 case of zeroing */ /* the size of a file after a crash doesn't propagate to the backup */ if (file->size != 0 && st->st_size == 0) { - fprintf(stderr, "The file '%s' in disk '%s' at dir '%s' has zero size!\n", sub, disk->name, disk->dir); - fprintf(stderr, "If it's really what you want to do, use 'snapraid --force sync\n"); - exit(EXIT_FAILURE); + if (!state->force_zero) { + fprintf(stderr, "The file '%s' in disk '%s' at dir '%s' has now zero size!\n", sub, disk->name, disk->dir); + fprintf(stderr, "If it's really what you want to sync it, use 'snapraid --force-zero sync\n"); + exit(EXIT_FAILURE); + } } /* remove and reinsert it */ @@ -247,9 +249,9 @@ void state_scan(struct snapraid_state* state) /* if all the previous file were removed */ if (scan[i].count_equal == 0 && scan[i].count_remove != 0) { - if (!state->force) { + if (!state->force_empty) { fprintf(stderr, "All the file in disk '%s' at dir '%s' are missing!\n", disk->name, disk->dir); - fprintf(stderr, "If it's really what you want to do, use 'snapraid --force sync\n"); + fprintf(stderr, "If it's really what you want to sync it, use 'snapraid --force-empty sync\n"); exit(EXIT_FAILURE); } } diff --git a/snapraid.c b/snapraid.c index ce64c2b0..beab6a78 100644 --- a/snapraid.c +++ b/snapraid.c @@ -36,7 +36,8 @@ void usage(void) { printf("Options:\n"); printf(" " SWITCH_GETOPT_LONG("-c, --conf FILE ", "-c") " Configuration file (default /etc/" PACKAGE ".conf)\n"); printf(" " SWITCH_GETOPT_LONG("-s, --start BLK ", "-s") " Start from the specified block number\n"); - printf(" " SWITCH_GETOPT_LONG("-f, --force ", "-f") " Force dangerous operations\n"); + printf(" " SWITCH_GETOPT_LONG("-Z, --force-zero ", "-Z") " Force synching of files that get zero size\n"); + printf(" " SWITCH_GETOPT_LONG("-E, --force-empty ", "-E") " Force synching of disks that get empty\n"); printf(" " SWITCH_GETOPT_LONG("-v, --verbose ", "-v") " Verbose\n"); printf(" " SWITCH_GETOPT_LONG("-h, --help ", "-h") " Help\n"); printf(" " SWITCH_GETOPT_LONG("-V, --version ", "-V") " Version\n"); @@ -46,7 +47,8 @@ void usage(void) { struct option long_options[] = { { "conf", 1, 0, 'c' }, { "start", 1, 0, 's' }, - { "force", 0, 0, 'f' }, + { "force-zero", 0, 0, 'Z' }, + { "force-empty", 0, 0, 'E' }, { "verbose", 0, 0, 'v' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'V' }, @@ -54,7 +56,7 @@ struct option long_options[] = { }; #endif -#define OPTIONS "c:s:fvhV" +#define OPTIONS "c:s:ZEvhV" volatile int global_interrupt = 0; @@ -75,7 +77,8 @@ int main(int argc, char* argv[]) { int c; int verbose; - int force; + int force_zero; + int force_empty; const char* conf; struct snapraid_state state; int operation; @@ -87,7 +90,8 @@ int main(int argc, char* argv[]) /* defaults */ conf = "/etc/" PACKAGE ".conf"; verbose = 0; - force = 0; + force_zero = 0; + force_empty = 0; blockstart = 0; opterr = 0; @@ -108,8 +112,11 @@ int main(int argc, char* argv[]) exit(EXIT_FAILURE); } break; - case 'f' : - force = 1; + case 'Z' : + force_zero = 1; + break; + case 'E' : + force_empty = 1; break; case 'v' : verbose = 1; @@ -144,7 +151,7 @@ int main(int argc, char* argv[]) state_init(&state); - state_config(&state, conf, verbose, force); + state_config(&state, conf, verbose, force_zero, force_empty); if (operation == OPERATION_SYNC) { state_read(&state); diff --git a/snapraid.d b/snapraid.d index 8a6a617a..676b4bab 100644 --- a/snapraid.d +++ b/snapraid.d @@ -3,7 +3,8 @@ Name{number} Synopsis :snapraid [-c, --conf CONFIG] [-s, --start BLOCK] - : [-f, --force] [-v, --verbose] [-e, --exclude PATTERN] + : [-Z, --force-zero] [-E, --force-empty] + : [-v, --verbose] [-e, --exclude PATTERN] : COMMAND :snapraid [-V, --version] [-h, --help] @@ -254,12 +255,21 @@ Options block number. It could be useful to easy retry to fix some specific block, in case of a damaged disk. - -f, --force - Forces insecure operations. If snapraid detects - an unsafe operation, it stops the execution asking you - to use this option to force the operation. - For example, it happens if all the files in a disk are - missing. + -Z, --force-zero + Forces the insecure operation of synching a file with zero + size that before was not empty. + If SnapRAID detects such condition, it stops proceeding + unless you specify this option. + This allows to easily detect when after a system crash, + some accessed files were zeroed. + + -E, --force-empty + Forces the insecure operation of synching an empty disk + that before was not empty. + If SnapRAID detects such condition, it stops proceeding + unless you specify this option. + This allows to easily detect when a data filesystem is not + mounted. -v, --verbose Prints more information in the processing. diff --git a/snapraid.html b/snapraid.html index 452145eb..19f66eb2 100644 --- a/snapraid.html +++ b/snapraid.html @@ -9,7 +9,8 @@ Synopsis
snapraid [-c, --conf CONFIG] [-s, --start BLOCK] - [-f, --force] [-v, --verbose] [-e, --exclude PATTERN] + [-Z, --force-zero] [-E, --force-empty] + [-v, --verbose] [-e, --exclude PATTERN] COMMAND
@@ -191,6 +192,8 @@ parity FILE Defines the file to use to store the redundancy information. It must be placed in a disk dedicated for this porpose with as much free space as the biggest disk in the array. +Leaving the parity disk reserved for only this file, ensures that +it doesn't get fragmented, improving the performance. This option can be used only one time. @@ -200,8 +203,8 @@ content FILE
| --f, --force +-Z, --force-zero |
| -Forces insecure operations. If snapraid detects -an unsafe operation, it stops the execution asking you -to use this option to force the operation. -For example, it happens if all the files in a disk are -missing. +Forces the insecure operation of synching a file with zero +size that before was not empty. +If SnapRAID detects such condition, it stops proceeding +unless you specify this option. +This allows to easily detect when after a system crash, +some accessed files were zeroed. + |
| +-E, --force-empty + |
| +Forces the insecure operation of synching an empty disk +that before was not empty. +If SnapRAID detects such condition, it stops proceeding +unless you specify this option. +This allows to easily detect when a data filesystem is not +mounted. |