Name files with serial number to make backup

Tags: #<Tag:0x00007f22590aef88>

Hi

I need to make a backup of some files in a folder. The files may have the same name which is why I would like to give them a serial number.
The files are processed in several threads and the backup can therefore be done in random order or simultaneously.

Any Ideas?

Regards Niels

Use a Date Time stamp of [email protected] like [email protected] or insert formatting to make obvious [email protected];30;15. Like your serial number the value keeps increasing, but it is not sequential.

At the start save Today() and Clock() so they all are the same.

I tend to not name the files with the Stamp, instead name a subfolder with the Stamp. So one backup is in one folder.

Since the files have the same name it’s possible to run ROBOCOPY that has multi-threaded copy builtin, plus many other features. It’s fast.

Files with the original names also makes it possible to do a folder compare to see changes. It also allows purging by deleting an entire folder, or zip it to archive.

Below is link to a BAT file I wrote to backup all of a Clarion project to a folder then zip to a file named with a Date-Time stamp. It uses RoboCopy and Zips with PowerShell

I would hash the file contents , because of this Case Sensitivity | Microsoft Docs

Windows is out the box not case sensitive, *Nix derivatives are case sensitive.

I’ve hit that problem before, hashing seems to be best option especially as file attributes like created & modified date times can also be changed by an app, thus making them less reliable.

FYI: GetTempFileName ( prefix, <pathname) and GetTempPath() are documented in ClarionHelp.chm.

I can’t say that I’ve used them…

I have used them in places https://github.com/jslarve/CSVParseClass/blob/f6b2d9bc669dde4130d7b43213aec026471e4a7d/JSCSVParseClass.clw#L1392

Thanks for some great input.
But I don’t really think it solve my challenge completely. Regardless of whether I use folders or rename files with a time stamp, I risk that there are two files who get the same name/folder and then it breaks my data.
Can of course just name with a GUID, but that is not very pretty nor very easy to debug in.
I am considering making a function that creates a blank file (looping adding serial until saving returns true) and return the file handle.
Just hoped that windows or clarion already had such a feature.

You mean like GetTempFileName( MyMeaningfulPrefix )

Not quite. If you have many thousands files, it becomes a little difficult to know what the original file was named.

The meaningfulprefix can contain the original filename, unless you’re concerned about reaching the maximum filename length supported by the file system.

But more to the point:
If you have thousands of files, then I would instead use a folder for each backup set.
Partially because you can create problems with too many files in a folder.
But also because it’s fairly clean to follow what’s going on
And it’s easy to restore the files by just copying an entire backup folder over the active folder.

You could add the hundredths of a second (Time % 100) to make it more unique. There is still the unlikely chance 2 threads get the same Clock() so you could protect for that.

Maybe make a function GetTimeStamp(*Date, *Time) so it’s in one place. Put the code inside a critical section to assure only one thread. Keep Static variables to save the last Date Time. If the new Stamp is the same as last then Yield() Loop and get Date Time again.

Using Today() and Clock() separately has the potential flaw when run near midnight. Date saved at 23:59 but Time being 00:01 of the new day so the Stamp is old by 24 hours. CwUtil has a GetSystemTime function that gets Date and Time in one call. Things like ClarionHoneyComb 24x7 logging should use that.

If you have Nettalk you could use GetElapsedTimeUTC to get the number of milliseconds since 1-1-1970.

Thanks, everybody . I’ve got some ideas to move on. Think it ends up with a combination of several of your suggestions.