Exemple #1
0
ErrorCode _CCONV FSBase::backupIncremental(const char * path, unsigned * amountChanged)
{
	if (path == nullptr)
		return INVALIDARG;

	StringParser otherParser;
	if (!otherParser.initialize(path))
		otherParser.setServer(path);
	if (otherParser.getServer().empty())
		return INVALIDARG;

	if (!createDir(otherParser.getServer()))
		return FAILEDTOGETWINDIR;
	fstream file;
	string data;
	ErrorCode retVal = getLogFileData(otherParser.getServer(), file, data);
	if (failed(retVal))
		return retVal;
	PathTimeLog log(parser.getServer(), data);
	if (log.isCorrupted())
		return LOG_CORRUPTED;
	unsigned amountBackup = 0;
	retVal = backupAux(parser.getServer(), otherParser.getServer(), &log.getLastBackupTime(), amountBackup);
	if (failed(retVal))
		return retVal;
	replaceRecordInData(parser.getServer(), log.getNowTime(), data);
	retVal = setLogFileData(otherParser.getServer(), file, data);
	if (amountChanged != nullptr)
		*amountChanged = amountBackup;
	return retVal;
}
Exemple #2
0
ErrorCode _CCONV FSBase::backupFull(const char * path, unsigned * amountChanged)
{
	if (path == nullptr)
		return INVALIDARG;
	StringParser otherParser;
	if (!otherParser.initialize(path))
		otherParser.setServer(path);
	if (otherParser.getServer().empty())
		return INVALIDARG;
	if (!createDir(otherParser.getServer()))
		return FAILEDTOGETWINDIR;
	unsigned amountBackup = 0;
	ErrorCode res = backupAux(parser.getServer(), otherParser.getServer(), NULL, amountBackup);
	if (amountChanged != nullptr)
		*amountChanged = amountBackup;
	return res;
}
Exemple #3
0
//storage,db,table, params[bcp ~ storage/table], elapsed_time, comment([local,global],[hierarhy],[amount backuped])
//params for export files ~ amount of exported files
void makeLogRecord(const char * init, const char * params, const unsigned indexStorage, const char method,
	const double time_elapsed, const char * comment)
{
	if (indexStorage > 6) return;
	const char * methodNames[] = { "FSStorage", "SMBStorage", "FTPStorage", "MsSQLStorage",
		"PostgreSQLStorage", "SQLiteStorage", "MongoDB" };
	string rel_path = methodNames[indexStorage];
	if (!createDir(rel_path))
	{
		cout << "Can't create dir";
		return;
	}
	string method_name, method_params;
	switch (tolower(method))
	{
	case 'a':
		method_name = "add";
		method_params = d_makeWithQuotes(string(params));
		break;
	case 'g':
		method_name = "get";
		method_params = d_makeWithQuotes(string(params));
		break;
	case 'e':
		method_name = "export";
		method_params = d_makeWithQuotes(string(comment));
		comment = nullptr;
		break;
	case 'f':
	case 'i':
	{
		method_name = tolower(method) == 'f' ? "backupFull" : "backupIncremental";
		StringParser parser(params);
		method_params = mergeServerDbTable(parser);
		break;
	}
	default:
		cout << "Can't log unknown method";
		return;
	}
	StringParser parser;
	//for FSStorage
	if (!parser.initialize(init))
		parser.setServer(init);
	//1 column: storage/db/table
	string new_record = mergeServerDbTable(parser) + ',';
	//2 column: params
	new_record += method_params + ',';
	//3 column: time
	string s_time(30,'\0');
	sprintf_s(&s_time[0], 30, "%f", time_elapsed);
	s_time.resize(s_time.find('\0'));
	new_record += s_time;
	//4 column[opt]: comment
	if (comment != nullptr && strlen(comment)>0)
	{
		new_record += ',' + string(comment);
	}

	rel_path = makePathFile(rel_path, method_name + ".csv");
	ofstream f(rel_path, ofstream::app | ofstream::out);
	if (!f.is_open())
	{
		cout << "Can't create/open log file" << endl;
		return;
	}
	f.write(new_record.data(), new_record.size());
	f << endl;

}