~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to pgadmin/frm/frmBackupServer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////
2
 
//
3
 
// pgAdmin III - PostgreSQL Tools
4
 
// RCS-ID:      $Id: frmBackupServer.cpp 7243 2008-04-29 09:06:34Z dpage $
5
 
// Copyright (C) 2002 - 2008, The pgAdmin Development Team
6
 
// This software is released under the Artistic Licence
7
 
//
8
 
// frmBackupServer.cpp - Backup server dialogue
9
 
//
10
 
//////////////////////////////////////////////////////////////////////////
11
 
 
12
 
// wxWindows headers
13
 
#include <wx/wx.h>
14
 
#include <wx/settings.h>
15
 
 
16
 
 
17
 
// App headers
18
 
#include "pgAdmin3.h"
19
 
#include "frm/frmMain.h"
20
 
#include "frm/frmBackupServer.h"
21
 
#include "utils/sysLogger.h"
22
 
#include "schema/pgSchema.h"
23
 
#include "schema/pgTable.h"
24
 
 
25
 
// Icons
26
 
#include "images/backup.xpm"
27
 
 
28
 
 
29
 
#define nbNotebook              CTRL_NOTEBOOK("nbNotebook")
30
 
#define txtFilename             CTRL_TEXT("txtFilename")
31
 
#define btnFilename             CTRL_BUTTON("btnFilename")
32
 
#define chkVerbose              CTRL_CHECKBOX("chkVerbose")
33
 
 
34
 
 
35
 
BEGIN_EVENT_TABLE(frmBackupServer, ExternProcessDialog)
36
 
    EVT_TEXT(XRCID("txtFilename"),          frmBackupServer::OnChange)
37
 
    EVT_BUTTON(XRCID("btnFilename"),        frmBackupServer::OnSelectFilename)
38
 
    EVT_BUTTON(wxID_OK,                     frmBackupServer::OnOK)
39
 
    EVT_CLOSE(                              ExternProcessDialog::OnClose)
40
 
END_EVENT_TABLE()
41
 
 
42
 
 
43
 
 
44
 
frmBackupServer::frmBackupServer(frmMain *form, pgObject *obj) : ExternProcessDialog(form)
45
 
{
46
 
    object=obj;
47
 
 
48
 
    wxWindowBase::SetFont(settings->GetSystemFont());
49
 
    LoadResource(form, wxT("frmBackupServer"));
50
 
    RestorePosition();
51
 
 
52
 
    SetTitle(wxString::Format(_("Backup globals %s %s"), object->GetTranslatedTypeName().c_str(), object->GetFullIdentifier().c_str()));
53
 
 
54
 
    wxString val;
55
 
    settings->Read(wxT("frmBackupServer/LastFile"), &val, wxEmptyString);
56
 
    txtFilename->SetValue(val);
57
 
 
58
 
    if (!((pgServer *)object)->GetPasswordIsStored())
59
 
       environment.Add(wxT("PGPASSWORD=") + ((pgServer *)object)->GetPassword());
60
 
 
61
 
    // Icon
62
 
    SetIcon(wxIcon(backup_xpm));
63
 
 
64
 
    txtMessages = CTRL_TEXT("txtMessages");
65
 
    txtMessages->SetMaxLength(0L);
66
 
    btnOK->Disable();
67
 
 
68
 
    wxCommandEvent ev;
69
 
    OnChange(ev);
70
 
}
71
 
 
72
 
 
73
 
frmBackupServer::~frmBackupServer()
74
 
{
75
 
    SavePosition();
76
 
}
77
 
 
78
 
 
79
 
wxString frmBackupServer::GetHelpPage() const
80
 
{
81
 
    wxString page;
82
 
    page = wxT("pg/app-pgdumpall");
83
 
    return page;
84
 
}
85
 
 
86
 
 
87
 
void frmBackupServer::OnSelectFilename(wxCommandEvent &ev)
88
 
{
89
 
    wxString title, prompt, FilenameOnly;
90
 
 
91
 
    title  = _("Select output file");
92
 
    prompt = _("Query files (*.sql)|*.sql|All files (*.*)|*.*");
93
 
    
94
 
    wxFileName::SplitPath(txtFilename->GetValue(), NULL, NULL, &FilenameOnly, NULL);
95
 
    wxFileDialog file(this, title, ::wxPathOnly(txtFilename->GetValue()), FilenameOnly, prompt, wxFD_SAVE);
96
 
    
97
 
    if (file.ShowModal() == wxID_OK)
98
 
    {
99
 
        txtFilename->SetValue(file.GetPath());
100
 
        OnChange(ev);
101
 
    }
102
 
}
103
 
 
104
 
 
105
 
