Sign in to follow this  
Followers 0
Lee Bussy

Database Log Files

5 posts in this topic

I've been pondering this one a few hours, and there has to be an easier way to do it. Here's what has to be done:

Let's say directory "A" has database log (like binary log) files.

Directory "B" is my backup directory.

I want to copy anything that is in A to B. Pretty easy with:

FileCopy($s_DBFolder & "\*.log", $s_HourlyFolder, 0)

... but then I want to maintain X days of log files past the oldest file in "A" in "B" for emergencies.

I thought about things like creating an array with FileFindNextFile and all sorts of horrible solutions, but there are potentially thousands of files and there has to be a better way.

Any ideas on the best way to attack this?

Share this post


Link to post
Share on other sites



Personally, I like the _FileListToArray() command for getting a list of files from a folder :D

Then all you have to do is compare the FileGetTime() of the last file in A to the files in B and see if it's within your timeframe.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I did not see that function, I'll give it a look, thanks. I was thinking I'd have to write that part, much better to use something existing. :D

Can we be certain that the last file is actually the oldest file?

Edited by Lee Bussy

Share this post


Link to post
Share on other sites

I would read A to an array using the same function, the using the FileGetTime, loop through the array checking to see if the next file is older. Durring each loop, if the file with the older time is assigned to a variable, then by the end of the loop, you should have the oldest file in there.

Something like:

$array = _FileListToArray("C:FolderA", "*", 1);1 to return files only
$oldtime = @YEAR&@MON&@MDAY&@HOUR&@MIN&@SEC
For $i = 1 to Ubound($array)-1
 $aTime = FileGetTime("C:FolderA" & $array[$i], 0, 1);0 is the last modified time, 1 returns the time in YYYYMMDDHHMMSS format
 If $aTime < $oldtime Then
  $oldtime = $aTime
  $oldfile = $array[$i]
 EndIf
Next

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I would read A to an array using the same function, the using the FileGetTime, loop through the array checking to see if the next file is older. Durring each loop, if the file with the older time is assigned to a variable, then by the end of the loop, you should have the oldest file in there.

Aha! The old bubble sort! great call, thanks for kiling my gray matter into firing on all cylinders. :D

Edited by Lee Bussy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0