Skip to content

Commit

Permalink
Implemented feature #55
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad1mir-D committed Sep 22, 2015
1 parent b8d1611 commit a9029fe
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 7 deletions.
5 changes: 5 additions & 0 deletions chunk_index.cc
Expand Up @@ -78,6 +78,11 @@ void ChunkIndex::loadIndex( IndexProcessor & ip )
verbosePrintf( "Index loaded.\n" );
}

size_t ChunkIndex::size()
{
return hashTable.size();
}

void ChunkIndex::startIndex( string const & )
{
}
Expand Down
2 changes: 2 additions & 0 deletions chunk_index.hh
Expand Up @@ -118,6 +118,8 @@ public:

void loadIndex( IndexProcessor & );

size_t size();

private:
/// Inserts new chunk id into the in-memory hash table. Returns the created
/// Chain if it was inserted, NULL if it existed before
Expand Down
29 changes: 23 additions & 6 deletions zbackup.cc
Expand Up @@ -179,7 +179,8 @@ int main( int argc, char *argv[] )
" performs import from source to destination storage,\n"
" for export/import storage path must point to\n"
" a valid (initialized) storage\n"
" inspect <backup file name> - inspect backup\n"
" inspect [fast|deep] <backup file name> - inspect backup (default\n"
" is fast)\n"
" gc [fast|deep] <storage path> - performs garbage\n"
" collection (default is fast)\n"
" passwd <storage path> - changes repo info file passphrase\n"
Expand Down Expand Up @@ -376,16 +377,32 @@ int main( int argc, char *argv[] )
else
if ( strcmp( args[ 0 ], "inspect" ) == 0 )
{
if ( args.size() != 2 )
if ( args.size() < 2 || args.size() > 3 )
{
fprintf( stderr, "Usage: %s %s <storage path>\n",
fprintf( stderr, "Usage: %s %s [full] <storage path>\n",
*argv, args[ 0 ] );
return EXIT_FAILURE;
}

ZInspect zi( ZRestore::deriveStorageDirFromBackupsFile( args[ 1 ] ),
passwords[ 0 ], config );
zi.inspect( args[1] );
int fieldStorage = 1, fieldAction = 2;

if ( args.size() == 3 )
{
fieldStorage = 2, fieldAction = 1;
}

if ( args.size() > 2 && strcmp( args[ fieldAction ], "deep" ) == 0 )
{
ZInspect zi( ZRestore::deriveStorageDirFromBackupsFile( args[ fieldStorage ] ),
passwords[ 0 ], config, true );
zi.inspect( args[ fieldStorage ] );
}
else
{
ZInspect zi( ZRestore::deriveStorageDirFromBackupsFile( args[ fieldStorage ] ),
passwords[ 0 ], config, false );
zi.inspect( args[ fieldStorage ] );
}
}
else
if ( strcmp( args[ 0 ], "config" ) == 0 )
Expand Down
28 changes: 27 additions & 1 deletion zutils.cc
Expand Up @@ -477,6 +477,12 @@ ZInspect::ZInspect( string const & storageDir, string const & password,
{
}

ZInspect::ZInspect( string const & storageDir, string const & password,
Config & configIn, bool deep ):
ZBackupBase( storageDir, password, configIn, !deep )
{
}

void ZInspect::inspect( string const & inputFileName )
{
BackupInfo backupInfo;
Expand All @@ -499,5 +505,25 @@ void ZInspect::inspect( string const & inputFileName )
out += "\nSHA256 sum of data: ";
out += Utils::toHex( backupInfo.sha256() );

fprintf( stderr, "%s\n", out.c_str() );
// Index is loaded so mode is "deep", let's get chunk map
if ( chunkIndex.size() )
{
out += "\nBundles containing backup chunks:\n";
ChunkStorage::Reader chunkStorageReader( config, encryptionkey, chunkIndex, getBundlesPath(),
config.runtime.cacheSize );
string backupData;
BackupRestorer::restoreIterations( chunkStorageReader, backupInfo, backupData, NULL );
BackupRestorer::ChunkMap map;
BackupRestorer::restore( chunkStorageReader, backupData, NULL, NULL, &map, NULL );

for ( BackupRestorer::ChunkMap::const_iterator it = map.begin(); it != map.end(); it++ )
{
out += Utils::toHex( string( (*it).first.blob, Bundle::IdSize ) );
out += "\n";
}
}
else
out += "\n";

fprintf( stderr, "%s", out.c_str() );
}
2 changes: 2 additions & 0 deletions zutils.hh
Expand Up @@ -79,6 +79,8 @@ class ZInspect : public ZBackupBase
public:
ZInspect( std::string const & storageDir, std::string const & password,
Config & configIn );
ZInspect( std::string const & storageDir, std::string const & password,
Config & configIn, bool deep );

void inspect( string const & inputFileName );
};
Expand Down

0 comments on commit a9029fe

Please sign in to comment.