void frmBackupServer::OnChange(wxCommandEvent &ev)
106
 
{
107
 
    if (!process && !done)
108
 
        btnOK->Enable(!txtFilename->GetValue().IsEmpty());
109
 
}
110
 
 
111
 
wxString frmBackupServer::GetCmd(int step)
112
 
{
113
 
    wxString cmd = getCmdPart1();
114
 
 
115
 
    return cmd + getCmdPart2();
116
 
}
117
 
 
118
 
 
119
 
wxString frmBackupServer::GetDisplayCmd(int step)
120
 
{
121
 
    wxString cmd = getCmdPart1();
122
 
 
123
 
    return cmd + getCmdPart2();
124
 
}
125
 
 
126
 
 
127
 
wxString frmBackupServer::getCmdPart1()
128
 
{
129
 
    extern wxString pgBackupAllExecutable;
130
 
    extern wxString edbBackupAllExecutable;
131
 
 
132
 
    pgServer *server = (pgServer *)object;
133
 
 
134
 
    wxString cmd;
135
 
    if (server->GetConnection()->EdbMinimumVersion(8,0))
136
 
        cmd=edbBackupAllExecutable;
137
 
    else
138
 
        cmd=pgBackupAllExecutable;
139
 
 
140
 
    if (!server->GetName().IsEmpty())
141
 
        cmd += wxT(" -h ") + server->GetName();
142
 
 
143
 
    cmd +=  wxT(" -p ") + NumToStr((long)server->GetPort())
144
 
         +  wxT(" -U ") + server->GetUsername();
145
 
    return cmd;
146
 
}
147
 
 
148
 
 
149
 
wxString frmBackupServer::getCmdPart2()
150
 
{
151
 
    wxString cmd;
152
 
    // if (server->GetSSL())
153
 
    // pg_dump doesn't support ssl
154
 
 
155
 
    if (chkVerbose->GetValue())
156
 
        cmd.Append(wxT(" -v"));
157
 
 
158
 
    cmd.Append(wxT(" -f \"") + txtFilename->GetValue() + wxT("\""));
159
 
 
160
 
    return cmd;
161
 
}
162
 
 
163
 
 
164
 
void frmBackupServer::Go()
165
 
{
166
 
    txtFilename->SetFocus();
167
 
    Show(true);
168
 
}
169
 
 
170
 
void frmBackupServer::OnOK(wxCommandEvent &ev)
171
 
{
172
 
    if (!done)
173
 
    {
174
 
        if (processedFile == txtFilename->GetValue())
175
 
        {
176
 
            if (wxMessageBox(_("Are you sure you wish to run a backup to this file again?"), _("Repeat backup?"), wxICON_QUESTION | wxYES_NO) == wxNO)
177
 
                return;
178
 
        }
179
 
 
180
 
        processedFile = txtFilename->GetValue();
181
 
    }
182
 
 
183
 
    settings->Write(wxT("frmBackupServer/LastFile"), txtFilename->GetValue());
184
 
    ExternProcessDialog::OnOK(ev);
185
 
}
186
 
 
187
 
backupServerFactory::backupServerFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) : contextActionFactory(list)
188
 
{
189
 
    mnu->Append(id, _("&Backup server..."), _("Creates a backup of the entire server"));
190
 
}
191
 
 
192
 
 
193
 
wxWindow *backupServerFactory::StartDialog(frmMain *form, pgObject *obj)
194
 
{
195
 
    frmBackupServer *frm=new frmBackupServer(form, obj);
196
 
    frm->Go();
197
 
    return 0;
198
 
}
199
 
 
200
 
 
201
 
bool backupServerFactory::CheckEnable(pgObject *obj)
202
 
{
203
 
    extern wxString pgBackupExecutable;
204
 
    extern wxString edbBackupExecutable;
205
 
 
206
 
    if (!obj)
207
 
        return false;
208
 
 
209
 
    if (!((pgServer *)obj)->GetConnected() || obj->GetMetaType() != PGM_SERVER)
210
 
        return false;
211
 
 
212
 
    if (obj->GetConnection()->EdbMinimumVersion(8, 0))
213
 
        return !edbBackupExecutable.IsEmpty() && pgAppMinimumVersion(edbBackupExecutable, 8, 3);
214
 
    else
215
 
        return !pgBackupExecutable.IsEmpty() && pgAppMinimumVersion(pgBackupExecutable, 8, 3);
216
 
}
 
1
//////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pgAdmin III - PostgreSQL Tools
 
4
// RCS-ID:      $Id: frmBackupServer.cpp 7919 2009-06-11 13:31:15Z dpage $
 
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
 
6
// This software is released under the BSD Licence
 
7
//
 
8
// frmBackupServer.cpp - Backup server dialogue
 
