mirror of https://github.com/vitalif/zbackup
Slight refactoring, boilerplates for config
parent
84caffd375
commit
6276815579
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org> and ZBackup contributors, see CONTRIBUTORS
|
||||
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
|
||||
|
||||
#include "config.hh"
|
||||
#include "debug.hh"
|
||||
|
||||
ZConfig::ZConfig( string const & storageDir, string const & password ):
|
||||
ZBackupBase( storageDir, password, true )
|
||||
{
|
||||
}
|
||||
|
||||
string ZConfig::toString( google::protobuf::Message const & message )
|
||||
{
|
||||
std::string str;
|
||||
google::protobuf::TextFormat::PrintToString( message, &str );
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void ZConfig::print()
|
||||
{
|
||||
printf( "%s", toString( extendedStorageInfo.config() ).c_str() );
|
||||
}
|
||||
|
||||
bool ZConfig::parse( const string & str, google::protobuf::Message * mutable_message )
|
||||
{
|
||||
return google::protobuf::TextFormat::ParseFromString( str, mutable_message );
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org> and ZBackup contributors, see CONTRIBUTORS
|
||||
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
|
||||
|
||||
#ifndef CONFIG_HH_INCLUDED__
|
||||
#define CONFIG_HH_INCLUDED__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <google/protobuf/text_format.h>
|
||||
|
||||
#include "zbackup_base.hh"
|
||||
#include "zbackup.pb.h"
|
||||
#include "sptr.hh"
|
||||
|
||||
using std::string;
|
||||
|
||||
class ZConfig: public ZBackupBase
|
||||
{
|
||||
public:
|
||||
ZConfig( string const & storageDir, string const & password );
|
||||
|
||||
// Print current configuration to screen
|
||||
void print();
|
||||
|
||||
private:
|
||||
string toString( google::protobuf::Message const & message );
|
||||
bool parse( const string & str, google::protobuf::Message * mutable_message );
|
||||
};
|
||||
|
||||
#endif
|
51
zbackup.cc
51
zbackup.cc
|
@ -28,6 +28,7 @@
|
|||
#include "index_file.hh"
|
||||
#include "bundle.hh"
|
||||
#include "backup_collector.hh"
|
||||
#include "config.hh"
|
||||
|
||||
using std::vector;
|
||||
using std::bitset;
|
||||
|
@ -180,10 +181,9 @@ void ZRestore::restoreToStdin( string const & inputFileName )
|
|||
}
|
||||
|
||||
ZExchange::ZExchange( string const & srcStorageDir, string const & srcPassword,
|
||||
string const & dstStorageDir, string const & dstPassword,
|
||||
bool prohibitChunkIndexLoading ):
|
||||
srcZBackupBase( srcStorageDir, srcPassword, prohibitChunkIndexLoading ),
|
||||
dstZBackupBase( dstStorageDir, dstPassword, prohibitChunkIndexLoading )
|
||||
string const & dstStorageDir, string const & dstPassword ):
|
||||
srcZBackupBase( srcStorageDir, srcPassword, true ),
|
||||
dstZBackupBase( dstStorageDir, dstPassword, true )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -512,7 +512,8 @@ int main( int argc, char *argv[] )
|
|||
" performs import from source to destination storage;\n"
|
||||
" gc <storage path> - performs chunk garbage collection;\n"
|
||||
" passwd <storage path> - changes repository info file passphrase;\n"
|
||||
" info <storage path> - shows information about storage.\n"
|
||||
" info <storage path> - shows information about storage;\n"
|
||||
" config <storage path> - performs configuration manipulations.\n"
|
||||
" For export/import storage path must be valid (initialized) storage.\n"
|
||||
"", *argv,
|
||||
defaultThreads, defaultCacheSizeMb );
|
||||
|
@ -541,7 +542,7 @@ int main( int argc, char *argv[] )
|
|||
// Perform the init
|
||||
if ( args.size() != 2 )
|
||||
{
|
||||
fprintf( stderr, "Usage: %s init <storage path>\n", *argv );
|
||||
fprintf( stderr, "Usage: %s %s <storage path>\n", *argv, args[ 0 ] );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -553,8 +554,8 @@ int main( int argc, char *argv[] )
|
|||
// Perform the backup
|
||||
if ( args.size() != 2 )
|
||||
{
|
||||
fprintf( stderr, "Usage: %s backup <backup file name>\n",
|
||||
*argv );
|
||||
fprintf( stderr, "Usage: %s %s <backup file name>\n",
|
||||
*argv, args[ 0 ] );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
ZBackup zb( ZBackup::deriveStorageDirFromBackupsFile( args[ 1 ] ),
|
||||
|
@ -569,8 +570,8 @@ int main( int argc, char *argv[] )
|
|||
// Perform the restore
|
||||
if ( args.size() != 2 )
|
||||
{
|
||||
fprintf( stderr, "Usage: %s restore <backup file name>\n",
|
||||
*argv );
|
||||
fprintf( stderr, "Usage: %s %s <backup file name>\n",
|
||||
*argv , args[ 0 ] );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
ZRestore zr( ZRestore::deriveStorageDirFromBackupsFile( args[ 1 ] ),
|
||||
|
@ -612,8 +613,7 @@ int main( int argc, char *argv[] )
|
|||
ZExchange ze( ZBackupBase::deriveStorageDirFromBackupsFile( args[ src ], true ),
|
||||
passwords[ src - 1 ],
|
||||
ZBackupBase::deriveStorageDirFromBackupsFile( args[ dst ], true ),
|
||||
passwords[ dst - 1 ],
|
||||
true );
|
||||
passwords[ dst - 1 ] );
|
||||
ze.exchange( args[ src ], args[ dst ], exchange );
|
||||
}
|
||||
else
|
||||
|
@ -622,8 +622,8 @@ int main( int argc, char *argv[] )
|
|||
// Perform the restore
|
||||
if ( args.size() != 2 )
|
||||
{
|
||||
fprintf( stderr, "Usage: %s gc <storage path>\n",
|
||||
*argv );
|
||||
fprintf( stderr, "Usage: %s %s <storage path>\n",
|
||||
*argv, args[ 0 ] );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
ZCollector zr( args[ 1 ], passwords[ 0 ], threads, cacheSizeMb * 1048576 );
|
||||
|
@ -635,8 +635,8 @@ int main( int argc, char *argv[] )
|
|||
// Perform the password change
|
||||
if ( args.size() != 2 )
|
||||
{
|
||||
fprintf( stderr, "Usage: %s passwd <storage path>\n",
|
||||
*argv );
|
||||
fprintf( stderr, "Usage: %s %s <storage path>\n",
|
||||
*argv, args[ 0 ] );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -659,8 +659,8 @@ int main( int argc, char *argv[] )
|
|||
// Show repo info
|
||||
if ( args.size() != 2 )
|
||||
{
|
||||
fprintf( stderr, "Usage: %s info <storage path>\n",
|
||||
*argv );
|
||||
fprintf( stderr, "Usage: %s %s <storage path>\n",
|
||||
*argv, args[ 0 ] );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -668,6 +668,21 @@ int main( int argc, char *argv[] )
|
|||
passwords[ 0 ] );
|
||||
}
|
||||
else
|
||||
if ( strcmp( args[ 0 ], "config" ) == 0 )
|
||||
{
|
||||
// Show repo info
|
||||
if ( args.size() != 2 )
|
||||
{
|
||||
fprintf( stderr, "Usage: %s %s <storage path>\n",
|
||||
*argv, args[ 0 ] );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ZConfig zc( ZBackupBase::deriveStorageDirFromBackupsFile( args[ 1 ], true ),
|
||||
passwords[ 0 ] );
|
||||
zc.print();
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf( stderr, "Error: unknown command line option: %s\n", args[ 0 ] );
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -67,8 +67,7 @@ class ZExchange
|
|||
|
||||
public:
|
||||
ZExchange( string const & srcStorageDir, string const & srcPassword,
|
||||
string const & dstStorageDir, string const & dstPassword,
|
||||
bool prohibitChunkIndexLoading );
|
||||
string const & dstStorageDir, string const & dstPassword );
|
||||
|
||||
/// Exchanges the data between storages
|
||||
void exchange( string const & srcFileName, string const & dstFileName,
|
||||
|
|
|
@ -42,18 +42,29 @@ message StorageInfo
|
|||
optional string default_compression_method = 4 [default = "lzma", deprecated = true];
|
||||
}
|
||||
|
||||
message ConfigInfo
|
||||
message ChunkConfigInfo
|
||||
{
|
||||
// Maximum chunk size used when storing chunks
|
||||
required uint32 max_size = 1 [default = 65536];
|
||||
}
|
||||
|
||||
message BundleConfigInfo
|
||||
{
|
||||
required uint32 chunk_max_size = 1 [default = 65536];
|
||||
// Maximum number of bytes a bundle can hold. Only real chunk bytes are
|
||||
// counted, not metadata. Any bundle should be able to contain at least
|
||||
// one arbitrary single chunk, so this should not be smaller than
|
||||
// chunk_max_size
|
||||
required uint32 bundle_max_payload_size = 2 [default = 0x200000];
|
||||
required uint32 max_payload_size = 2 [default = 0x200000];
|
||||
// Default compression for new bundles
|
||||
optional string default_compression_method = 3 [default = "lzma"];
|
||||
}
|
||||
|
||||
message ConfigInfo
|
||||
{
|
||||
required ChunkConfigInfo chunk = 1;
|
||||
required BundleConfigInfo bundle = 2;
|
||||
}
|
||||
|
||||
message ExtendedStorageInfo
|
||||
{
|
||||
// Config data storage
|
||||
|
|
|
@ -91,13 +91,18 @@ void ZBackupBase::initStorage( string const & storageDir,
|
|||
StorageInfo storageInfo;
|
||||
ExtendedStorageInfo extendedStorageInfo;
|
||||
|
||||
// TODO: make the following configurable
|
||||
// TODO: Make a proper setup of initial values
|
||||
storageInfo.set_chunk_max_size( 65536 );
|
||||
storageInfo.set_bundle_max_payload_size( 0x200000 );
|
||||
extendedStorageInfo.mutable_config()->set_chunk_max_size(
|
||||
extendedStorageInfo.config().chunk_max_size() );
|
||||
extendedStorageInfo.mutable_config()->set_bundle_max_payload_size(
|
||||
extendedStorageInfo.config().bundle_max_payload_size() );
|
||||
storageInfo.set_default_compression_method(
|
||||
Compression::CompressionMethod::defaultCompression->getName() );
|
||||
|
||||
extendedStorageInfo.mutable_config()->mutable_chunk()->set_max_size(
|
||||
extendedStorageInfo.config().chunk().max_size() );
|
||||
extendedStorageInfo.mutable_config()->mutable_bundle()->set_max_payload_size(
|
||||
extendedStorageInfo.config().bundle().max_payload_size() );
|
||||
extendedStorageInfo.mutable_config()->mutable_bundle()->set_default_compression_method(
|
||||
extendedStorageInfo.config().bundle().default_compression_method() );
|
||||
|
||||
EncryptionKey encryptionkey = EncryptionKey::noKey();
|
||||
|
||||
|
@ -106,9 +111,6 @@ void ZBackupBase::initStorage( string const & storageDir,
|
|||
*storageInfo.mutable_encryption_key(),
|
||||
encryptionkey );
|
||||
|
||||
storageInfo.set_default_compression_method(
|
||||
Compression::CompressionMethod::defaultCompression->getName() );
|
||||
|
||||
Paths paths( storageDir );
|
||||
|
||||
if ( !Dir::exists( storageDir ) )
|
||||
|
|
Loading…
Reference in New Issue