mirror of https://github.com/vitalif/zbackup
Added switch for choosing fast or deep GC
parent
c32ce15e51
commit
0631d70c4b
|
@ -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++;
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
ChunkStorage::Reader *chunkStorageReader;
|
||||
ChunkStorage::Writer *chunkStorageWriter;
|
||||
BackupRestorer::ChunkSet usedChunkSet;
|
||||
bool gcRepack;
|
||||
bool gcRepack, gcDeep;
|
||||
|
||||
void startIndex( string const & indexFn );
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ void Config::prefillKeywords()
|
|||
},
|
||||
|
||||
{
|
||||
"gc-repack",
|
||||
"gc.repack",
|
||||
Config::oRuntime_gcRepack,
|
||||
Config::Runtime,
|
||||
"Repack indexes and bundles during garbage collection.\n"
|
||||
|
|
39
zbackup.cc
39
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] <storage path> - performs garbage\n"
|
||||
" collection (default is chunks)\n"
|
||||
" gc [fast|deep] <storage path> - performs garbage\n"
|
||||
" collection (default is fast)\n"
|
||||
" passwd <storage path> - changes repo info file passphrase\n"
|
||||
//" info <storage path> - shows repo information\n"
|
||||
" config [show|edit|set|reset] <storage path> - 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 <storage path>\n",
|
||||
fprintf( stderr, "Usage: %s %s [chunks|indexes] <storage path>\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 )
|
||||
|
|
|
@ -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" );
|
||||
|
||||
|
|
Loading…
Reference in New Issue