9
//
 
10
//////////////////////////////////////////////////////////////////////////
 
11
 
 
12
// wxWindows headers
 
13
#include <wx/wx.h>
 
14
#include <wx/settings.h>
 
15
 
 
16
 
 
17
// App headers
 
18
#include "pgAdmin3.h"
 
19
#include "frm/frmMain.h"
 
20
#include "frm/frmBackupServer.h"
 
21
#include "utils/sysLogger.h"
 
22
#include "schema/pgSchema.h"
 
23
#include "schema/pgTable.h"
 
24
 
 
25
// Icons
 
26
#include "images/backup.xpm"
 
27
 
 
28
 
 
29
#define nbNotebook              CTRL_NOTEBOOK("nbNotebook")
 
30
#define txtFilename             CTRL_TEXT("txtFilename")
 
31
#define btnFilename             CTRL_BUTTON("btnFilename")
 
32
#define chkVerbose              CTRL_CHECKBOX("chkVerbose")
 
33
 
 
34
 
 
35
BEGIN_EVENT_TABLE(frmBackupServer, ExternProcessDialog)
 
36
    EVT_TEXT(XRCID("txtFilename"),          frmBackupServer::OnChange)
 
37
    EVT_BUTTON(XRCID("btnFilename"),        frmBackupServer::OnSelectFilename)
 
38
    EVT_BUTTON(wxID_OK,                     frmBackupServer::OnOK)
 
39
    EVT_CLOSE(                              ExternProcessDialog::OnClose)
 
40
END_EVENT_TABLE()
 
41
 
 
42
 
 
43
 
 
44
frmBackupServer::frmBackupServer(frmMain *form, pgObject *obj) : ExternProcessDialog(form)
 
45
{
 
46
    object=obj;
 
47
 
 
48
    wxWindowBase::SetFont(settings->GetSystemFont());
 
49
    LoadResource(form, wxT("frmBackupServer"));
 
50
    RestorePosition();
 
51
 
 
52
    SetTitle(wxString::Format(_("Backup globals %s %s"), object->GetTranslatedTypeName().c_str(), object->GetFullIdentifier().c_str()));
 
53
 
 
54
    wxString val;
 
55
    settings->Read(wxT("frmBackupServer/LastFile"), &val, wxEmptyString);
 
56
    txtFilename->SetValue(val);
 
57
 
 
58
    if (!((pgServer *)object)->GetPasswordIsStored())
 
59
       environment.Add(wxT("PGPASSWORD=") + ((pgServer *)object)->GetPassword());
 
60
 
 
61
        // Pass the SSL mode via the environment
 
62
        environment.Add(wxT("PGSSLMODE=") + ((pgServer *)object)->GetConnection()->GetSslModeName());
 
63
 
 
64
        // Icon
 
65
    SetIcon(wxIcon(backup_xpm));
 
66
 
 
67
    txtMessages = CTRL_TEXT("txtMessages");
 
68
    txtMessages->SetMaxLength(0L);
 
69
    btnOK->Disable();
 
70
 
 
71
    wxCommandEvent ev;
 
72
    OnChange(ev);
 
73
}
 
74
 
 
75
 
 
76
frmBackupServer::~frmBackupServer()
 
77
{
 
78
    SavePosition();
 
79
}
 
80
 
 
81
 
 
82
wxString frmBackupServer::GetHelpPage() const
 
83
{
 
84
    wxString page;
 
85
    page = wxT("pg/app-pgdumpall");
 
86
    return page;
 
87
}
 
88
 
 
89
 
 
90
void frmBackupServer::OnSelectFilename(wxCommandEvent &ev)
 
91
{
 
92
    wxString title, prompt, FilenameOnly;
 
93
 
 
94
    title  = _("Select output file");
 
95
    prompt = _("Query files (*.sql)|*.sql|All files (*.*)|*.*");
 
96
    
 
97
    wxFileName::SplitPath(txtFilename->GetValue(), NULL, NULL, &FilenameOnly, NULL);
 
98
    wxFileDialog file(this, title, ::wxPathOnly(txtFilename->GetValue()), FilenameOnly, prompt, wxFD_SAVE);
 
99
    
 
100
    if (file.ShowModal() == wxID_OK)
 
101
    {
 
102
        txtFilename->SetValue(file.GetPath());
 
103
        OnChange(ev);
 
104
    }
 
105
}
 
106
 
 
107
 
 
108
void frmBackupServer::OnChange(wxCommandEvent &ev)
 
109
{
 
110
    if (!process && !done)
 
111
        btnOK->Enable(!txtFilename->GetValue().IsEmpty());
 
112
}
 
113
 
 
114
wxString frmBackupServer::GetCmd(int step)
 
