From 3ff24945a2bb50a87ba7fc2111f39e6444ad93fc Mon Sep 17 00:00:00 2001 From: Vladimir Stackov Date: Thu, 6 Aug 2015 14:02:55 +0300 Subject: [PATCH] Added boilerplates for index GC Fixed misspelling: s/indicies/indexes/g --- backup_collector.cc | 11 ----------- backup_collector.hh | 7 ------- backup_exchanger.hh | 2 +- config.cc | 9 +++++---- zbackup.cc | 41 +++++++++++++++++++++++++++++++++++------ zutils.cc | 14 +++++++++----- zutils.hh | 3 ++- 7 files changed, 52 insertions(+), 35 deletions(-) diff --git a/backup_collector.cc b/backup_collector.cc index 147f874..5c99c4d 100644 --- a/backup_collector.cc +++ b/backup_collector.cc @@ -3,17 +3,6 @@ #include "backup_collector.hh" -#include -#include - -#include "bundle.hh" -#include "chunk_index.hh" -#include "backup_restorer.hh" -#include "backup_file.hh" -#include "backup_exchanger.hh" - -#include "debug.hh" - using std::string; void BundleCollector::startIndex( string const & indexFn ) diff --git a/backup_collector.hh b/backup_collector.hh index 96669e7..92b1d6c 100644 --- a/backup_collector.hh +++ b/backup_collector.hh @@ -4,18 +4,11 @@ #ifndef BACKUP_COLLECTOR_HH_INCLUDED #define BACKUP_COLLECTOR_HH_INCLUDED -#include "zbackup_base.hh" -#include "chunk_storage.hh" - #include #include -#include -#include "bundle.hh" -#include "chunk_index.hh" #include "backup_restorer.hh" #include "backup_file.hh" -#include "backup_exchanger.hh" #include "debug.hh" diff --git a/backup_exchanger.hh b/backup_exchanger.hh index 457c48f..d32ae73 100644 --- a/backup_exchanger.hh +++ b/backup_exchanger.hh @@ -17,7 +17,7 @@ using std::pair; enum { backups, bundles, - index, + indexes, Flags }; diff --git a/config.cc b/config.cc index d29195c..cd37f00 100644 --- a/config.cc +++ b/config.cc @@ -119,7 +119,7 @@ void Config::prefillKeywords() "Valid values:\n" "backups - exchange backup instructions (files in backups/ directory)\n" "bundles - exchange bundles with data (files in bunles/ directory)\n" - "index - exchange indicies of chunks (files in index/ directory)\n" + "indexes - exchange indexes of chunks (files in index/ directory)\n" "No default value, you should specify it explicitly" }, @@ -439,12 +439,13 @@ bool Config::parseOrValidate( const string & option, const OptionType type, if ( strcmp( optionValue, "bundles" ) == 0 ) runtime.exchange.set( BackupExchanger::bundles ); else - if ( strcmp( optionValue, "index" ) == 0 ) - runtime.exchange.set( BackupExchanger::index ); + if ( strcmp( optionValue, "indexes" ) == 0 || + strcmp( optionValue, "index" ) == 0 ) + runtime.exchange.set( BackupExchanger::indexes ); else { fprintf( stderr, "Invalid exchange value specified: %s\n" - "Must be one of the following: backups, bundles, index.\n", + "Must be one of the following: backups, bundles, indexes.\n", optionValue ); return false; } diff --git a/zbackup.cc b/zbackup.cc index 04479a2..1180977 100644 --- a/zbackup.cc +++ b/zbackup.cc @@ -172,7 +172,8 @@ invalid_option: " performs import from source to destination storage,\n" " for export/import storage path must be\n" " a valid (initialized) storage\n" -" gc - performs chunk garbage collection\n" +" gc [chunks|indexes] - performs garbage\n" +" collection (default is chunks)\n" " passwd - changes repo info file passphrase\n" //" info - shows repo information\n" " config [show|edit|set|reset] - performs\n" @@ -278,15 +279,43 @@ invalid_option: else if ( strcmp( args[ 0 ], "gc" ) == 0 ) { - // Perform the restore - if ( args.size() != 2 ) + // Perform the garbage collection + if ( args.size() < 2 || args.size() > 3 ) { - fprintf( stderr, "Usage: %s %s \n", + fprintf( stderr, "Usage: %s %s [chunks|indexes] \n", *argv, args[ 0 ] ); return EXIT_FAILURE; } - ZCollector zc( args[ 1 ], passwords[ 0 ], config ); - zc.gc(); + + int fieldStorage = 1; + int fieldAction = 2; + + if ( args.size() == 3 ) + { + fieldStorage = 2; + fieldAction = 1; + } + + if ( args.size() > 2 && strcmp( args[ fieldAction ], "chunks" ) == 0 ) + { + ZCollector zc( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ), + passwords[ 0 ], config ); + zc.gcChunks(); + } + else + if ( args.size() > 2 && strcmp( args[ fieldAction ], "indexes" ) == 0 ) + { + ZCollector zc( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ), + passwords[ 0 ], config ); + fprintf( stderr, "NOT IMPLEMENTED YET!\n" ); + zc.gcIndexes(); + } + else + { + ZCollector zc( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ), + passwords[ 0 ], config ); + zc.gcChunks(); + } } else if ( strcmp( args[ 0 ], "passwd" ) == 0 ) diff --git a/zutils.cc b/zutils.cc index d57a524..9818e86 100644 --- a/zutils.cc +++ b/zutils.cc @@ -207,13 +207,13 @@ void ZExchange::exchange() verbosePrintf( "Bundle exchange completed.\n" ); } - if ( config.runtime.exchange.test( BackupExchanger::index ) ) + if ( config.runtime.exchange.test( BackupExchanger::indexes ) ) { - verbosePrintf( "Searching for indicies...\n" ); - vector< string > indicies = BackupExchanger::findOrRebuild( + verbosePrintf( "Searching for indexes...\n" ); + vector< string > indexes = BackupExchanger::findOrRebuild( srcZBackupBase.getIndexPath(), dstZBackupBase.getIndexPath() ); - for ( std::vector< string >::iterator it = indicies.begin(); it != indicies.end(); ++it ) + for ( std::vector< string >::iterator it = indexes.begin(); it != indexes.end(); ++it ) { verbosePrintf( "Processing index file %s... ", it->c_str() ); string outputFileName ( Dir::addPath( dstZBackupBase.getIndexPath(), *it ) ); @@ -307,7 +307,7 @@ ZCollector::ZCollector( string const & storageDir, string const & password, { } -void ZCollector::gc() +void ZCollector::gcChunks() { ChunkIndex chunkReindex( encryptionkey, tmpMgr, getIndexPath(), true ); @@ -366,3 +366,7 @@ void ZCollector::gc() verbosePrintf( "Garbage collection complete\n" ); } + +void ZCollector::gcIndexes() +{ +} diff --git a/zutils.hh b/zutils.hh index 59d23d4..7201ff2 100644 --- a/zutils.hh +++ b/zutils.hh @@ -55,7 +55,8 @@ public: ZCollector( std::string const & storageDir, std::string const & password, Config & configIn ); - void gc(); + void gcChunks(); + void gcIndexes(); }; #endif