-
Notifications
You must be signed in to change notification settings - Fork 0
/
uprincipal.pas
104 lines (88 loc) · 2.15 KB
/
uprincipal.pas
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
unit uprincipal;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, ActnList, process;
type
{ Tfrmprincipal }
{ 040 099 041 032 073 110 102 111 099 111 116 105 100 105 097 110 111 }
Tfrmprincipal = class(TForm)
btnBackup: TButton;
edtMYSQLDUMP: TEdit;
edtSCHEMA: TEdit;
edtUSUARIO: TEdit;
edtSENHA: TEdit;
edtSERVIDOR: TEdit;
edtDESTINO: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Memo1: TMemo;
Panel1: TPanel;
procedure btnBackupClick(Sender: TObject);
private
{ private declarations }
procedure backupMySQL;
public
{ public declarations }
end;
var
frmprincipal: Tfrmprincipal;
implementation
{$R *.lfm}
{ Tfrmprincipal }
procedure Tfrmprincipal.btnBackupClick(Sender: TObject);
begin
backupMySQL;
end;
procedure Tfrmprincipal.backupMySQL;
const READ_BYTES = 2048;
var
command : TProcess;
cARQBKP: String;
output : tstringlist;
BytesRead, n : LongInt;
m: TMemoryStream;
begin
cARQBKP:= edtDESTINO.Text;
command := TProcess.Create(nil);
output := TStringList.Create;
m := TMemoryStream.Create;
BytesRead:=0;
command.CommandLine:=edtMYSQLDUMP.Text+' -u'+edtUSUARIO.Text+' -p'+edtSENHA.Text+' -h'+edtSERVIDOR.Text+' '+edtSCHEMA.text;
command.Options:=command.Options+[poUsePipes];
Memo1.Clear;
Memo1.Lines.Add('Backup Iniciado');
command.ShowWindow:=swoHIDE;
command.Execute;
while command.Running do
begin
m.SetSize(BytesRead+READ_BYTES);
n:= command.Output.Read((m.Memory+BytesRead)^, READ_BYTES);
if n> 0 then
inc(BytesRead,n)
else
Sleep(100);
end;
repeat
m.SetSize(BytesRead+READ_BYTES);
n := command.Output.Read((m.Memory+BytesRead)^, READ_BYTES);
if n> 0 then
inc(BytesRead,n)
else
Sleep(100);
until n <= 0;
m.SetSize(BytesRead);
output.LoadFromStream(m);
Memo1.Lines.AddStrings(output);
output.SaveToFile(cARQBKP);
output.Free;
command.free;
m.Free;
Memo1.Lines.Add('Comando concluido !');
end;
end.