Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "backup.h"
00023 #include "tarfile.h"
00024 #include "error.h"
00025 #include <sstream>
00026 #include <iomanip>
00027 #include <iostream>
00028
00029 namespace Barry {
00030
00031 Backup::Backup(const std::string &tarpath)
00032 {
00033 try {
00034 m_tar.reset( new reuse::TarFile(tarpath.c_str(), true,
00035 &reuse::gztar_ops_nonthread, true) );
00036 }
00037 catch( reuse::TarFile::TarError &te ) {
00038 throw Barry::BackupError(te.what());
00039 }
00040 }
00041
00042 Backup::~Backup()
00043 {
00044 try {
00045 Close();
00046 }
00047 catch( Barry::BackupError & ) {
00048
00049 }
00050 }
00051
00052 void Backup::Close()
00053 {
00054 if( m_tar.get() ) try {
00055 m_tar->Close();
00056 m_tar.reset();
00057 }
00058 catch( reuse::TarFile::TarError &te ) {
00059 throw Barry::BackupError(te.what());
00060 }
00061 }
00062
00063
00064
00065
00066
00067 void Backup::ParseRecord(const Barry::DBData &data,
00068 const Barry::IConverter *ic)
00069 {
00070 m_current_dbname = data.GetDBName();
00071
00072 std::ostringstream oss;
00073 oss << std::hex << data.GetUniqueId()
00074 << " " << (unsigned int)data.GetRecType();
00075 m_tar_id_text = oss.str();
00076
00077 if( m_current_dbname.size() == 0 )
00078 throw Barry::BackupError("Backup: No database name available");
00079 if( m_tar_id_text.size() == 0 )
00080 throw Barry::BackupError("Backup: No unique ID available!");
00081
00082 m_record_data.assign(
00083 (const char*)data.GetData().GetData() + data.GetOffset(),
00084 data.GetData().GetSize() - data.GetOffset());
00085
00086
00087 std::string tarname = m_current_dbname + "/" + m_tar_id_text;
00088 m_tar->AppendFile(tarname.c_str(), m_record_data);
00089 }
00090
00091 }
00092