dedup

deduplicating backup program
git clone git://git.2f30.org/dedup
Log | Files | Refs | README | LICENSE

commit 6499f2d353ff8cc5cffeb336cee6c8dbf20679c2
parent 27bf6699242c15fb69fcb20f5afcf46665902fa5
Author: sin <sin@2f30.org>
Date:   Thu, 18 Apr 2019 11:36:14 +0100

dinfo: Implement terse mode output

Diffstat:
Mdinfo.1 | 16++++++++++++++--
Mdinfo.c | 67++++++++++++++++++++++++++++++++++++++++++-------------------------
2 files changed, 56 insertions(+), 27 deletions(-)

diff --git a/dinfo.1 b/dinfo.1 @@ -1,4 +1,4 @@ -.Dd April 17, 2019 +.Dd April 18, 2019 .Dt DINFO 1 .Os .Sh NAME @@ -6,7 +6,7 @@ .Nd Print information about a dedup repository .Sh SYNOPSIS .Nm dinfo -.Op Fl v +.Op Fl tv .Op repo .Sh DESCRIPTION .Nm @@ -17,6 +17,18 @@ is specified, then the current directory is assumed to be the repository. .Sh OPTIONS .Bl -tag -width "-v" +.It Fl t +Enable terse mode. +The output fields are as follows: +.br +[original dataset size] +[compressed dataset size] +[deduplicated dataset size] +[deduplication ratio] +[min block size] +[average block size] +[max block size] +[number of unique blocks] .It Fl v Enable verbose mode. .El diff --git a/dinfo.c b/dinfo.c @@ -25,32 +25,45 @@ int verbose; char *argv0; static void -print_info(void) +print_info(int tflag) { struct stats *st = &snap_hdr.st; - fprintf(stderr, "Compression algorithm: %s\n", - compr_type2name(compr_algo)); - fprintf(stderr, "Hash algorithm: %s\n", - hash_type2name(hash_algo)); - - if (st->nr_blks == 0) - return; - - fprintf(stderr, "Original size: %llu bytes\n", - (unsigned long long)st->orig_size); - fprintf(stderr, "Compressed size: %llu bytes\n", - (unsigned long long)st->compr_size); - fprintf(stderr, "Deduplicated size: %llu bytes\n", - (unsigned long long)st->dedup_size); - fprintf(stderr, "Deduplication ratio: %.2f\n", - (double)st->orig_size / st->dedup_size); - fprintf(stderr, "Min/avg/max block size: %llu/%llu/%llu bytes\n", - (unsigned long long)st->min_blk_size, - (unsigned long long)st->dedup_size / st->nr_blks, - (unsigned long long)st->max_blk_size); - fprintf(stderr, "Number of unique blocks: %llu\n", - (unsigned long long)st->nr_blks); + if (!tflag) { + fprintf(stderr, "Compression algorithm: %s\n", + compr_type2name(compr_algo)); + fprintf(stderr, "Hash algorithm: %s\n", + hash_type2name(hash_algo)); + + if (st->nr_blks == 0) + return; + + fprintf(stderr, "Original size: %llu bytes\n", + (unsigned long long)st->orig_size); + fprintf(stderr, "Compressed size: %llu bytes\n", + (unsigned long long)st->compr_size); + fprintf(stderr, "Deduplicated size: %llu bytes\n", + (unsigned long long)st->dedup_size); + fprintf(stderr, "Deduplication ratio: %.2f\n", + (double)st->orig_size / st->dedup_size); + fprintf(stderr, "Min/avg/max block size: %llu/%llu/%llu bytes\n", + (unsigned long long)st->min_blk_size, + (unsigned long long)st->dedup_size / st->nr_blks, + (unsigned long long)st->max_blk_size); + fprintf(stderr, "Number of unique blocks: %llu\n", + (unsigned long long)st->nr_blks); + } else { + /* terse mode */ + fprintf(stderr, "%llu %llu %llu %.2f %llu %llu %llu %llu\n", + (unsigned long long)st->orig_size, + (unsigned long long)st->compr_size, + (unsigned long long)st->dedup_size, + (double)st->orig_size / st->dedup_size, + (unsigned long long)st->min_blk_size, + (unsigned long long)st->dedup_size / st->nr_blks, + (unsigned long long)st->max_blk_size, + (unsigned long long)st->nr_blks); + } } static void @@ -84,7 +97,7 @@ term(void) static void usage(void) { - fprintf(stderr, "usage: %s [-v] [repo]\n", argv0); + fprintf(stderr, "usage: %s [-tv] [repo]\n", argv0); exit(1); } @@ -92,8 +105,12 @@ int main(int argc, char *argv[]) { char *repo = NULL; + int tflag = 0; ARGBEGIN { + case 't': + tflag = 1; + break; case 'v': verbose++; break; @@ -116,7 +133,7 @@ main(int argc, char *argv[]) err(1, "chdir: %s", repo); init(); - print_info(); + print_info(tflag); term(); return 0; }