Extension To Watch-For or Modify Backup File Name

whitedavidp's Avatar

whitedavidp

15 Feb, 2018 05:53 PM

Hello. I like that MD performs backups upon exit. And I like that I can specify where the backup is to be placed. But I am troubled by the fact that only only backup file name is created per day. I would like basically unlimited files per day. This helps protect me from myself :-(

So I am thinking to create an extension for MD that either somehow is able to change the name used for the backup file to include the current time along with the current date OR to watch for the completion of the backup file being written and then modifying that file's name to include the current time as well as the current date (as is done by default using the export backup command).

I have already cobbled-together an external mechanism to do this. But I would prefer to have something internal rather than the contraption I have now.

Anyhow... I am looking at the extension developer's information and I am looking for things to help me in this endeavor. It appears that the backup file's name is based upon the root account's name and I can get that easily enough. So too with the current date. But the backup file location is stored in a preference somewhere. And I don't see how to get my hands on that via the API. I suppose I could create a user interface and force the user to duplicate this bit of information. But that seems a weakness in that it needs to be kept in sync with the actual preference value.

In poking around, I can see that there is a file called config.dict that on Windows is stored at c:\users\<current user>\.moneydance. No idea where it is stored on other platforms. Is this location available via the API? Is it same to assume that this is always found at System.getProperty("user.home")? Is it "safe" to open/read/parse this file with MD is active?

With the above, I would simply try - when MD is started (or possibly when the dirty state flag is set to not dirty) to have my extension run. When it does, it would:

(a) get the backups location folder
(b) look in the backups location folder for a file with a name matching <root account name>.<current date in YYYY-MM-DD format>.moneydancearchive
(c) if the file is found, rename it with a name matching <root account name>.<current date in YYYY-MM-DD format>-<current time in hhmmss format>.moneydancearchive

Think this would work?

Thanks...

  1. 1 Posted by whitedavidp on 15 Feb, 2018 06:10 PM

    whitedavidp's Avatar

    Hmm. One more thing... At an initial glance, I thought the config.dict fie was in JSON format. But when submitting it to several online JSON verify sites, they are all reporting it is invalid. So what format is this? Thanks

  2. 2 Posted by whitedavidp on 15 Feb, 2018 08:53 PM

    whitedavidp's Avatar

    Maybe the answer to my own question - is the config.dict a StreamTable? And can it be found via LocalStorage? Seems possible. If so, the backup location is retrieved as a String with the key: "backup.location"? Thanks!

  3. 3 Posted by dwg on 15 Feb, 2018 09:22 PM

    dwg's Avatar

    Your extension would have to be constantly running and somehow able to execute after the backup has finish and before Moneydance exits, I doubt if that is possible.

    I suspect you would have a better chance in scripting a solution.

    Basically running Moneydance via a script file rather than calling the executable directly. When you exit Moneydance the script can take over, if you use Moneydance's own backups then copying to another location and renaming them, I would not leave them in the same location as moneydance is set to keep "X" number of backups and with trying to keep multiple daily backups you would be more likely to want to keep "Y" days worth of backups, or you could just dispense with Moneydance's backups and create your own using your favourite zip file program from the command line.

    Naturally your script should also do the housekeeping necessary to purge old backups.

  4. 4 Posted by whitedavidp on 15 Feb, 2018 09:53 PM

    whitedavidp's Avatar

    My issue seems to come if I open/close MD more than once per day. I am doing that alot right now. Otherwise, I am fine with the backup file being named as is now. So
    I was actually thinking my extension should run when MD starts. Since MD performs the backup upon exit, the extension should find any previous moneydancearchive file with the current date and be able to rename it in-place. Then when MD exits again there will be a new file created which does NOT over write the previous one. I have no idea how to get the extension to run upon startup. But I can see that somehow the Quotes extension is getting triggered after startup (or so it appears). Thanks!

    PS - but your idea to run it all via a script is far simpler than what I have cobbled together so far. Not thinking very clearly, I guess.

  5. 5 Posted by dwg on 15 Feb, 2018 10:43 PM

    dwg's Avatar

    I believe the Q & ER extension is open sourced (another user did make a modification to it in recent times) so I think you should be able to grab a copy of it and see how they get it to run on startup, the time stamp you apply however will not represent the creation time of the file, I suppose you could see if you can interrogate the file properties to get the creation date and use that.

    Renaming the file in place could be a problem, I do not know how the keep "X" files algorithm works in Moneydance so renaming files could well break this and result in you having to do some file maintenance.

  6. 6 Posted by whitedavidp on 16 Feb, 2018 01:00 AM

    whitedavidp's Avatar

    Why yes, you are exactly right. I should query the file's time stamp and use that, not the current time. Not sure what I was thinking but it wasn't too clearly. I agree that the file maintenance may become an issue. Right now I have mine set to infinite with the intention of managing it myself. But that could change.

    Right now still having some problems getting some of the API functions to work as anticipated when listing files/folders in the user's home directory. I am starting off slowly and fooling around in Python rather than going whole-hog into Java. That may prove the best way to go eventually. But the learning is somewhat faster without the need to compile, etc.

    Cheers!

  7. 7 Posted by whitedavidp on 19 Feb, 2018 03:01 AM

    whitedavidp's Avatar

    Just FYI, I have written and posted the extension in Java here <http://help.infinitekind.com/discussions/suggestions/11524-improvements-to-backups>.

  8. System closed this discussion on 21 May, 2018 03:10 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

23 Sep, 2018 04:15 AM
23 Sep, 2018 02:47 AM
22 Sep, 2018 11:34 PM
22 Sep, 2018 10:07 PM
22 Sep, 2018 10:04 PM