Suggeston for Location of Backup Files

LO makes it backup files in one directory. It would be nice if it would make backup files in the directory in which the original file is located.

Is this possible?

Or better I think would be relative to the location of the current file, like in distributed ./Backups/ folders, e.g. ~/project1/Backups/, ~/project2/Backups/ … btw the appropriate place for suggestions is not here, but rather in a bug report (as an improvement suggestion). So if you’re already working on that please add the link here to the submitted bug report, as I would like to chime in there too. Thanks.

===== Start Edit =====
See the much more attentive and well researched answer by @Ratslinger.
(I have to take this for another reason to consider what value is in trying to contribute to this breathlessly running ticker without any reasonable structure.)
===== End Edit =====

Since the topic should only apply to the specific system (imo) and not to distributed documents, there is no strong reason to avoid relying on user code (“macros”) in this case. To make a routine (‘Sub’) for saving copies of a document or to move/rename already existing copies (in BASIC e.g.) is rather simple. The Sub must then be assigned to an appropriate document event (or a series of Subs to a series of such events). ‘Tools’ > ‘Customize…’ > ‘Events’ is listing the available events.

If you accept the task, and specifically if you include an option to create a (LIFO) stack of backups to a certain depth, please publish your code. I would be interested. A good idea might, however, be to create a folder ‘LibObackups’ in each folder containing LibO documents. The stack functionality can be achieved then by changing a numeric appendix to the filename. (Simplest: Highest number = youngest backup.)

@Lupp Your notation is well received. It is unfortunate items like this get buried so quickly in this forum. It is even more troublesome to see post after post stating “How do I recover my lost file?”. A little “PM” goes a long way.

BTW - these macros were also tested and work using AOO.

And I noticed that my friend @Ratslinger brought up one “strong reason” why macro based backup won’t yet work, he wrote, “Base is not included as this presents other challenges.” I want a better solution for Base that does not force me to keep re-naming using Save-As which is the only solution we have right now for successive backups as I develop Base applications. e.g. Save As: MyApplication-01.odb; Save As: MyApplication-02.odb; Save As: MyApplication-03.odb, etc.

In particular, I want something like Access has: A menu item which creates a backup on my command, and allows me to modify the auto-generated place and name before committing the save. I recall back in the early days, when Access did not yet have it, and I thought it was a great improvement when it was added, and I have loved the way they got this right, and it has saved me hundreds of times when things went wrong. It’s simple and quick. It’s time LO has such a backup I think.

You can change the location where LO places backups through Tools | Options | LibreOffice | Paths

Set the location for Backups to be the same as My Documents.

Edit:
Of course this then applies to all backup files; if you have files in other than the default save directory the backups won’t be in the same location. Thanks pierre-yves samyn for reminding me :slight_smile:

That’s one location. I think you cannot “parametrize” it in a way the OQ obviously had in mind. (Except probably by tricks concerning the OS.)

Hi

Sorry, this is not possible … This is an interesting request for enhancement (especially for the problem of identical file names).

Has already been reported: tdf#68565

Regards

I’ve brought this up a few times in these posts but it is easy enough to get lost in this forum.

There is an old post in another forum containing a macro to save timestamped copies of various documents with a button or toolbar click.

This was expanded upon by @mark_t on this post by adding an automated save function. All code and instructions are in the post.

This set of macros has has two settings made by the user: how often changed documents are saved; where they are saved to. If the user saves the document (normal save procedure) the automated saves are halted until another unsaved change is made. The save event occurs via a headless call to one of the installed macros.

The directory the backup is saved in is a line of code sPathBackupFolder = "YOUR_DIRECTORY" and all copies go there. However there are ways to change this. For example, since the code already creates a directory if the specified one doesn’t exist, sPathBackupFolder = "YOUR_DIRECTORY" & oDoc.Title will put a documents’ backup in its’ own subdirectory:

There are certainly other ways to easily change directory locations.

Did a lot of testing while this was being developed (LO v 5.1.x) and works fine in Windows and Linux. No one tested this for Mac. Today I also re-ran tests using LO v 5.3.0.3 (Linux Mint 18) and had no problems. This testing included simultaneous saving of Draw, Writer and Calc documents. Impress should also work but haven’t tested. Base is not included as this presents other challenges.

The biggest down side to all this (my opinion) there is no regulation on the number of backup copies saved. Please post if anyone comes up with a process for it.

