mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Splits the force option in force-zero and force-empty
This commit is contained in:
parent
f0ed233a58
commit
543658640a
7 changed files with 91 additions and 42 deletions
12
scan.c
12
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
snapraid.c
23
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);
|
||||
|
|
|
|||
24
snapraid.d
24
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.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ Synopsis
|
|||
</h2>
|
||||
<pre>
|
||||
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
|
||||
</pre>
|
||||
<p>
|
||||
|
|
@ -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.
|
||||
</td></tr>
|
||||
</table>
|
||||
|
|
@ -200,8 +203,8 @@ content FILE
|
|||
</strong></td></tr><tr><td>
|
||||
Defines the file to use to store the content of the redundancy
|
||||
organization.
|
||||
It must be placed in the same disk of the parity file, or in
|
||||
another location, but not in a disk of the array.
|
||||
It can be placed in the same disk of the parity file, or better
|
||||
in another disk, but NOT in a disk of the array.
|
||||
This option can be used only one time.
|
||||
</td></tr>
|
||||
</table>
|
||||
|
|
@ -394,13 +397,26 @@ some specific block, in case of a damaged disk.
|
|||
</table>
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="2">
|
||||
<tr valign="top" align="left"><td><strong>
|
||||
-f, --force
|
||||
-Z, --force-zero
|
||||
</strong></td></tr><tr><td>
|
||||
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.
|
||||
</td></tr>
|
||||
</table>
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="2">
|
||||
<tr valign="top" align="left"><td><strong>
|
||||
-E, --force-empty
|
||||
</strong></td></tr><tr><td>
|
||||
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.
|
||||
</td></tr>
|
||||
</table>
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="2">
|
||||
|
|
|
|||
30
snapraid.txt
30
snapraid.txt
|
|
@ -7,7 +7,8 @@
|
|||
==========
|
||||
|
||||
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]
|
||||
|
|
@ -145,13 +146,15 @@ it should contains the following options:
|
|||
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.
|
||||
|
||||
content FILE
|
||||
Defines the file to use to store the content of the redundancy
|
||||
organization.
|
||||
It must be placed in the same disk of the parity file, or in
|
||||
another location, but not in a disk of the array.
|
||||
It can be placed in the same disk of the parity file, or better
|
||||
in another disk, but NOT in a disk of the array.
|
||||
This option can be used only one time.
|
||||
|
||||
disk NAME DIR
|
||||
|
|
@ -277,12 +280,21 @@ For example:
|
|||
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.
|
||||
|
|
|
|||
5
state.c
5
state.c
|
|
@ -51,13 +51,14 @@ void state_done(struct snapraid_state* state)
|
|||
tommy_list_foreach(&state->excludelist, (tommy_foreach_func*)filter_free);
|
||||
}
|
||||
|
||||
void state_config(struct snapraid_state* state, const char* path, int verbose, int force)
|
||||
void state_config(struct snapraid_state* state, const char* path, int verbose, int force_zero, int force_empty)
|
||||
{
|
||||
FILE* f;
|
||||
unsigned line;
|
||||
|
||||
state->verbose = verbose;
|
||||
state->force = force;
|
||||
state->force_zero = force_zero;
|
||||
state->force_empty = force_empty;
|
||||
|
||||
f = fopen(path, "rt");
|
||||
if (!f) {
|
||||
|
|
|
|||
5
state.h
5
state.h
|
|
@ -28,7 +28,8 @@ extern volatile int global_interrupt;
|
|||
|
||||
struct snapraid_state {
|
||||
int verbose; /**< Verbose output. */
|
||||
int force; /**< Forced dangerous operations. */
|
||||
int force_zero; /**< Forced dangerous operations of synching file now with zero size. */
|
||||
int force_empty; /**< Forced dangerous operations of synching disk now empty. */
|
||||
uint32_t block_size; /**< Block size in bytes. */
|
||||
char content[PATH_MAX]; /**< Path of the content file. */
|
||||
char parity[PATH_MAX]; /**< Path of the parity file. */
|
||||
|
|
@ -49,7 +50,7 @@ void state_done(struct snapraid_state* state);
|
|||
/**
|
||||
* Read the configuration file.
|
||||
*/
|
||||
void state_config(struct snapraid_state* state, const char* path, int verbose, int force);
|
||||
void state_config(struct snapraid_state* state, const char* path, int verbose, int force_zero, int force_empty);
|
||||
|
||||
/**
|
||||
* Read the state.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue