diff --git a/backup_collector.cc b/backup_collector.cc index 0a2ee08..34fa96f 100644 --- a/backup_collector.cc +++ b/backup_collector.cc @@ -25,7 +25,7 @@ void BundleCollector::finishIndex( string const & indexFn ) else { chunkStorageWriter->reset(); - if ( !indexNecessary ) + if ( gcDeep && !indexNecessary ) // this index was a complete copy so we don't need it filesToUnlink.push_back( indexFn ); } @@ -40,10 +40,13 @@ void BundleCollector::startBundle( Bundle::Id const & bundleId ) void BundleCollector::processChunk( ChunkId const & chunkId ) { - if ( overallChunkSet.find ( chunkId ) == overallChunkSet.end() ) - overallChunkSet.insert( chunkId ); - else - return; + if ( gcDeep ) + { + if ( overallChunkSet.find ( chunkId ) == overallChunkSet.end() ) + overallChunkSet.insert( chunkId ); + else + return; + } totalChunks++; if ( usedChunkSet.find( chunkId ) != usedChunkSet.end() ) @@ -84,7 +87,7 @@ void BundleCollector::finishBundle( Bundle::Id const & bundleId, BundleInfo cons } else { - if ( 0 == totalChunks ) + if ( gcDeep && 0 == totalChunks ) { if ( overallBundleSet.find ( bundleId ) == overallBundleSet.end() ) { @@ -102,8 +105,9 @@ void BundleCollector::finishBundle( Bundle::Id const & bundleId, BundleInfo cons } else { - if ( overallBundleSet.find ( bundleId ) == overallBundleSet.end() ) + if ( gcDeep && overallBundleSet.find ( bundleId ) == overallBundleSet.end() ) overallBundleSet.insert( bundleId ); + chunkStorageWriter->addBundle( info, savedId ); dPrintf( "Keeping %s bundle\n", i.c_str() ); indexKeptBundles++; diff --git a/backup_collector.hh b/backup_collector.hh index 8144051..d75e277 100644 --- a/backup_collector.hh +++ b/backup_collector.hh @@ -32,7 +32,7 @@ public: ChunkStorage::Reader *chunkStorageReader; ChunkStorage::Writer *chunkStorageWriter; BackupRestorer::ChunkSet usedChunkSet; - bool gcRepack; + bool gcRepack, gcDeep; void startIndex( string const & indexFn ); diff --git a/config.cc b/config.cc index cdeba8c..32ce6f5 100644 --- a/config.cc +++ b/config.cc @@ -124,7 +124,7 @@ void Config::prefillKeywords() }, { - "gc-repack", + "gc.repack", Config::oRuntime_gcRepack, Config::Runtime, "Repack indexes and bundles during garbage collection.\n" diff --git a/zbackup.cc b/zbackup.cc index 59a7eb2..1466317 100644 --- a/zbackup.cc +++ b/zbackup.cc @@ -172,8 +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 [chunks|indexes] - performs garbage\n" -" collection (default is chunks)\n" +" gc [fast|deep] - performs garbage\n" +" collection (default is fast)\n" " passwd - changes repo info file passphrase\n" //" info - shows repo information\n" " config [show|edit|set|reset] - performs\n" @@ -280,16 +280,41 @@ invalid_option: if ( strcmp( args[ 0 ], "gc" ) == 0 ) { // Perform the garbage collection - if ( args.size() != 2 ) + 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( ZBackupBase::deriveStorageDirFromBackupsFile( args[ 1 ], true ), - 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 ], "fast" ) == 0 ) + { + ZCollector zc( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ), + passwords[ 0 ], config ); + zc.gc( false ); + } + else + if ( args.size() > 2 && strcmp( args[ fieldAction ], "deep" ) == 0 ) + { + ZCollector zc( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ), + passwords[ 0 ], config ); + zc.gc( true ); + } + else + { + ZCollector zc( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ), + passwords[ 0 ], config ); + zc.gc( false ); + } } else if ( strcmp( args[ 0 ], "passwd" ) == 0 ) diff --git a/zutils.cc b/zutils.cc index fbffce5..3702998 100644 --- a/zutils.cc +++ b/zutils.cc @@ -307,7 +307,7 @@ ZCollector::ZCollector( string const & storageDir, string const & password, { } -void ZCollector::gc() +void ZCollector::gc( bool gcDeep ) { ChunkIndex chunkReindex( encryptionkey, tmpMgr, getIndexPath(), true ); @@ -321,6 +321,7 @@ void ZCollector::gc() collector.chunkStorageReader = &this->chunkStorageReader; collector.chunkStorageWriter = &chunkStorageWriter; collector.gcRepack = config.runtime.gcRepack; + collector.gcDeep = gcDeep; verbosePrintf( "Performing garbage collection...\n" ); diff --git a/zutils.hh b/zutils.hh index 59d23d4..644db20 100644 --- a/zutils.hh +++ b/zutils.hh @@ -55,7 +55,7 @@ public: ZCollector( std::string const & storageDir, std::string const & password, Config & configIn ); - void gc(); + void gc( bool ); }; #endif