115
{
 
116
    wxString cmd = getCmdPart1();
 
117
 
 
118
    return cmd + getCmdPart2();
 
119
}
 
120
 
 
121
 
 
122
wxString frmBackupServer::GetDisplayCmd(int step)
 
123
{
 
124
    wxString cmd = getCmdPart1();
 
125
 
 
126
    return cmd + getCmdPart2();
 
127
}
 
128
 
 
129
 
 
130
wxString frmBackupServer::getCmdPart1()
 
131
{
 
132
    pgServer *server = (pgServer *)object;
 
133
 
 
134
    wxString cmd;
 
135
    if (server->GetConnection()->EdbMinimumVersion(8,0))
 
136
        cmd=edbBackupAllExecutable;
 
137
    else if (server->GetConnection()->GetIsGreenplum())
 
138
        cmd=gpBackupAllExecutable;
 
139
    else
 
140
        cmd=pgBackupAllExecutable;
 
141
 
 
142
    if (!server->GetName().IsEmpty())
 
143
        cmd += wxT(" --host ") + server->GetName();
 
144
 
 
145
    cmd +=  wxT(" --port ") + NumToStr((long)server->GetPort())
 
146
         +  wxT(" --username ") + server->GetUsername();
 
147
    return cmd;
 
148
}
 
149
 
 
150
 
 
151
wxString frmBackupServer::getCmdPart2()
 
152
{
 
153
    wxString cmd;
 
154
 
 
155
    if (settings->GetIgnoreVersion())
 
156
        cmd.Append(wxT(" --ignore-version"));
 
157
    if (chkVerbose->GetValue())
 
158
        cmd.Append(wxT(" --verbose"));
 
159
 
 
160
    cmd.Append(wxT(" --file \"") + txtFilename->GetValue() + wxT("\""));
 
161
 
 
162
    return cmd;
 
163
}
 
164
 
 
165
 
 
166
void frmBackupServer::Go()
 
167
{
 
168
    txtFilename->SetFocus();
 
169
    Show(true);
 
170
}
 
171
 
 
172
void frmBackupServer::OnOK(wxCommandEvent &ev)
 
173
{
 
174
    if (!done)
 
175
    {
 
176
        if (processedFile == txtFilename->GetValue())
 
177
        {
 
178
            if (wxMessageBox(_("Are you sure you wish to run a backup to this file again?"), _("Repeat backup?"), wxICON_QUESTION | wxYES_NO) == wxNO)
 
179
                return;
 
180
        }
 
181
        else if (wxFile::Exists(txtFilename->GetValue()))
 
182
        {
 
183
            wxString msg;
 
184
            msg.Printf(_("The file: \n\n%s\n\nalready exists. Do you want to overwrite it?"), txtFilename->GetValue().c_str());
 
185
            if (wxMessageBox(msg, _("Overwrite file?"), wxICON_WARNING | wxYES_NO) == wxNO)
 
186
                return;
 
187
        }
 
188
 
 
189
        processedFile = txtFilename->GetValue();
 
190
    }
 
191
 
 
192
    settings->Write(wxT("frmBackupServer/LastFile"), txtFilename->GetValue());
 
193
    ExternProcessDialog::OnOK(ev);
 
194
}
 
195
 
 
196
backupServerFactory::backupServerFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : contextActionFactory(list)
 
197
{
 
198
    mnu->Append(id, _("&Backup server..."), _("Creates a backup of the entire server"));
 
199
}
 
200
 
 
201
 
 
202
wxWindow *backupServerFactory::StartDialog(frmMain *form, pgObject *obj)
 
203
{
 
204
    frmBackupServer *frm=new frmBackupServer(form, obj);
 
205
    frm->Go();
 
206
    return 0;
 
207
}
 
208
 
 
209
 
 
210
bool backupServerFactory::CheckEnable(pgObject *obj)
 
211
{
 
212
    if (!obj)
 
213
        return false;
 
214
 
 
215
    if (!((pgServer *)obj)->GetConnected() || obj->GetMetaType() != PGM_SERVER)
 
216
        return false;
 
217
 
 
218
    if (obj->GetConnection()->EdbMinimumVersion(8, 0))
 
219
        return !edbBackupExecutable.IsEmpty() && pgAppMinimumVersion(edbBackupExecutable, 8, 3);
 
220
    else if (obj->GetConnection()->GetIsGreenplum())
 
221
        return !gpBackupExecutable.IsEmpty() && pgAppMinimumVersion(gpBackupExecutable, 8, 3);
 
222
    else
 
223
        return !pgBackupExecutable.IsEmpty() && pgAppMinimumVersion(pgBackupExecutable, 8, 3);
 
224
}
 
225