Adds more extensive tests

This commit is contained in:
Andrea Mazzoleni 2011-03-12 23:21:32 +01:00
parent 7c64ee26f9
commit 2bea59f042
10 changed files with 308 additions and 141 deletions

View file

@ -11,9 +11,10 @@ type:
make install
then change the example configuration file snapraid.conf to fit
your needs and copy it in /etc/snapraid.conf.
then change the example configuration file snapraid.conf.example
to fit your needs and copy it in /etc/snapraid.conf
The documentation is in the man page:
man snapraid

View file

@ -1,5 +1,5 @@
bin_PROGRAMS = snapraid
check_PROGRAMS = testgen
check_PROGRAMS = mktest
snapraid_SOURCES = \
snapraid.c \
@ -33,8 +33,8 @@ noinst_HEADERS = \
tommyhashdyn.c \
tommylist.c
testgen_SOURCES = \
testgen.c
mktest_SOURCES = \
mktest.c
EXTRA_DIST = \
autogen.sh \
@ -63,29 +63,34 @@ check-local:
mkdir test/disk1
mkdir test/disk2
mkdir test/disk3
echo Create some files, sync and check
./testgen 1 3 2000
echo --- Create some files, sync and check
./mktest generate 1 3 1000 4000
./snapraid -c $(srcdir)/test.conf sync
./snapraid -c $(srcdir)/test.conf check
echo Create some more files, sync and check
./testgen 2 3 2000
echo --- Create some more files, sync and check
./mktest generate 2 3 1000 4000
./snapraid -c $(srcdir)/test.conf sync
./snapraid -c $(srcdir)/test.conf check
echo Delete some files, fix and check
echo --- Delete some files, fix and check
rm test/disk1/a*
./snapraid -c $(srcdir)/test.conf check 2>/dev/null
./snapraid -c $(srcdir)/test.conf fix 2>/dev/null
./snapraid -c $(srcdir)/test.conf check
echo Delete the parity, fix and check
echo --- Delete the parity, fix and check
rm test/parity
./snapraid -c $(srcdir)/test.conf check 2>/dev/null
./snapraid -c $(srcdir)/test.conf fix 2>/dev/null
./snapraid -c $(srcdir)/test.conf check
echo Corrupt the parity, fix and check
dd if=/dev/zero of=test/parity bs=1024 count=1000 seek=1000 conv=notrunc
echo --- Corrupt the parity, fix and check
./mktest damage 1 10 10000 test/parity
./snapraid -c $(srcdir)/test.conf check 2>/dev/null
./snapraid -c $(srcdir)/test.conf fix 2>/dev/null
./snapraid -c $(srcdir)/test.conf check
echo --- Corrupt some files, fix and check
./mktest damage 1 1 500 test/disk2/b*
./snapraid -c $(srcdir)/test.conf check 2>/dev/null
./snapraid -c $(srcdir)/test.conf fix 2>/dev/null
./snapraid -c $(srcdir)/test.conf check
echo Success!
valgrind:

22
README
View file

@ -2,9 +2,29 @@ SnapRAID
========
SnapRAID is a backup program for a disk array using redundancy.
Just like a RAID system but based on snapshots.
SnapRAID uses a disk of the array to store redundancy information,
and it allows to recover from a complete disk failure.
SnapRAID is mainly targeted for a home media server, where you have
a lot of big files that rarely change.
The main features of SnapRAID are:
* You can start using SnapRAID with already filled disks.
You do not have to reformat or copy your data.
* The disks of the array can have different sizes.
You have only to use the biggest one for the redundancy data.
* If you accidentally delete some files in a disk, you can
recover them.
* If more than one disk fails, you lose the data only on the failed disks.
All the data in the other disks is safe.
* It doesn't lock-in your data.
You can stop using SnapRAID at any time.
The official site of SnapRAID is:
http://snapraid.sourceforge.net

View file

@ -119,7 +119,7 @@
#define PACKAGE_NAME "snapraid"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "snapraid 0.1"
#define PACKAGE_STRING "snapraid 0.2"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "snapraid"
@ -128,7 +128,7 @@
#define PACKAGE_URL "http://snapraid.sourceforge.net"
/* Define to the version of this package. */
#define PACKAGE_VERSION "0.1"
#define PACKAGE_VERSION "0.2"
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
@ -159,7 +159,7 @@
/* Version number of package */
#define VERSION "0.1"
#define VERSION "0.2"
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */

