Backing up a stack; problems with save as

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
jimlehrman
Posts: 1
Joined: Wed Jul 10, 2013 7:04 pm

Backing up a stack; problems with save as

Post by jimlehrman »

I’m wanting to write a script that periodically creates a back up copy of a stack. I want the back up stack to have a unique name that depicts the time it was backed up. But my use of “save as” is not working. I can write scripts that save the stack automatically, but can't get it to save the stack as a separate stack than the original. Can anyone help me with a script that does what I want. Here’s what isn’t working for me:
put "Client Emails BU" && the short date && the time into vBUstack
save this stack as vBUstack

I’ve also tried revSmartSave plugin and it doesn’t seem to do anything. (Maybe it’s too old?)

Thanks for any help on this.
Jimmy
San Diego CA
Paonia CO
scott_morrow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Tue Jun 27, 2006 8:35 pm
Contact:

Re: Backing up a stack; problems with save as

Post by scott_morrow »

Chipp Walters https://www.altuit.com/ shared a number of great utilities back in the day. I still use this one regularly.

Code: Select all

--|--------------------------------
--|  based on the AltArchive plugin
--|
--| Chipp Walters
--| AltArchive  version 1.7
--|--------------------------------


on mouseUp
   altShowMe
end mouseUp

on altGetInfo
  put fld "info" into tMsg
  put "altAnswer " & tMsg into toDo
  call toDo of stack "AltPlugin"
end altGetInfo

on altGetVersion
  send "altAnswer" && first word of fld "info" to stack "AltPlugin"
end altGetVersion

on openStack
  if word 1 of the systemVersion is "NT" and word 2 of the systemVersion > 5 then
    put queryRegistry("HKEY_CURRENT_USER\Control Panel\Colors\MenuBar") into tColor
    if tColor <> "" then
      put word 1 of tColor,word 2 of tColor,word 3 of tColor into tColor
      set the backgroundColor of this stack to tColor
    end if
  end if
end openStack

function checkStyle
  if the short name of the topStack = the short name of me then
    return true
  else
    return false
  end if
end checkStyle
  
on altShowMe
  
  if the altKey is down then
    if the platform is "Win32" then
      put the filename of the topstack into tfile
      #replace quote with empty in tfile
      replace "/" with "\" in tfile
      
      put "attrib"&& quote & tfile & quote && "-R" into DosCommand
      put DosCommand
      set the hideConsoleWindows to true
      put shell (DosCommand)
      answer information tfile & cr & "Unlocked"
    end if
    exit to top
  end if
  
  put the short name of the topStack into StackName
  put the mainStack of stack StackName into StackName
  
  if the effective filename of stack StackName is empty then
    --> THE STACK HAS NEVER BEEN SAVED
    answer question "This stack has never been saved." & cr & "Do you wish to save it now?" with "Cancel" or "Okay"
    if it is "Cancel" then exit to top
    revSaveAs StackName
  else
    answer question "Archive Stack: " & StackName with "Cancel" and "Okay"
    if it is "Cancel" then exit to top
    revSave StackName
  end if
  
  put the fileName of stack StackName into StackFileName
   
  put the fileName of stack StackName into folderPath
   
  set itemDel to "/"
  put the last item of folderPath into fileName
  delete last item of folderPath
  put folderPath & "/" into folderPath
  set itemDel to "."
  if the number of items in fileName > 1 then
    delete the last item of fileName
  end if
  set itemDel to ","
 
  put the defaultFolder into savedDF
   
  set the defaultFolder to folderPath
  put the files into fileList
   
  --CHECK TO SEE IF ARCHIVE FOLDER EXISTS
  if there is not a folder "archive" then
    printMsg "making folder Archive",""
    create folder "archive"
  end if
  put folderpath & "archive/" into folderpath
  set the defaultFolder to folderPath
   
  repeat with count = 1 to 1000
    if count < 10 then
      put fileName & "0000" & count & ".rev" into file2save
    else
      put fileName & "000" & count & ".rev" into file2save
    end if
    if there is not a file file2save then
       
      -- IF YOU UNCOMMENT THE BELOW YOU NEED TO COMMENT THESE THREE LINES
      put "binfile:" & StackFileName into file2copy
      printMsg "File to Copy", StackFileName
      put "binfile:" & folderpath & file2save into archiveFile
      printMsg "Archive File:" ,folderpath & file2save
      put url file2copy into url archiveFile
       
      exit repeat
    end if
  end repeat
  set the defaultFolder to savedDF
   
end altShowMe


on printMsg msg1 msg2
--  --NEED TO COMMENT OUT WHEN IT'S A PALETTE
--  put msg1 & ":" & msg2 into line (the number of lines of fld "test" of stack "revArchive" + 1) of fld "test" of stack "revArchive"
end printMsg
Elementary Software
...now with 20% less chalk dust!
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10544
Joined: Wed May 06, 2009 2:28 pm

Re: Backing up a stack; problems with save as

Post by dunbarx »

I have never tried this. But a simple handler in a button:

Code: Select all

n mouseUp
   save this stack as "backup" & random(99)
end mouseUp
does NOT create a new stack such as "backup32". Not sure why not, but will play with it tomorrow when I get to my office with better tools, and to see if the filePath is being improperly ignored.

Craig
SparkOut
Posts: 2990
Joined: Sun Sep 23, 2007 4:58 pm

Re: Backing up a stack; problems with save as

Post by SparkOut »

Not tested, but I suspect a confusion between the "name" of the stack and the "filename" of the stack.
Klaus
Posts: 14354
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Backing up a stack; problems with save as

Post by Klaus »

Hi Jim,

you need to create a COPY of the binary stackfile on disk!
Something like this (out of my head):

Code: Select all

command saveAcopy

   ## IMPORTANT to get an up-to-date set of data!:
   save this stack
   
   ## To make sure the copy is in the SAME directory as the stack
   ## Change this if you want to save the copy elsewhere
   put specialfolderpath("resources") & "/" into tTargetFolder
   put tTargetFolder & "Client Emails BU" && the short date && the time into vBUstack
   
   ## Filename of the binary file to copy
   put the filename of this stack into tSource
   put url("binfile:" & tSource) into url("binfile:" & vBUstack)

  ## Optional, but you'll need to define an EXIT here:
  send "saveAcopy" to me in 60 secs
  ## or whatever frequnency you prefer
end saveAcopy
HINT:
This will NOT change the NAME of the stack.

Hope that helps!

Best
Klaus
Post Reply