Default compression is stored in StorageInfo

The user can set the default compression method, when she creates the storage. This method
will be used for backup unless the user overrides it with a command-line switch. That way
she can still choose for each backup.

suggested by dragonroot
master
benny 2013-10-08 23:57:27 +02:00
parent abebe7a1ee
commit fb4d814e5c
3 changed files with 22 additions and 1 deletions

View File

@ -87,6 +87,8 @@ void ZBackupBase::initStorage( string const & storageDir,
EncryptionKey::generate( password,
*storageInfo.mutable_encryption_key() );
storageInfo.set_default_compression_method( Compression::defaultCompression );
Paths paths( storageDir );
if ( !Dir::exists( storageDir ) )
@ -127,6 +129,13 @@ string ZBackupBase::deriveStorageDirFromBackupsFile( string const &
return realPath.substr( 0, pos );
}
void ZBackupBase::useDefaultCompressionMethod()
{
std::string compression_method_name = storageInfo.default_compression_method();
const_sptr<Compression> compression = Compression::findCompression( compression_method_name );
Compression::defaultCompression = compression;
}
ZBackup::ZBackup( string const & storageDir, string const & password,
size_t threads ):
ZBackupBase( storageDir, password ),
@ -310,6 +319,7 @@ int main( int argc, char *argv[] )
size_t const defaultCacheSizeMb = 40;
size_t cacheSizeMb = defaultCacheSizeMb;
bool printHelp = false;
bool forcedCompressionMethod = false;
vector< char const * > args;
for( int x = 1; x < argc; ++x )
@ -376,6 +386,7 @@ int main( int argc, char *argv[] )
return EXIT_FAILURE;
}
Compression::defaultCompression = lzo;
forcedCompressionMethod = true;
}
else
if ( strcmp( argv[ x ], "--lzma" ) == 0 )
@ -389,6 +400,7 @@ int main( int argc, char *argv[] )
return EXIT_FAILURE;
}
Compression::defaultCompression = lzma;
forcedCompressionMethod = true;
}
else
if ( strcmp( argv[ x ], "--help" ) == 0 || strcmp( argv[ x ], "-h" ) == 0 )
@ -464,6 +476,8 @@ int main( int argc, char *argv[] )
}
ZBackup zb( ZBackup::deriveStorageDirFromBackupsFile( args[ 1 ] ),
passwordData, threads );
if ( !forcedCompressionMethod )
zb.useDefaultCompressionMethod();
zb.backupFromStdin( args[ 1 ] );
}
else
@ -478,6 +492,8 @@ int main( int argc, char *argv[] )
}
ZRestore zr( ZRestore::deriveStorageDirFromBackupsFile( args[ 1 ] ),
passwordData, cacheSizeMb * 1048576 );
if ( !forcedCompressionMethod )
zr.useDefaultCompressionMethod();
zr.restoreToStdin( args[ 1 ] );
}
else

View File

@ -60,6 +60,8 @@ public:
/// storage dir or throws an exception
static string deriveStorageDirFromBackupsFile( string const & backupsFile );
void useDefaultCompressionMethod();
protected:
StorageInfo storageInfo;
EncryptionKey encryptionkey;

View File

@ -38,6 +38,8 @@ message StorageInfo
required uint32 bundle_max_payload_size = 2;
// If present, used for encryption/decryption of all data
optional EncryptionKeyInfo encryption_key = 3;
// Default encryption for new bundles
optional string default_compression_method = 4 [default = "lzma"];
}
message BundleInfo
@ -68,7 +70,8 @@ message BundleFileHeader
// Compression method that is used for this file
// If the program doesn't support that field, it will try LZMA. If it is
// LZMA, that will work. If it isn't, liblzma will recognize this and abort.
// LZMA, that will work. If it isn't, it will have aborted before because
// the version in FileHeader is higher than it can support.
optional string compression_method = 2 [default = "lzma"];
}