View file

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ([2.65])
AC_INIT([snapraid], [0.1], [], [], [http://snapraid.sourceforge.net])
AC_INIT([snapraid], [0.2], [], [], [http://snapraid.sourceforge.net])
AM_INIT_AUTOMAKE([foreign no-dependencies])
AC_CONFIG_SRCDIR([snapraid.c])
AC_CONFIG_HEADER([config.h])

161
mktest.c Normal file
View file

@ -0,0 +1,161 @@
/*
* Copyright (C) 2011 Andrea Mazzoleni
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "portable.h"
/**
* Pseudo random number generator.
*/
unsigned long long seed = 0;
unsigned rnd(unsigned max)
{
seed = seed * 6364136223846793005LL + 1442695040888963407LL;
return (seed >> 32) % max;
}
void generate(int disk, int size)
{
char path[PATH_MAX];
char name[PATH_MAX];
FILE* f;
int count;
int i;
int l;
l = 1 + rnd(32);
for(i=0;i<l;++i) {
name[i] = 'a' + rnd(22);
}
name[i] = 0;
snprintf(path, sizeof(path), "test/disk%d/%s", disk, name);
f = fopen(path, "w");
if (!f) {
fprintf(stderr, "Error writing %s\n", path);
exit(EXIT_FAILURE);
}
count = size;
while (count) {
fputc(rnd(256), f);
--count;
}
fclose(f);
}
void damage(const char* path, int size)
{
FILE* f;
struct stat st;
off_t start;
int count;
f = fopen(path, "r+");
if (!f) {
fprintf(stderr, "Error writing %s\n", path);
exit(EXIT_FAILURE);
}
if (fstat(fileno(f), &st) != 0) {
fprintf(stderr, "Error accessing %s\n", path);
exit(EXIT_FAILURE);
}
/* start at random position inside the file */
start = rnd(st.st_size);
if (fseek(f, start, SEEK_SET) != 0) {
fprintf(stderr, "Error seeking %s\n", path);
exit(EXIT_FAILURE);
}
/* write garbage, in case also over the end */
count = rnd(size);
while (count) {
fputc(rnd(256), f);
--count;
}
fclose(f);
}
void help(void)
{
printf("Test for " PACKAGE " v" VERSION " by Andrea Mazzoleni, " PACKAGE_URL "\n");
printf("Usage:\n");
printf("\tmktest generate SEED DISK_NUM FILE_NUM FILE_SIZE\n");
printf("\tmktest damage SEED FAIL_NUM FAIL_SIZE FILE\n");
}
int main(int argc, char* argv[])
{
int i, j;
if (argc < 2) {
help();
exit(EXIT_FAILURE);
}
if (strcmp(argv[1], "generate") == 0) {
int disk, file, size;
if (argc != 6) {
help();
exit(EXIT_FAILURE);
}
seed = atoi(argv[2]);
disk = atoi(argv[3]);
file = atoi(argv[4]);
size = atoi(argv[5]);
for(i=0;i<disk;++i) {
for(j=0;j<file;++j) {
generate(i+1, rnd(size));
}
}
} else if (strcmp(argv[1], "damage") == 0) {
int fail, size;
const char* file;
if (argc < 6) {
help();
exit(EXIT_FAILURE);
}
seed = atoi(argv[2]);
fail = atoi(argv[3]);
size = atoi(argv[4]);
for(i=5;i<argc;++i) {
for(j=0;j<fail;++j) {
damage(argv[i], rnd(size));
}
}
} else {
help();
exit(EXIT_FAILURE);
}
return 0;
}

View file

@ -12,12 +12,10 @@ Description
SnapRAID is a backup program for a disk array using redundancy.
SnapRAID uses a disk of the array to store redundancy information,
and it allows to recover from a complete disk failure.
and it allows to recover from a disk failure.
SnapRAID is based on the snapshot concept like a backup program.
You decide the time to make the "sync" of the redundancy information,
and you are able to restore all the changes done at a disk of the array,
until the "sync".
SnapRAID is mainly targeted for a home media server, where you have
a lot of big files that rarely change.
The main features of SnapRAID are:
@ -25,18 +23,37 @@ Description
You do not have to reformat or copy your data.
* The disks of the array can have different sizes.
You have only to use the biggest one for the redundancy data.
* The data in the disks is not changed in any way.
It doesn't even need write access at the data.
* If more than one disk fails, you lose the data only on the failed disks.
All the data in the other disks is safe.
* If you accidentally delete some files in a disk, you can
recover them.
* If more than one disk fails, you lose the data only on the
failed disks. All the data in the other disks is safe.
* It doesn't lock-in your data.
You can stop using SnapRAID at any time.
You can stop using SnapRAID at any time without the
need to reformat or move data.
The official site of SnapRAID is:
:http://snapraid.sourceforge.net
Limitations
SnapRAID is in between a RAID and a backup program trying to get the best
benefits of them. Altough it also has some downsides that you should
consider before using it:
benefits of them. Altought it also has some limitations that you should
consider before using it.
The main one, is that if a disk fail, and you haven't recently synched,
you may not able to do a complete recover.
More specifically, you may be unable to recover up to the size of the
amount of the changed or deleted files, from the last sync operation.
This happens even if the files changed or deleted are not in the
failed disk.
New added files don't prevent the recovering of the already existing
files. You may only lose the just added files, if they were on the failed
disk.
This is the reason because SnapRAID is better suited for data that
rarely change.
Other limitations are:
* You have different filesystems for each disk.
Using a RAID you have only a big filesystem.
* It doesn't stripe data.
@ -49,7 +66,7 @@ Limitations
Getting Started
To use SnapRAID you need first to mount all the disks of your disk
array and select which one to dedicate as redundancy information.
array and select which one to dedicate at the redundancy information.
This disk will be dedicated to this pourpuse only, and you should
not store any other data on it.
@ -79,7 +96,7 @@ Getting Started
:snapraid sync
This process will take some hours at best the first time, depending on
the size of the data already present in the data disks.
the size of the data already present in the disks.
If the disks are empty the process is immediate.
You can stop it at any time pressing Ctrl+C, and at the next run it
will start where interrupted.

View file

@ -22,12 +22,10 @@ Description
SnapRAID is a backup program for a disk array using redundancy.
<p>
SnapRAID uses a disk of the array to store redundancy information,
and it allows to recover from a complete disk failure.
and it allows to recover from a disk failure.
<p>
SnapRAID is based on the snapshot concept like a backup program.
You decide the time to make the "sync" of the redundancy information,
and you are able to restore all the changes done at a disk of the array,
until the "sync".
SnapRAID is mainly targeted for a home media server, where you have
a lot of big files that rarely change.
<p>
The main features of SnapRAID are:
<ul>
@ -40,29 +38,53 @@ The disks of the array can have different sizes.
You have only to use the biggest one for the redundancy data.
</li>
<li>
The data in the disks is not changed in any way.
It doesn't even need write access at the data.
If you accidentally delete some files in a disk, you can
recover them.
</li>
<li>
If more than one disk fails, you lose the data only on the failed disks.
All the data in the other disks is safe.
If more than one disk fails, you lose the data only on the
failed disks. All the data in the other disks is safe.
</li>
<li>
It doesn't lock-in your data.
You can stop using SnapRAID at any time.
You can stop using SnapRAID at any time without the
need to reformat or move data.
</li>
</ul>
<p>
The official site of SnapRAID is:
<p>
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td width="5%"></td><td width="95%">
<pre>
<a href="http://snapraid.sourceforge.net">http://snapraid.sourceforge.net</a>
</pre>
</td></tr></table>
<h2><a name="3">3</a>
Limitations
</h2>
SnapRAID is in between a RAID and a backup program trying to get the best
benefits of them. Altough it also has some downsides that you should
consider before using it:
<ul>
<li>
You have different filesystems for each disk.
benefits of them. Altought it also has some limitations that you should
consider before using it.
<p>
The main one, is that if a disk fail, and you haven't recently synched,
you may not able to do a complete recover.
More specifically, you may be unable to recover up to the size of the
amount of the changed or deleted files, from the last sync operation.
This happens even if the files changed or deleted are not in the
failed disk.
New added files don't prevent the recovering of the already existing
files. You may only lose the just added files, if they were on the failed
disk.
<p>
This is the reason because SnapRAID is better suited for data that
rarely change.
<p>
Other limitations are:
* You have different filesystems for each disk.
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td width="5%"></td><td width="95%">
Using a RAID you have only a big filesystem.
</li>
</td></tr></table>
<ul>
<li>
It doesn't stripe data.
With RAID you get a speed boost with striping.
@ -81,7 +103,7 @@ failure of the whole disk array.
Getting Started
</h2>
To use SnapRAID you need first to mount all the disks of your disk
array and select which one to dedicate as redundancy information.
array and select which one to dedicate at the redundancy information.
<p>
This disk will be dedicated to this pourpuse only, and you should
not store any other data on it.
@ -123,7 +145,7 @@ snapraid sync
</td></tr></table>
<p>
This process will take some hours at best the first time, depending on
the size of the data already present in the data disks.
the size of the data already present in the disks.
If the disks are empty the process is immediate.
You can stop it at any time pressing Ctrl+C, and at the next run it
will start where interrupted.

View file

@ -19,12 +19,10 @@ snapraid [-V, --version] [-h, --help]
SnapRAID is a backup program for a disk array using redundancy.
SnapRAID uses a disk of the array to store redundancy information,
and it allows to recover from a complete disk failure.
and it allows to recover from a disk failure.
SnapRAID is based on the snapshot concept like a backup program.
You decide the time to make the "sync" of the redundancy information,
and you are able to restore all the changes done at a disk of the array,
until the "sync".
SnapRAID is mainly targeted for a home media server, where you have
a lot of big files that rarely change.
The main features of SnapRAID are:
@ -32,23 +30,42 @@ The main features of SnapRAID are:
You do not have to reformat or copy your data.
* The disks of the array can have different sizes.
You have only to use the biggest one for the redundancy data.
* The data in the disks is not changed in any way.
It doesn't even need write access at the data.
* If more than one disk fails, you lose the data only on the failed disks.
All the data in the other disks is safe.
* If you accidentally delete some files in a disk, you can
recover them.
* If more than one disk fails, you lose the data only on the
failed disks. All the data in the other disks is safe.
* It doesn't lock-in your data.
You can stop using SnapRAID at any time.
You can stop using SnapRAID at any time without the
need to reformat or move data.
The official site of SnapRAID is:
http://snapraid.sourceforge.net
3 LIMITATIONS
=============
SnapRAID is in between a RAID and a backup program trying to get the best
benefits of them. Altough it also has some downsides that you should
consider before using it:
benefits of them. Altought it also has some limitations that you should
consider before using it.
The main one, is that if a disk fail, and you haven't recently synched,
you may not able to do a complete recover.
More specifically, you may be unable to recover up to the size of the
amount of the changed or deleted files, from the last sync operation.
This happens even if the files changed or deleted are not in the
failed disk.
New added files don't prevent the recovering of the already existing
files. You may only lose the just added files, if they were on the failed
disk.
This is the reason because SnapRAID is better suited for data that
rarely change.
Other limitations are:
* You have different filesystems for each disk.
Using a RAID you have only a big filesystem.
Using a RAID you have only a big filesystem.
* It doesn't stripe data.
With RAID you get a speed boost with striping.
* It doesn't support realtime recovery.
@ -62,7 +79,7 @@ consider before using it:
=================
To use SnapRAID you need first to mount all the disks of your disk
array and select which one to dedicate as redundancy information.
array and select which one to dedicate at the redundancy information.
This disk will be dedicated to this pourpuse only, and you should
not store any other data on it.
@ -92,7 +109,7 @@ redundancy information.
snapraid sync
This process will take some hours at best the first time, depending on
the size of the data already present in the data disks.
the size of the data already present in the disks.
If the disks are empty the process is immediate.
You can stop it at any time pressing Ctrl+C, and at the next run it
will start where interrupted.

View file

@ -1,76 +0,0 @@
/*
* Copyright (C) 2011 Andrea Mazzoleni
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "portable.h"
void gen(int disk, int size)
{
char path[PATH_MAX];
char name[PATH_MAX];
FILE* f;
int i;
int l;
l = 1 + rand() % 32;
for(i=0;i<l;++i) {
name[i] = 'a' + (rand() % 22);
}
name[i] = 0;
snprintf(path, sizeof(path), "test/disk%d/%s", disk, name);
f = fopen(path, "w");
if (!f) {
fprintf(stderr, "Error writing %s\n", path);
exit(EXIT_FAILURE);
}
while (size) {
fputc(size, f);
--size;
}
fclose(f);
}
int main(int argc, char* argv[])
{
int i, j;
int s = 1;
int d = 3;
int n = 100;
if (argc != 4) {
fprintf(stderr, "Syntax: testgen SEED DISK FILE\n");
exit(EXIT_FAILURE);
}
s = atoi(argv[1]);
d = atoi(argv[2]);
n = atoi(argv[3]);
srand(s);
for(i=0;i<d;++i) {
for(j=0;j<n;++j) {
gen(i+1, j);
}
}
return 0;
}