Exemplo n.º 1
0
wxString frmBackupServer::getCmdPart1()
{
    pgServer *server = (pgServer *)object;

    wxString cmd = backupExecutable;

    if (!server->GetName().IsEmpty())
        cmd += wxT(" --host ") + server->GetName();

    cmd +=  wxT(" --port ") + NumToStr((long)server->GetPort())
            +  wxT(" --username ") + commandLineCleanOption(qtIdent(server->GetUsername()));

    if (!cbRolename->GetValue().IsEmpty())
        cmd += wxT(" --role ") + commandLineCleanOption(qtIdent(cbRolename->GetValue()));

    return cmd;
}
Exemplo n.º 2
0
wxString frmBackup::getCmdPart1()
{
	pgServer *server = object->GetDatabase()->GetServer();

	wxString cmd = backupExecutable;

	if (!server->GetName().IsEmpty())
		cmd += wxT(" --host ") + server->GetName();

	cmd +=  wxT(" --port ") + NumToStr((long)server->GetPort())
	        +  wxT(" --username ") + commandLineCleanOption(qtIdent(server->GetUsername()));

	if (!cbRolename->GetValue().IsEmpty())
		cmd += wxT(" --role ") + commandLineCleanOption(qtIdent(cbRolename->GetValue()));

	if (pgAppMinimumVersion(backupExecutable, 8, 4))
		cmd += wxT(" --no-password ");

	if (object->GetConnection()->GetIsGreenplum())
		cmd += wxT(" --gp-syntax ");
	return cmd;
}
wxString frmRestore::getCmdPart1()
{
    wxString cmd;

    cmd = restoreExecutable;

    if (!server->GetName().IsEmpty())
        cmd += wxT(" --host ") + server->GetName();

    cmd += wxT(" --port ") + NumToStr((long)server->GetPort())
         + wxT(" --username ") + qtIdent(server->GetUsername())
         + wxT(" --dbname ") + commandLineCleanOption(object->GetDatabase()->GetQuotedIdentifier());
    return cmd;
}
Exemplo n.º 4
0
wxString frmBackupGlobals::getCmdPart1()
{
	pgServer *server;
	if (object->GetMetaType() == PGM_SERVER)
		server = (pgServer *)object;
	else
		server = object->GetDatabase()->GetServer();

	wxString cmd = backupExecutable;

	if (!server->GetName().IsEmpty())
		cmd += wxT(" --host ") + server->GetName();

	cmd +=  wxT(" --port ") + NumToStr((long)server->GetPort())
	        +  wxT(" --username ") + commandLineCleanOption(qtIdent(server->GetUsername()));

	if (!cbRolename->GetValue().IsEmpty())
		cmd += wxT(" --role ") + commandLineCleanOption(qtIdent(cbRolename->GetValue()));

	if (pgAppMinimumVersion(backupExecutable, 8, 4))
		cmd += wxT(" --no-password ");

	return cmd;
}
wxString frmRestore::getCmdPart2(int step)
{
    wxString cmd;

    wxString restoreExecutable;
    if (object->GetConnection()->EdbMinimumVersion(8,0))
        restoreExecutable=edbBackupExecutable;
    else if (object->GetConnection()->GetIsGreenplum())
        restoreExecutable=gpBackupExecutable;
    else
        restoreExecutable=pgBackupExecutable;

    if (step)
    {
        cmd.Append(wxT(" --list"));
    }
    else
    {
        if (chkOnlyData->GetValue())
        {
            cmd.Append(wxT(" --data-only"));
        }
        else
        {
            if (chkNoOwner->GetValue())
                cmd.Append(wxT(" --no-owner"));
            if (chkNoPrivileges->GetValue())
                cmd.Append(wxT(" --no-priviledges"));
            if (chkNoTablespaces->GetValue())
                cmd.Append(wxT(" --no-tablespaces"));
        }

        if (chkOnlySchema->GetValue())
        {
            cmd.Append(wxT(" --schema-only"));
        }
        else
        {
            if (chkDisableTrigger->GetValue())
                cmd.Append(wxT(" --disable-triggers"));
        }
        if (chkCreateDb->GetValue())
            cmd.Append(wxT(" --create"));
        if (chkClean->GetValue())
            cmd.Append(wxT(" --clean"));
        if (chkSingleXact->GetValue())
            cmd.Append(wxT(" --single-transaction"));
        if (chkNoDataForFailedTables->GetValue())
            cmd.Append(wxT(" --no-data-for-failed-tables"));
        if (chkUseSetSession->GetValue())
            cmd.Append(wxT(" --use-set-session-authorization"));
        if (chkExitOnError->GetValue())
            cmd.Append(wxT(" --exit-on-error"));

        if (!txtNumberOfJobs->GetValue().IsEmpty())
            cmd.Append(wxT(" --jobs ") + txtNumberOfJobs->GetValue());

        // Process selected items
        wxTreeItemId root, firstLevelObject, secondLevelObject;
        wxTreeItemIdValue firstLevelObjectData, secondLevelObjectData;
        bool partialDump = false;

        // Get root object
        root = ctvObjects->GetRootItem();

        if (root && object->GetMetaType() == PGM_DATABASE)
        {
            // Prepare the array
            wxArrayString restoreStrings;
            restoreStrings.Add(wxEmptyString, numberOfTOCItems);
            restoreTreeItemData *data;

            // Loop through first level objects
            firstLevelObject = ctvObjects->GetFirstChild(root, firstLevelObjectData);
            while (firstLevelObject.IsOk())
            {
                if (ctvObjects->IsChecked(firstLevelObject))
                {
                    // Write the file
                    data = (restoreTreeItemData*)ctvObjects->GetItemData(firstLevelObject);
                    restoreStrings[data->GetId()] = data->GetDesc();

                    // Loop through second level objects
                    secondLevelObject = ctvObjects->GetFirstChild(firstLevelObject, secondLevelObjectData);
                    while (secondLevelObject.IsOk())
                    {
                        if (ctvObjects->IsChecked(secondLevelObject))
                        {
                            // Write the file
                            data = (restoreTreeItemData*)ctvObjects->GetItemData(secondLevelObject);
                            restoreStrings[data->GetId()] = data->GetDesc();
                        }
                        else
                            partialDump = true;
                        secondLevelObject = ctvObjects->GetNextChild(firstLevelObject, secondLevelObjectData);
                    }
                }
                else
                    partialDump = true;
                firstLevelObject = ctvObjects->GetNextChild(root, firstLevelObjectData);
            }

            // Open a temporary file to store the TOC
            restoreTOCFilename = wxFileName::CreateTempFileName(wxT("restore"));
            wxFile tocFile;
            tocFile.Open(restoreTOCFilename.c_str(), wxFile::write);

            // Write all selected items in it
            for (int i=0; i<numberOfTOCItems; i++)
            {
                if (restoreStrings[i] != wxEmptyString)
                {
                    if (!tocFile.Write(restoreStrings[i] + wxT("\n")))
                        wxLogError(_("Error writing to the temporary file ") + restoreTOCFilename);
                }
            }

            // If some items were not checked and if the file still contains something, we have to use the list
            if (partialDump && tocFile.Length() > 0)
                cmd.Append(wxT(" --use-list \"") + restoreTOCFilename + wxT("\""));
            tocFile.Close();
        }
        else if (object->GetMetaType() != PGM_DATABASE)
        {
            switch (object->GetMetaType())
            {
                case PGM_FUNCTION:
                    cmd.Append(wxT(" --function ") + commandLineCleanOption(qtIdent(object->GetFullName())));
                    break;
                case PGM_INDEX:
                    cmd.Append(wxT(" --index ") + commandLineCleanOption(object->GetQuotedIdentifier()));
                    break;
                case PGM_TABLE:
                    cmd.Append(wxT(" --table ") + commandLineCleanOption(object->GetQuotedIdentifier()));
                    break;
                case PGM_TRIGGER:
                    cmd.Append(wxT(" --trigger ") + commandLineCleanOption(object->GetQuotedIdentifier()));
                    break;
                default:
                    break;
            }
            if (object->GetMetaType() == PGM_SCHEMA)
                cmd.Append(wxT(" --schema ") + commandLineCleanOption(object->GetQuotedIdentifier()));
            else if (pgAppMinimumVersion(restoreExecutable, 8, 2))
                cmd.Append(wxT(" --schema ") + commandLineCleanOption(object->GetSchema()->GetQuotedIdentifier()));
        }

        if (settings->GetIgnoreVersion())
            cmd.Append(wxT(" --ignore-version"));
        if (chkVerbose->GetValue())
            cmd.Append(wxT(" --verbose"));
    }


    cmd.Append(wxT(" \"") + txtFilename->GetValue() + wxT("\""));

    return cmd;
}
Exemplo n.º 6
0
wxString frmBackup::getCmdPart2()
{
	wxString cmd;

	switch (cbFormat->GetSelection())
	{
		case 0: // compressed
		{
			cmd.Append(wxT(" --format custom"));
			if (chkBlobs->GetValue())
				cmd.Append(wxT(" --blobs"));
			if (!txtCompressRatio->GetValue().IsEmpty())
				cmd.Append(wxT(" --compress ") + txtCompressRatio->GetValue());
			break;
		}
		case 1: // tar
		{
			cmd.Append(wxT(" --format tar"));
			if (chkBlobs->GetValue())
				cmd.Append(wxT(" --blobs"));
			break;
		}
		case 2: // plain
		{
			cmd.Append(wxT(" --format plain"));
			if (chkOnlyData->GetValue())
			{
				cmd.Append(wxT(" --data-only"));
				if (chkDisableTrigger->GetValue())
					cmd.Append(wxT(" --disable-triggers"));
			}
			else
			{
				if (chkOnlySchema->GetValue())
					cmd.Append(wxT(" --schema-only"));
				if (chkNoOwner->GetValue())
					cmd.Append(wxT(" --no-owner"));
				if (chkCreateDb->GetValue())
					cmd.Append(wxT(" --create"));
				if (chkDropDb->GetValue())
					cmd.Append(wxT(" --clean"));
			}
			break;
		}
		case 3: // directory
		{
			cmd.Append(wxT(" --format directory"));
			break;
		}
	}

	// Section
	if (pgAppMinimumVersion(backupExecutable, 9, 2))
	{
		if (chkSectionPreData->GetValue())
			cmd.Append(wxT(" --section pre-data"));
		if (chkSectionData->GetValue())
			cmd.Append(wxT(" --section data"));
		if (chkSectionPostData->GetValue())
			cmd.Append(wxT(" --section post-data"));
	}

	if (!cbEncoding->GetValue().IsEmpty())
		cmd.Append(wxT(" --encoding ") + cbEncoding->GetValue());
	if (chkOid->GetValue())
		cmd.Append(wxT(" --oids"));
	if (chkInsert->GetValue())
		cmd.Append(wxT(" --inserts"));
	if (chkColumnInserts->GetValue())
		cmd.Append(wxT(" --column-inserts"));
	if (chkNoPrivileges->GetValue())
		cmd.Append(wxT(" --no-privileges"));
	if (chkNoTablespaces->GetValue())
		cmd.Append(wxT(" --no-tablespaces"));
	if (chkUseSetSession->GetValue())
		cmd.Append(wxT(" --use-set-session-authorization"));
	if (chkDisableDollar->GetValue())
		cmd.Append(wxT(" --disable-dollar-quoting"));
	if (settings->GetIgnoreVersion())
		cmd.Append(wxT(" --ignore-version"));
	if (chkVerbose->GetValue())
		cmd.Append(wxT(" --verbose"));
	if (chkForceQuoteForIdent->GetValue())
		cmd.Append(wxT(" --quote-all-identifiers"));
	if (chkNoUnloggedTableData->GetValue())
		cmd.Append(wxT(" --no-unlogged-table-data"));

	cmd.Append(wxT(" --file \"") + txtFilename->GetValue() + wxT("\""));

	if (!txtNumberOfJobs->GetValue().IsEmpty())
		cmd.Append(wxT(" --jobs ") + txtNumberOfJobs->GetValue());

	// Process selected items
	wxTreeItemId root, schema, table;
	wxTreeItemIdValue schemaData, tableData;
	wxString cmdSchemas, cmdTables, tmpTables;
	bool partialDump;
	bool partialSchema;

	root = ctvObjects->GetRootItem();
	schema = ctvObjects->GetFirstChild(root, schemaData);
	cmdSchemas = wxT("");
	cmdTables = wxT("");
	partialDump = false;
	while (schema.IsOk())
	{
		if (ctvObjects->IsChecked(schema))
		{
			partialSchema = false;
			tmpTables = wxT("");
			table = ctvObjects->GetFirstChild(schema, tableData);
			while (table.IsOk())
			{
				if (ctvObjects->IsChecked(table))
				{
					// The syntax changed in 8.2 :-(
					if (pgAppMinimumVersion(backupExecutable, 8, 2))
					{
						tmpTables.Append(wxT(" --table \"") +
						                 commandLineCleanOption(qtIdent(ctvObjects->GetItemText(schema)), true) +
						                 wxT(".") +
						                 commandLineCleanOption(qtIdent(ctvObjects->GetItemText(table)), true) +
						                 wxT("\""));
					}
					else
					{
						tmpTables.Append(wxT(" --table \"") + commandLineCleanOption(qtIdent(ctvObjects->GetItemText(table)), true) + wxT("\""));
						tmpTables.Append(wxT(" --schema \"") + commandLineCleanOption(qtIdent(ctvObjects->GetItemText(schema)), true) + wxT("\""));
					}
				}
				else
				{
					partialDump = true;
					partialSchema = true;
				}
				table = ctvObjects->GetNextChild(schema, tableData);
			}

			if (partialSchema)
			{
				cmdTables += tmpTables;
			}
			else
			{
				cmdSchemas.Append(wxT(" --schema \"") + commandLineCleanOption(qtIdent(ctvObjects->GetItemText(schema)), true) + wxT("\""));
			}
		}
		else
		{
			partialDump = true;
		}

		schema = ctvObjects->GetNextChild(root, schemaData);
	}

	if (partialDump)
	{
		if (!cmdTables.IsEmpty())
			cmd.Append(cmdTables);
		if (!cmdSchemas.IsEmpty())
			cmd.Append(cmdSchemas);
	}

	cmd.Append(wxT(" ") + commandLineCleanOption(object->GetDatabase()->GetQuotedIdentifier()));

	return cmd;
}