Bug 57913 - Automated backups of last saved JMX files
Summary: Automated backups of last saved JMX files
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: Main (show other bugs)
Version: 2.13
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
Depends on:
Reported: 2015-05-10 19:08 UTC by Benoit Vatan
Modified: 2015-06-07 12:43 UTC (History)
1 user (show)

Patch for backing JMX file when saving (12.62 KB, patch)
2015-05-10 19:08 UTC, Benoit Vatan
Details | Diff
auto-save patch update after first comments (v2) (16.66 KB, patch)
2015-05-11 22:06 UTC, Benoit Vatan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benoit Vatan 2015-05-10 19:08:38 UTC
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

# 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

# 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

Backup files are created in a subdirectory of the main JMX file and is named from the JMX name suffixed with ".backups"


We are saving to an existing jmeter.jmx file in some /path/to directory , we'll then have :


where /path/to/jmeterx.jmx.backups will contains the backups history :

This would prevent anyone to lose work anymore...

Comment 1 Felix Schumacher 2015-05-10 19:52:58 UTC
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"?
Comment 2 Philippe Mouawad 2015-05-10 20:27:02 UTC
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

Comment 3 Benoit Vatan 2015-05-10 21:11:12 UTC
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.

Comment 4 Benoit Vatan 2015-05-11 22:06:09 UTC
Created attachment 32730 [details]
auto-save patch update after first comments (v2)
Comment 5 Benoit Vatan 2015-05-11 22:14:26 UTC
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.

Comment 6 Philippe Mouawad 2015-05-12 21:04:37 UTC
Date: Tue May 12 21:03:51 2015
New Revision: 1679098

URL: http://svn.apache.org/r1679098
Bug 57913 - Automated backups of last saved JMX files
Bugzilla Id: 57913

Comment 7 Philippe Mouawad 2015-05-12 21:04:54 UTC
Thanks a lot for your contribution.
Comment 8 Philippe Mouawad 2015-06-05 20:16:26 UTC
Date: Fri Jun  5 20:15:35 2015
New Revision: 1683855

URL: http://svn.apache.org/r1683855
Bug 57913 - Automated backups of last saved JMX files
Add related properties to jmeter.properties
Bugzilla Id: 57913

Comment 9 Milamber 2015-06-07 08:54:31 UTC

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)
Comment 10 Felix Schumacher 2015-06-07 12:43:46 UTC
Date: Sun Jun  7 12:42:42 2015
New Revision: 1684029

URL: http://svn.apache.org/r1684029
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

Comment 11 The ASF infrastructure team 2022-09-24 20:37:59 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/3591