Created attachment 32725 [details] Patch for backing JMX file when saving After an OOME occured while saving my test plan, a significant part of it was lost and made the whole work unusable without "handworking" the XML. Given that no recent copy of my work was available to me anymore, I was really angry and in bad situatio, lesson learnt : don't ever forget backing up your work. I thus have brought some enhancement to the JMX save process so that it keeps a copy istory of the last saved JMX. What's more I am aware that this did happened to someone else so I come to the conclusion that sharing it might be usefull to someone else. The attached patch adds logic to the JMX save process so that the last saved JMX file is copied with a timestamp suffix. user.properties contains properties to control backup history : # Enable backup history, defaults to true # Set to false to return to the default behaviour #jmeter.gui.action.save.backup_when_saving=true # Set the max number of hours that existing backups are kept # older backups are delete when a save operation occurs # Default is keep backup for ever #jmeter.gui.action.save.keep_backup_max_hours=0 # Set maximum number of backup to be kept # Default is 10, so while we set no max_hours we only keep at most 10 backups #jmeter.gui.action.save.keep_backup_max_count=10 Backup files are created in a subdirectory of the main JMX file and is named from the JMX name suffixed with ".backups" Example: We are saving to an existing jmeter.jmx file in some /path/to directory , we'll then have : /path/to/jmeter.jmx /path/to/jmeter.jmx.backups where /path/to/jmeterx.jmx.backups will contains the backups history : jmeter.jmx.20150502-180909 jmeter.jmx.20150502-180911 jmeter.jmx.20150502-180915 jmeter.jmx.20150502-180916 jmeter.jmx.20150502-180917 jmeter.jmx.20150502-180919 jmeter.jmx.20150502-180920 jmeter.jmx.20150502-180921 jmeter.jmx.20150502-180922 jmeter.jmx.20150502-180923 This would prevent anyone to lose work anymore... Regards. Benoit
I think the general idea is great. Nobody likes it, when their work vanishes while saving. Even when it saves correctly, one might have done something stupid and would like to have it back. I wonder, if it would be nicer to enumerate the backup files and keep the .jmx suffix. The time and date of the save operation, will most probably be available by looking at the file stats. And I don't know if I like the idea of a directory called after the file name. Apart from that, a few nitpicks: * instead of backup_when_saving I would have chosen backup_on_save or backup_before_save * One comment is "... everything when right..." where it probably should be "... everything went right ..." * deleteMe variable could be renamed to expiredBackupFile or something alike * in javadoc shorten the code tag in line 249ff to enclose only code fragments, that way true and false could be tagged as code as well * The variable emptyList in line 265 could probably be inlined in line 270 * line 297 "expiry date" or your "cutoff date" instead of "oldest date"?
Hi, Thanks for great contribution. As Felix I think it is very useful feature that I have seen requested many times. Few notes: 1/I think properties should be in jmeter.properties: 2/ Local variables that are initialized from JMeterUtils.getPropDefault should be static final constants Regards
Creating a backup subdirectory after the JMX file does not smell good to me either. At first backups were stored directly in the same directory as the JMX file, but this quickly mess the directory up, hence the .backup subdir. Wouldn't it be better to have some default backup directory, say in JMETER_HOME/backups or something ? This could be controlled by some jmeter.property with a default destination that could be user overridden in user.property ? This would then leave the JMX save directory as clean as possible. I will update the code and provide a patch after your above comments. Thanks for your feedback. Benoit.
Created attachment 32730 [details] auto-save patch update after first comments (v2)
Here it is, I think I have updated the patch to take all your remarks into account. Backup files are now stored by default in ${JMETER_HOME}/backups unless jmeter.gui.action.save.backup_directory is set to a different location. jmeter.gui.action.save.backup_on_save has been renamed according to Felix's advice. Backup file names are now timestamp free, replaced by a version number auto-incremented from the highest version found in the already existing backup files. Backup extensions is now .jmx instead of a timestamp. I have rework the code to make it simpler and make use of commons-io filters. Reworked the javado, mistyped comments and renamed variable names as well according to your recommandations. Properties have been moved to system.properties with the default values. I have updated hints_and_tips documentation but I'm not sure of the format so it might have to be checked. Regards.
Date: Tue May 12 21:03:51 2015 New Revision: 1679098 URL: http://svn.apache.org/r1679098 Log: Bug 57913 - Automated backups of last saved JMX files Bugzilla Id: 57913 Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/Save.java jmeter/trunk/xdocs/changes.xml jmeter/trunk/xdocs/usermanual/hints_and_tips.xml
Thanks a lot for your contribution. Regards
Date: Fri Jun 5 20:15:35 2015 New Revision: 1683855 URL: http://svn.apache.org/r1683855 Log: Bug 57913 - Automated backups of last saved JMX files Add related properties to jmeter.properties Bugzilla Id: 57913 Modified: jmeter/trunk/bin/jmeter.properties
If you save a new file (the first time), you have a error in jmeter.log: 2015/06/07 09:24:09 INFO - jmeter.services.FileServer: Default base='/home/milamber/W-workspaces/Workspaces-JMeter/Jmeter/bin' 2015/06/07 09:24:09 INFO - jmeter.services.FileServer: Set new base='/home/milamber/W-workspaces/Workspaces-JMeter/Jmeter/bin' 2015/06/07 09:24:09 ERROR - jmeter.gui.action.Save: Failed to backup file :/home/milamber/W-workspaces/Workspaces-JMeter/Jmeter/bin/Thread Group.jmx java.io.FileNotFoundException: Source '/home/milamber/W-workspaces/Workspaces-JMeter/Jmeter/bin/Thread Group.jmx' does not exist at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1074) at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1038) at org.apache.jmeter.gui.action.Save.createBackupFile(Save.java:379) at org.apache.jmeter.gui.action.Save.doAction(Save.java:213) at org.apache.jmeter.gui.action.ActionRouter.performAction(ActionRouter.java:81) at org.apache.jmeter.gui.action.ActionRouter.access$0(ActionRouter.java:69) at org.apache.jmeter.gui.action.ActionRouter$1.run(ActionRouter.java:63) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:694) at java.awt.EventQueue$3.run(EventQueue.java:692) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:703) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91) I think a test condition must be adding before create the backup file (don't copy if that is the first save)
Date: Sun Jun 7 12:42:42 2015 New Revision: 1684029 URL: http://svn.apache.org/r1684029 Log: Bug 57913 - Automated backups of last saved JMX files Only backup file, if it exists (otherwise we get an exception on first save of a file). Bugzilla Id: 57913 Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/Save.java
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/3591