Makes a backup copy of the content file.

Before overwriting the existing content file, rename it
adding the .backup extension, but only if such content file
was read and validated.
This commit is contained in:
Andrea Mazzoleni 2014-06-13 18:23:24 +02:00
parent 68042d528d
commit da08ca4497
8 changed files with 49 additions and 16 deletions

View file

@ -5,6 +5,9 @@ SnapRAID HISTORY
=================
* The -N, --force-nocopy option now also works if you used previously
"sync" commands without it.
* When saving the content file keep a copy of the previos one adding
the ".backup" extension.
* Auto exclude the lock file.
6.2 2014/5
==========

7
TODO
View file

@ -5,13 +5,6 @@ This is the list of TODO items for SnapRAID.
- Next
* Keep backup copies of the content file.
Like snapraid.content.1, snapraid.content.2, snapraid.content.3 and so on.
Note that the rotation should happen only one time for each sync,
and not for intermediate sync write.
* Auto exclude lock files.
* Measures the time waited in blocking syscall for each disk,
and prints stats of the disk speeds when the command finish,
or when it's running.

View file

@ -298,6 +298,16 @@ int filter_content(tommy_list* contentlist, const char* path)
pathprint(tmp, sizeof(tmp), "%s.tmp", content->content);
if (pathcmp(tmp, path) == 0)
return -1;
/* exclude also the ".backup" copy */
pathprint(tmp, sizeof(tmp), "%s.backup", content->content);
if (pathcmp(tmp, path) == 0)
return -1;
/* exclude also the ".lock" file */
pathprint(tmp, sizeof(tmp), "%s.lock", content->content);
if (pathcmp(tmp, path) == 0)
return -1;
}
return 0;

View file

@ -4008,6 +4008,9 @@ void state_read(struct snapraid_state* state)
state_map(state);
state_content_check(state, path);
/* mark that we read the content file, and it passed all the checks */
state->checked_read = 1;
}
void state_write(struct snapraid_state* state)
@ -4087,6 +4090,24 @@ void state_write(struct snapraid_state* state)
while (i) {
struct snapraid_content* content = i->data;
char tmp[PATH_MAX];
char backup[PATH_MAX];
/* if the content file was checked reading it, it's a good candidate */
/* to be renamed as backup copy */
if (state->checked_read) {
pathprint(backup, sizeof(backup), "%s.backup", content->content);
if (rename(content->content, backup) != 0) {
/* ignore the error for not existing */
if (errno != ENOENT) {
/* LCOV_EXCL_START */
fprintf(stderr, "Error renaming the content file '%s' to '%s' in rename(). %s.\n", content->content, backup, strerror(errno));
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
}
}
/* now renames the just written copy with the correct name */
pathprint(tmp, sizeof(tmp), "%s.tmp", content->content);
if (rename(tmp, content->content) != 0) {
/* LCOV_EXCL_START */
@ -4094,10 +4115,12 @@ void state_write(struct snapraid_state* state)
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
i = i->next;
}
state->need_write = 0; /* no write needed anymore */
state->checked_read = 0; /* what we wrote is not checked in read */
}
void state_filter(struct snapraid_state* state, tommy_list* filterlist_file, tommy_list* filterlist_disk, int filter_missing, int filter_error)

View file

@ -91,6 +91,7 @@ struct snapraid_state {
int filter_hidden; /**< Filter out hidden files. */
uint64_t autosave; /**< Autosave after the specified amount of data. 0 to disable. */
int need_write; /**< If the state is changed. */
int checked_read; /**< If the state was read and checked. */
uint32_t block_size; /**< Block size in bytes. */
unsigned raid_mode; /**< Raid mode to use. RAID_MODE_DEFAULT or RAID_MODE_ALTERNATE. */
char parity_path[LEV_MAX][PATH_MAX]; /**< Path of the parity file. One for each parity. */

View file

@ -1389,10 +1389,11 @@ SnapRAID stores the list and checksums of your files in the content file.
It\'s a binary file, listing all the files present in your disk array,
with all the checksums to verify their integrity.
.PP
You do not need to understand its format to use SnapRAID.
.PP
This file is read and written by the \[dq]sync\[dq] and \[dq]scrub\[dq] commands, and
only read by \[dq]fix\[dq], \[dq]check\[dq] and \[dq]status\[dq].
read by \[dq]fix\[dq], \[dq]check\[dq] and \[dq]status\[dq].
.PP
When saving a new copy, the previous one is renamed adding the \[dq].backup\[dq]
extension.
.SH PARITY
SnapRAID stores the parity information of your array in the parity
files.

View file

@ -1007,10 +1007,11 @@ Content
It's a binary file, listing all the files present in your disk array,
with all the checksums to verify their integrity.
You do not need to understand its format to use SnapRAID.
This file is read and written by the "sync" and "scrub" commands, and
only read by "fix", "check" and "status".
read by "fix", "check" and "status".
When saving a new copy, the previous one is renamed adding the ".backup"
extension.
Parity
SnapRAID stores the parity information of your array in the parity

View file

@ -1090,10 +1090,11 @@ SnapRAID stores the list and checksums of your files in the content file.
It's a binary file, listing all the files present in your disk array,
with all the checksums to verify their integrity.
You do not need to understand its format to use SnapRAID.
This file is read and written by the "sync" and "scrub" commands, and
only read by "fix", "check" and "status".
read by "fix", "check" and "status".
When saving a new copy, the previous one is renamed adding the ".backup"
extension.
11 PARITY