Marvin's Paranoid Backup Script

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 349
Joined: Mon Jun 10, 2013 1:32 pm

Marvin's Paranoid Backup Script

Post by Lagi Pittas » Mon May 11, 2015 2:54 pm

Even though I save my projects in a folder in my dropbox which allows me to go back 2 hundreds of previous version. I still lose a lot of work when livecode crashes - and it does far too frequently - usually when I have been using the debugger.

Oh but you should save every 5/10 minutes I hear you say - many times I save more often than that but then you get engrossed in solving a problem and you press apply instead of CTRL-S.

So here is my Fix

1. I still save my project in a dropbox directory
2. I have my time-machine backup which backs up hourly
3. I place the following script in my working stack which backs up OUTSIDE the dropboxfolder onto my machine and an external hard drive

Code: Select all

-- Script Local Variable in main Stack Script
Local snCallNumber


-- Call this in PreOpenStack or OpenStack
-- Should be removed in final Standalone
on AutoSaveStack
   
   if the environment <> "development" then exit AutoSaveStack
   
   -- Mainly when debugging could have multiple pending Autosave messages
   
   
   -- save this stack every 10 minutes to a dropbox directory
   -- First Call asks to save - second call makes the backup
   if snCallNumber = 0 then 
      add 1 to snCallNumber
      beep 
      save this stack
      ClearPending("AutoSaveStack")
      send AutoSaveStack to me in 15 seconds
      exit AutoSaveStack
   end if
   
   put zero into snCallNumber
   send AutoSaveStack to me in 600 seconds
   SaveLocalCopy
   
end AutoSaveStack

on SaveLocalCopy
   local lcSaveDefault, lcBackupPath = "/Volumes/WinMac/lcbackups/"
   local lcBackupName, lcCurrentName, lcOriginalFile,  lcFileList, lnFileNum, lnNext
   
   local lcNonNumeric =  "[ \.\-\\ABCDFEGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]"
   
   put GetStackPath() & "/" into lcSaveDefault
   
   put the short name of this stack into lcBackupName
   put the short name of this stack into lcCurrentName
   
   set the defaultfolder to lcBackupPath
   
   put the files into laFileList
   
   put zero into lnNext
   repeat for each line lcLine  in laFileList
      if offset(lcCurrentName, lcLine) > 0 then 
         put replacetext(lcLine,lcNonNumeric,"") into lnFileNum
         
         -- Now get the last 4 digits - just in case we have a digit in the name
         put  char -4 to -1 of lnFileNum into lnFileNum
         
         -- Defensive programming Just in case we have non-numerics left in lnFileNum or a bug in the logic
         if lnFileNum is not a number then put 2000 into lnFileNum -- 2000 should be a over a months worth
         
         try
            if lnFileNum > lnNext then put lnFileNum into lnNext
         catch lcErr
            answer lnFileNum & CR & lcErr
            put 2000 into lnNext 
         end try
         
      end if 
   end repeat
   
   -- Pad with Zeroes so when we sort latest is first
   add 1 to lnNext
   put format ("%04d", lnNext) into lnNext
   
   put lcBackupPath & the short name of this stack &  lnNext into lcBackupName
   put ".livecode" after lcBackupName
   
   -- Load the current file on disk as a binary/raw data file
   put lcSaveDefault & lcCurrentName & ".livecode" into lcOriginalFile
   get url("binfile:" & lcOriginalFile)
   if IT is empty then
      Answer "Error reading Original Stack : " & lcOriginalFile
   end if
   
   
   -- And save it to a local directory, USB or external drive for ease of access and peace of mind!
   put IT into url("binfile:" & lcBackupName)
   
   set the defaultfolder to lcSaveDefault
   
end SaveLocalCopy

function getStackPath
   local lcPath
   
   put the filename of this stack into lcPath
   set the itemdel to "/"
   
   -- Delete the filename
   delete  item - 1 of lcPath
   return lcPath
   
end getStackPath

on ClearPending pMsg
   local lcLine
   
   repeat for each line lcLine in the pendingmessages
      if pMsg is in item 3 of lcLine then
         cancel item 1 of lcLine
      end if
   end repeat
