1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// frmBackupServer.cpp - Backup server dialogue
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
#include <wx/settings.h>
// App headers
#include "pgAdmin3.h"
#include "frm/frmMain.h"
#include "frm/frmBackupServer.h"
#include "utils/sysLogger.h"
#include "schema/pgSchema.h"
#include "schema/pgTable.h"
// Icons
#include "images/backup.pngc"
#define nbNotebook CTRL_NOTEBOOK("nbNotebook")
#define txtFilename CTRL_TEXT("txtFilename")
#define btnFilename CTRL_BUTTON("btnFilename")
#define cbRolename CTRL_COMBOBOX("cbRolename")
#define chkVerbose CTRL_CHECKBOX("chkVerbose")
#define chkForceQuoteForIdent CTRL_CHECKBOX("chkForceQuoteForIdent")
BEGIN_EVENT_TABLE(frmBackupServer, ExternProcessDialog)
EVT_TEXT(XRCID("txtFilename"), frmBackupServer::OnChange)
EVT_BUTTON(XRCID("btnFilename"), frmBackupServer::OnSelectFilename)
EVT_BUTTON(wxID_OK, frmBackupServer::OnOK)
EVT_CLOSE( ExternProcessDialog::OnClose)
END_EVENT_TABLE()
frmBackupServer::frmBackupServer(frmMain *form, pgObject *obj) : ExternProcessDialog(form)
{
object = obj;
SetFont(settings->GetSystemFont());
LoadResource(form, wxT("frmBackupServer"));
RestorePosition();
SetTitle(object->GetTranslatedMessage(BACKUPSERVERTITLE));
pgServer *server = (pgServer *)object;
if (server->GetConnection()->EdbMinimumVersion(8, 0))
backupExecutable = edbBackupAllExecutable;
else if (server->GetConnection()->GetIsGreenplum())
backupExecutable = gpBackupAllExecutable;
else
backupExecutable = pgBackupAllExecutable;
wxString val;
settings->Read(wxT("frmBackupServer/LastFile"), &val, wxEmptyString);
txtFilename->SetValue(val);
bool roles_supported = pgAppMinimumVersion(backupExecutable, 8, 4) && server->GetConnection()->BackendMinimumVersion(8, 1);
cbRolename->Enable(roles_supported);
if (roles_supported)
{
// Collect the available rolenames
pgSetIterator set(server->GetConnection(),
wxT("SELECT DISTINCT rolname\n")
wxT("FROM pg_roles db\n")
wxT("ORDER BY rolname"));
cbRolename->Append(wxEmptyString);
while(set.RowsLeft())
cbRolename->Append(set.GetVal(wxT("rolname")));
cbRolename->SetValue(server->GetRolename());
}
if (!server->GetPasswordIsStored())
environment.Add(wxT("PGPASSWORD=") + server->GetPassword());
// Pass the SSL mode via the environment
environment.Add(wxT("PGSSLMODE=") + server->GetConnection()->GetSslModeName());
// Icon
SetIcon(*backup_png_ico);
txtMessages = CTRL_TEXT("txtMessages");
// Note that under GTK+, SetMaxLength() function may only be used with single line text controls.
// (see http://docs.wxwidgets.org/2.8/wx_wxtextctrl.html#wxtextctrlsetmaxlength)
#ifndef __WXGTK__
txtMessages->SetMaxLength(0L);
#endif
btnOK->Disable();
if (!pgAppMinimumVersion(backupExecutable, 9, 1))
{
chkForceQuoteForIdent->Disable();
}
wxCommandEvent ev;
OnChange(ev);
}
frmBackupServer::~frmBackupServer()
{
SavePosition();
}
wxString frmBackupServer::GetHelpPage() const
{
wxString page;
page = wxT("pg/app-pg-dumpall");
return page;
}
void frmBackupServer::OnSelectFilename(wxCommandEvent &ev)
{
wxString title, prompt, FilenameOnly;
title = _("Select output file");
#ifdef __WXMSW__
prompt = _("Query files (*.sql)|*.sql|All files (*.*)|*.*");
#else
prompt = _("Query files (*.sql)|*.sql|All files (*)|*");
#endif
wxFileName::SplitPath(txtFilename->GetValue(), NULL, NULL, &FilenameOnly, NULL);
wxFileDialog file(this, title, ::wxPathOnly(txtFilename->GetValue()), FilenameOnly, prompt, wxFD_SAVE);
if (file.ShowModal() == wxID_OK)
{
txtFilename->SetValue(file.GetPath());
OnChange(ev);
}
}
void frmBackupServer::OnChange(wxCommandEvent &ev)
{
if (!process && !done)
btnOK->Enable(!txtFilename->GetValue().IsEmpty());
}
wxString frmBackupServer::GetCmd(int step)
{
wxString cmd = getCmdPart1();
return cmd + getCmdPart2();
}
wxString frmBackupServer::GetDisplayCmd(int step)
{
wxString cmd = getCmdPart1();
return cmd + getCmdPart2();
}
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()));
if (pgAppMinimumVersion(backupExecutable, 8, 4))
cmd += wxT(" --no-password ");
return cmd;
}
wxString frmBackupServer::getCmdPart2()
{
wxString cmd;
if (settings->GetIgnoreVersion())
cmd.Append(wxT(" --ignore-version"));
if (chkVerbose->GetValue())
cmd.Append(wxT(" --verbose"));
if (chkForceQuoteForIdent->GetValue())
cmd.Append(wxT(" --quote-all-identifiers"));
cmd.Append(wxT(" --file \"") + txtFilename->GetValue() + wxT("\""));
return cmd;
}
void frmBackupServer::Go()
{
txtFilename->SetFocus();
Show(true);
}
void frmBackupServer::OnOK(wxCommandEvent &ev)
{
if (!done)
{
if (processedFile == txtFilename->GetValue())
{
if (wxMessageBox(_("Are you sure you wish to run a backup to this file again?"), _("Repeat backup?"), wxICON_QUESTION | wxYES_NO) != wxYES)
return;
}
else if (wxFile::Exists(txtFilename->GetValue()))
{
wxString msg;
msg.Printf(_("The file: \n\n%s\n\nalready exists. Do you want to overwrite it?"), txtFilename->GetValue().c_str());
if (wxMessageBox(msg, _("Overwrite file?"), wxICON_WARNING | wxYES_NO) != wxYES)
return;
}
processedFile = txtFilename->GetValue();
}
settings->Write(wxT("frmBackupServer/LastFile"), txtFilename->GetValue());
ExternProcessDialog::OnOK(ev);
}
backupServerFactory::backupServerFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : contextActionFactory(list)
{
mnu->Append(id, _("&Backup server..."), _("Creates a backup of the entire server"));
}
wxWindow *backupServerFactory::StartDialog(frmMain *form, pgObject *obj)
{
frmBackupServer *frm = new frmBackupServer(form, obj);
frm->Go();
return 0;
}
bool backupServerFactory::CheckEnable(pgObject *obj)
{
if (!obj)
return false;
if (!((pgServer *)obj)->GetConnected() || obj->GetMetaType() != PGM_SERVER)
return false;
if (obj->GetConnection()->EdbMinimumVersion(8, 0))
return !edbBackupAllExecutable.IsEmpty() && pgAppMinimumVersion(edbBackupAllExecutable, 8, 3);
else if (obj->GetConnection()->GetIsGreenplum())
return !gpBackupAllExecutable.IsEmpty() && pgAppMinimumVersion(gpBackupAllExecutable, 8, 3);
else
return !pgBackupAllExecutable.IsEmpty() && pgAppMinimumVersion(pgBackupAllExecutable, 8, 3);
}
|