Aug 7, 2010

Multiple autosave in nuke

So we had a little dataloss yesterday, some of our nuke files went 0B in size. Checked the autosaves... none existing! What happened (other than file system corrruption or what)? We are working on linux, and the NUKE_TEMP_DIR environment variable was properly set in init.py. But, nuke was started as a simple user, and that dir can be written only by root. At least this is my idea. That's about it, but I started to think where and how to place autosaves properly. We now having them in /home/user/Nuke/autosaves folder. Another question is how to preserve the autosave files? Because nuke deletes them as soon as the scene is saved, but we need them to stay, for these occasional dataloss events.
I found a tip in the mailing list, to include the current date, time in the autosaved filename:

/autosaves/[date %y]-[date %m]-[date %d]_[date %H]-[date %M]_[file tail [value root.name]]
But this is too long, and can get infinite number of autosaves.

So another tip: include only the current minute, so it starts again in the next hour, maximum of 60 file (for 1 scenefile, if you save a new version there can be another 60!)
[file rootname [value root.name]]-[date %M].nk.autosave
it gives path like (when for example the current time in minute is 15):
w:/Projects/Test/AutosaveTest/AutosaveTest_v001-15.nk
But that is still to much files.

How can it be reduced? I could include a modulo (%) operator to limit the number of minutes, like %6 gives only 0-5. It's great, but think. When minute is 01, it writes in the fileneme 01. When 02, 02 and so on, and when 06, it starts from the beginning. It would be better to have 1 autosave filename in the first 5 minutes (continuously overwritten), then another in the next 5 minutes, and so on. So in half an hour you still would have the first file, and that gives a good chance to go back if something went wrong. This can be achieved, by an expression like this:

[file rootname [value root.name]]-[expr int ([expr [date %M]%30]/5)].nk.autosave

Let's look at this from closer! The first part (before the "-") is simply gives back the file path, but without extension, so we can put anything after this. The second part can be understood from inside the date part: [date %M] is the minute of current time (That's going 0-59). Outside there is an expr(ession) command for the modulo (%30) operation, that gives the remaining of current minute and 30, with this we modified the range to 0-29. Then comes "/5", notice the brackets, so range is 0-5.8. Then the "expr int" takes only the integer of this. The final range is 0-5 integer only. This is pasted after the filename.
Now this expression makes a "filename-0" file when current minute is between 0-4, then "filename-1" when minutes 5-9... and at 30 it starts from the beginning, overwriting the "filename-0". There can be maximum of 6 files, for 1 version. But remember if you save the script (ctrl-s) the last autosave will be deleted!
I hope this will be useful for someone. Modify as you need.

6 comments:

  1. A little addition: nuke could throw an error, when the current minute is "08" or "09", saying: "expected integer, got 09 (looks like invalid octal number". I modified the expression like this:
    [file rootname [value root.name]]-[expr int ([expr [scan [date %M] %d]%30]/3)].autosave
    Notice the scan function, that strips the 0!

    Our whole autosave expression looks now like this on windows:
    [set err [catch {value root.shotid} shotid]; return][if {$err} {set shotid "other"}; return][file mkdir c:/Users/user/Documents/nuke/autosaves/$shotid]c:/Users/user/Documents/nuke/autosaves/$shotid/[file tail [value root.name]]-[expr int ([expr [scan [date %M] %d]%30]/3)].autosave

    ReplyDelete
  2. This is a great post, and much more than I need. All I need to do is to change my default autosave location to a set place on my local drive. Do I only use this section of your script: [file mkdir c:/Users/user/Documents/nuke/autosaves/$shotid]c:/Users/user/Documents/nuke/autosaves/$shotid/[file tail [value root.name]].autosave

    Or am I still missing something?
    Thanks again for the post.

    ReplyDelete
  3. Hi I post this here as well on the nuke list, sorry for the late post :

    for example your new autosave target dir is:
    /home/user/temp

    then you can write
    /home/user/temp/[file tail [value root.name]].autosave

    with this nuke will create the autosave file there with the original
    file name+".autosave"

    ReplyDelete
  4. Got it. I used this:
    "C:/Users/dshort/Work/NukeAutosaves/[file tail [value root.name]].autosave"

    ReplyDelete
  5. [set temp "[getenv NUKE_TEMP_DIR]/autosaves/"; return][set root [file dirname [value root.name]]/[file rootname [file tail [value root.name]]]_autosaves; return][set data [date %Y-%m-%d]_[date %H-%M-%S]; return][if {[value root.name] == ""} {return [set main_dir $temp; return]} {return [set main_dir $root; return]}][file mkdir $main_dir]$main_dir/$data.autosave

    ReplyDelete
    Replies
    1. # Set 'temp' variable and return nothing
      [set temp "[getenv NUKE_TEMP_DIR]/autosaves/"; return]

      # Set 'root' variable and return nothing
      [set root [file dirname [value root.name]]/[file rootname [file tail [value root.name]]]_autosaves; return]

      # Set 'data' variable and return nothing
      [set data [date %Y-%m-%d]_[date %H-%M-%S]; return]

      # If projects not saved - use temp else use root directory
      [if {[value root.name] == ""} {return [set main_dir $temp; return]} {return [set main_dir $root; return]}][file mkdir

      # join directory and .autosave
      $main_dir]$main_dir/$data.autosave

      Delete