end ClearPending

3. Allows me to quickly restore without going onto the dropbox website plus allows fine grain background saving (every 10 minutes at the moment) whether I press CTRL-S or not.

This averages about 60+ files in a day which can be removed by hand and the last one renamed with the day when I start again next day. I also rename the stack by adding a letter/word or 2 - so the new file names star again with a 0001 suffix.
This is another defence that means if I accidentally load an old stack while the newest is loaded, worst case Livecode mixes up the library stacks which very rarely change. This only happened once in the early days (purge/cancel??) but others have had the same problems.

So now I have a backup in my dropbox directory , in the dropbox cloud (with untold previous versions), on my main hard disk and my external drive and timemachine.


Any mods, changes, suggestions, greatly appreciated.

As Marvin would say - "Backups? Don't talk to me about Backups!"

With apologies to Douglas Adams.

Regards Lagi

p.s.

Is there a way to get the system to "press" the APPLY Button on the editor?

Oh and yes I know I COULD find the last filename quicker by sort descending (I did at first), but I thought going through all files would be safest ... just in case ... Paranoid Moi??
Last edited by Lagi Pittas on Mon May 11, 2015 4:38 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7405
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Marvin's Paranoid Backup Script

Post by dunbarx » Mon May 11, 2015 3:52 pm

Having LC crash can be a pain in the diodes. But I rarely see this, recursion runaways excepted, and I think many others will agree.

What version are you using? I must admit that I am lazy, and still in 6.7.4, and one of the reasons I am there is due to stability.

Craig Newman
Last edited by dunbarx on Tue May 12, 2015 6:18 pm, edited 1 time in total.

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 349
Joined: Mon Jun 10, 2013 1:32 pm

Re: Marvin's Paranoid Backup Script

Post by Lagi Pittas » Mon May 11, 2015 4:07 pm

Hi Craig

I am using the latest Stable commercial 7.04.

It is not runaway recursion I don't know if its my stack which has 4 grids on 1 card but it has hung before with only a testing grid on 1 card. I'll be honest it's MUCH better than it was one day iwhen t crashed on me probably over 20 times but that was a couple of months ago.

What do I lose by going back to the six series other than unicode which is of no interest to me in this program. Will the developers backport Useful stuff into 6.x from 7/8 as they do in Python 2/3?

Regards Lagi

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

Re: Marvin's Paranoid Backup Script

Post by SparkOut » Mon May 11, 2015 5:53 pm

Not quite the same issue, so I'm nervous of posting in this thread, but LC 7.0.4 and 7.0.5 are the most unstable versions I've yet seen on Windows. I haven't had chance to get 8 to install properly or see what's going on with that, but in the 7.0.x versions there are frequent ghost windows, disappearing items, lack of response to property inspector, or even ability to view the property inspector. This was happening before I tried the hack to filter global variables view from the debugger pane, but I've also reinstalled LC 7.0.5 (community) without interfering, so as to eliminate that from the list of possible factors. Now an Android phone app that was working fine this morning, has become unusably slow (10 minutes to "go card 1") without any change to the stacks, but simply recompiling has made all code in the app run like treacle on a cold day.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3211
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Marvin's Paranoid Backup Script

Post by mwieder » Mon May 11, 2015 10:37 pm

LC 7.0.4 and 7.0.5 are the most unstable versions I've yet seen on Windows
or on linux. With the exception of LC8, which is all but unusable on linux, and barely usable on OSX.

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 349
Joined: Mon Jun 10, 2013 1:32 pm

Re: Marvin's Paranoid Backup Script

Post by Lagi Pittas » Tue May 12, 2015 6:16 pm

HI

I did ask if anybody knew how to make the script "press" the "Apply button in the editor.

I have tried the usual optionkeydown with "s" TYPE 's" with commandkey etc put it seems to need the focus on the tab. I even went into the libraries and found an idestacksave , which does save the stack but doesnt do an apply.

Anybody know how to in effect focus on each editor tab and do an apply?

Regards Lagi

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”