Edit 3/2/2017:

The reason Base was excluded is because of the many ways a user can implement it: Embedded, split, split using server, external DB’s etc. This is no way states a Base file can not be saved via a macro.

Many users simply use the embedded version of Base. In the Base documentation, Chapter 9 Macros, on page 63 is a macro which can be executed from a toolbar which will save the .odb in the system specified folder. This macro creates sequentially numbered backups (up to X number). Again, a little imagination can easily change where these backups are stored.

It shouldn’t be much more difficult to create macros to save other DB situations.

Also, it was good to reference the documentation again. I knew I had seen somewhere the limiting of entries in a folder. I will see about adapting this to the aforementioned macros.

There are tons of ways to do backups and many other tasks in LO that other products may have. The problem is one may have to put a bit of effort into it. It is a small PRICE to pay.

EDIT 3/6/17 :

Well I see this post is moving backward at about 1 page every two days. Soon it will be forgotten again. In the meantime, for whoever is truly interested, I have finally completed what I considered the missing function in this process - Number of copies to be retained.

The largest subroutine of the processAutomaticBackup is where the additional processing takes place. The actual use of timestamps made this more challenging. The process involves reading the backup directory for applicable previous backups, creating an array for them to reside in, loading those chosen file names into the array, sorting the array and finally deleting the unwanted backups according to the user setting.

Although I have tested this over many hours, it is always known you can never test too much. Please use this at your own risk - as you should with all posted code.

The testing included varying the number of copies saved; renaming backups in the slightest way to insure retention; changing from single backup directory to subdirectories (mentioned previously);changing just extensions and more.

Since the replacement macro is quite large, I have placed it in a document with some additional notes. If you don’t want to limit the number of copies per file, what was previously discussed is all that is needed.

Replacement Macro Document: TimedBackupReplacementMacro.odt

@Ratslinger, Humm? Looks good, but TimedBackupReplacementMacro.odt won’t run for me. This line ..= GetFileName(sDocNameWithFullPath, sSlash) is trying to call LibreOffice Macros & Dialogs.Tools.ModuleControls.GetFileName which has a different parameter signature, i.e: Sub GetFileName(oRefModel as Object, Filternames()) You have some other Libs loaded or any ideas why this won’t run.

@Ratslinger, :sunglasses: Just answered my own Q above. In the original source you referred to, I found the other auxiliary functions in the code box below the AutomaticBackup Sub (tip, scroll down far into the box), (and also an “Option Explicit” prefix that was left out). Will test again in a moment.

@EasyTrieve “Option Explicit” was not left out. It is at the beginning of the other routines in the Automated process.

Please see the above answer to get ALL the routines necessary for this AUTOMATED process to work. They are in the referenced expanded version along with the necessary instructions.

You might add a note above: Macro in Base documentation Chapter 9 Macros, page 63 reads in part, ...FOR k = 1 TO inMax - 1 TO 1 STEP -1... but should be FOR k = inMax - 1 TO 1 STEP -1. You just can’t have more than one TO in a For. :slight_smile:

Ok, bear with me please, I’m working bath through things with a fine toothed comb. In your TimedBackupReplacementMacro.odt above, your new sort, and delete etc, needs to be within the loop starting with While sBackup(i) <> "". Otherwise the optional components won’t be limited. Only the last of several BACKUP’s will be limited by your sort. That is the bug I initially found. But understanding this code allowed me a leg up on the bigger backup problem, which I am grateful-to-you for. :slight_smile:

No. You haven’t followed the above answer. It started with the original code - first link in answer. That was added onto (with other routines) & modified for those routines - second link. This answer modified the modified routine of the original. The While.. is part of the original. Just below that & starting with comment “'code inserted here to end of sub in order…” to the end of the sub was the code I added to limit # of saved records. No idea of “bug” you are talking about.

The automated routine is meant for copies for Writer(.odt), Calc(.ods), Draw(.odg) and Impress(.odp) files. These are safe types for original documents and others should be created from these.

I don’t know how to add a link to this message, at least it’s not intuitive to me. You can see Bug 68565.
Also, I think I’ll just save each document with a version number at the end of the name before I make any changes to it. That’s probably the best way as I’ll have several backups in numerical order. When I decide that a document is finished, I’ll just delete all “backups” except for the last one.

Thanks. In the future, please try and edit your original question above, instead of adding an “answer”.