2 Star 8 Fork 3

闲散居士/数据库备份

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.pas 4.60 KB
一键复制 编辑 原始数据 按行查看 历史
闲散居士 提交于 2021-12-08 10:58 . 清理源码注释
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, Psock, NMFtp,inifiles;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
NMFTP1:TNMFTP;
TheDate:TDate;
Current_Scheme_Values:Array[0..17] Of String;
procedure GetCurrentScheme(name: String);
procedure DelOldFile;
procedure FTPBackFile;
public
{ Public declarations }
end;
const
iniFileName:String='oraback.ini';
SCHEME_VALUES:Array[0..17] Of String=
('NAME','PARFILE','RUNTIME','RUNDATE','CYCLE','USERNAME','PASSWORD','SERVER','ARCDIR','ISZIP','SAVECYCLE','LEVELAST'
,'FTP_HOST','FTP_USE','FTP_PASS','FTP_PORT','FTP_DMP','FTP_RAR'
);
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
SCH:String;
begin
if ParamCount<2 Then
begin
Application.Terminate;
exit;
end;
TheDate:=StrToDate(ParamStr(1));
SCH:=ParamStr(2);
GetCurrentScheme(SCH);
FTPBackFile;
DelOldFile;
Application.Terminate;
end;
procedure TForm1.FTPBackFile;
var s,SCH,dmpname,rarname:string;
begin
if Current_Scheme_Values[12]='' then exit;
if (Current_Scheme_Values[16]<>'1') or (Current_Scheme_Values[17]<>'1') then exit;
NMFTP1:=TNMFTP.Create(self);
NMFTP1.Host:=Current_Scheme_Values[12];
NMFTP1.UserID:=Current_Scheme_Values[13];
NMFTP1.Password:=Current_Scheme_Values[14];
NMFTP1.Port:=StrToInt(Current_Scheme_Values[15]);
try
NMFTP1.Disconnect;
except end;
try
NMFTP1.connect;
except
exit;
end;
SCH:=Current_Scheme_Values[1];
if SCH='ȱʡ' then
SCH:=''
else
SCH:='_'+SCH;
S:=FormatDateTime('YYYY-MM-DD',TheDate);
dmpname:=Current_Scheme_Values[5]+'\EXP_'+Current_Scheme_Values[5]+'_'+S+SCH+'.dmp';
rarname:=Current_Scheme_Values[8]+'\'+Current_Scheme_Values[5]+'\EXP_'+Current_Scheme_Values[5]+'_'+S+SCH+'.rar';
try
if Current_Scheme_Values[16]='1' then
begin
NMFTP1.Upload(dmpname,dmpname);
end;
if Current_Scheme_Values[17]='1' then
begin
NMFTP1.Upload(rarname,rarname);
end;
finally
NMFTP1.Disconnect;
end;
end;
procedure TForm1.DelOldFile;
var
dmpname,rarname,S,SCH:String;
D1,D2:TDate;
I,DayCount:INTEGER;
HasLeve:boolean;
SaveCycle:Integer;
IsZip,LeveLast:Boolean;
ArcDir,UserName:String;
begin
SaveCycle:=StrToInt(Current_Scheme_Values[4]);
IsZip:=Current_Scheme_Values[9]='1';
ArcDir:=Current_Scheme_Values[8];
UserName:=Current_Scheme_Values[5];
LeveLast:=true;
if ParamCount>=7 then
LeveLast:=ParamStr(7)='1';
case SaveCycle of
1: //ÿ
begin
D1:=StrToDate(FormatDateTime('YYYY-MM',IncMonth(TheDate,-1))+'-01');
D2:=IncMonth(D1,1)-1;
end;
2: //ÿ
begin
D1:=(TheDate-DayOfWeek(TheDate)+2)-7;
D2:=D1+7;
end;
else begin
Application.Terminate;
exit;
end;
end;
DayCount:=round(D2-D1);
HasLeve:=false;
SCH:=Current_Scheme_Values[1];
if SCH='ȱʡ' then
SCH:=''
else
SCH:='_'+SCH;
for I := 0 to DayCount-1 do
begin
S:=FormatDateTime('YYYY-MM-DD',D2-I);
dmpname:=UserName+'\EXP_'+UserName+'_'+S+SCH+'.dmp';
rarname:=ArcDir+'\'+UserName+'\EXP_'+UserName+'_'+S+SCH+'.rar';
if FileExists(dmpname) then
begin
if LeveLast and not HasLeve then
begin
HasLeve:=true;
continue;
end;
DeleteFile(dmpname);
if IsZip and FileExists(rarname) then
DeleteFile(rarname);
end;
end;
end;
procedure TForm1.GetCurrentScheme(name:String);
var ini: TIniFile;
i:Integer;
begin
ini:=TIniFile.Create(iniFileName);
for i := 0 to length(SCHEME_VALUES)-1 do
begin
Current_Scheme_Values[i]:=ini.ReadString(name,SCHEME_VALUES[i],'');
end;
ini.Destroy;
If Current_Scheme_Values[3]='' Then
Current_Scheme_Values[3]:=DateToStr(date);
If Current_Scheme_Values[4]='' Then
Current_Scheme_Values[4]:='0';
If Current_Scheme_Values[2]='' Then
Current_Scheme_Values[2]:='00:00:00';
If Current_Scheme_Values[9]='' Then
Current_Scheme_Values[9]:='1';
If Current_Scheme_Values[10]='' Then
Current_Scheme_Values[10]:='0';
If Current_Scheme_Values[11]='' Then
Current_Scheme_Values[11]:='1';
If Current_Scheme_Values[16]='' Then
Current_Scheme_Values[16]:='1';
If Current_Scheme_Values[17]='' Then
Current_Scheme_Values[17]:='1';
end;
end.
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Delphi
1
https://gitee.com/xyxia/oraback.git
[email protected]:xyxia/oraback.git
xyxia
oraback
数据库备份
master

搜索帮助