Home > Back-end >  Who have deleted automatically backup files regularly program
Who have deleted automatically backup files regularly program

Time:10-11

There is a small project, database set up automatic backup every day

Time is long, the disk space is insufficient, must be removed manually

Want to use a program is set to automatically detect disk space, when found insufficient, delete the last backup file

Email address: [email protected]

CodePudding user response:


//delete expired files
* and//AMaskedNames said filename, take? The wildcard
The function DeleteExcessFiles (const ARemainNum: Integer; Const APath: string;
Const AMaskedNames: an array of string) : Integer;
Var
Sr: TSearchRec;
SPath: String;
SlFiles: TStringList;
I: Integer;
The begin
Result:=0;
SPath:=APath;
If (ARemainNum & gt; 0) and (sPath & lt;> ") and DirectoryExists (sPath) then
The begin
SPath:=IncludeTrailingPathDelimiter (sPath);
SlFiles:=TStringList. Create;
Try
SlFiles. Sorted:=true;
If FindFirst (sPath + '*. *, faAnyFile, sr)=0 then
The begin
Repeat
If (sr. Name=') or (sr) Name='.. ') then
continue;
If (sr. Attr and faDirectory) & lt;> FaDirectory then//only file
The begin
For I:=0 to High (AMaskedNames) do
The begin
If Masks. MatchesMask (sr., Name, AMaskedNames [I]) then
The begin
SlFiles. Add (Format (% d='% s', [the sr. Time, sPath + sr., the Name]));
Inc (Result);
Break;
end;
end;
end;
Until FindNext (sr) & lt;> 0;
SysUtils. FindClose (sr);
end;
//delete retains the number of files (in reverse chronological order)
While slFiles. Count & gt; ARemainNum do
The begin
SysUtils. DeleteFile (slFiles ValueFromIndex [0]).
SlFiles. Delete (0);
end;
The finally
SlFiles. Free;
end;
end;
end;

CodePudding user response:

Can write their own a,

CodePudding user response:

Database can be set store backup, how many days over automatically deleted (SQL Server, other don't know)

CodePudding user response:

CodePudding user response:

1, the backup file name, include the date information,
2, regularly check the backup file every day, when the date is more than N, delete,
  • Related