Backup

Could someone point me in the direction of a description/flowchart for backing up you Codea projects. I have tried to use this over the last few years with little success.

I suspect that my problem is down to numerous active projects and a Dropbox Codea account with 2090 files in it.

Backing up takes ages and the file is of the order of 890 mbytes.

I currently use the project @dave1707 has posted which records the code in a simple text file. But it takes a majorette-install/time to regenerate my Codea active projects. I’m in the middle of this now after a re-install and would like to trial the Backup procedure with only a few projects.

@Bri_G I’m not sure which backup program of mine your using because the one I use now is automatic. You can restore 1, 2, or how many you select or you can restore all of them automatically. But Codea has a backup program that works. You can restore some or you can restore all. The Codea backup saves a lot more of the unseen files Codea uses for each project whereas mine only does the text file. To use Codea’s, go to the Codea project screen, tap the gear icon at the upper right of the screen, then scroll all the way to the bottom. You’ll see an Export Projects Button. Pressing that will backup every project into a zip file you can save wherever you want. To restore files, you export the zip file and copy it into Codea where it will ask which projects you want to restore. The only problem is the restore part wasn’t put in the current version yet. It might be in the next release.

@dave1707 - the program that you published selects the archive file, lists the projects then, after enabling, allows you to select a single project and then install it. It works fine.

On the Codea Backup I thought it wasn’t transferring to Dropbox. When you go through the Backup function it comes back, building the file, with the file size and presents two options -1. To open in or 2. To save. On. The open in its the iPad sharing dialogue which contains two options for Dropbox.

I don’t use this much at all preferring to save small files. The last one I tried started but I couldn’t see any evidence for the transfer - later found it was still trying to upload the following day!!!

My use of the Codea Dropbox storage is simple - I put in there what I use at the moment and anything I think could be of use later. Hence the size. If Codea stores this data in a Backup it’s a waste of space and transfer time. I think the user should be responsible for the Dropbox data and Codea should only save the code plus a list of paths and names of external resources used (possibly as a commented out list). That would reduce the Backup requirements on Codea.

Another option I think should be available is an export option which could download all resources for a single project producing project.spritepack etc. This may be available for export to Xcode, which I have so far not used.

Whilst I’m on data storage, is there anywhere describing the construction of a project.spritepack, I’ like to build a few?

@Bri_G One thing I did in the Dropbox app was create a bkup folder in my Codea folder. When I save backups to the Dropbox app , I move them to to the bkup folder so anytime I do a sync in Codea, it doesn’t copy the files to the Codea Dropbox folder. Then when I need a file from the Dropbox app, I’ll copy the file from bkup to the Dropbox Codea folder then do a sync in Codea to get the file there.

The backup program you have of mine, does that one allow you to do a mass restore, or do you manually have to restore one project at a time.

@dave1707 - the backup you coded, which I use, is only a single file backup and restore - no mass restore.

@Bri_G I think you and everyone else that wants to do backups should start using the Codea backup. The backups can be done now, but the restore won’t work until it’s added in a future release. It was left out for reasons I don’t know but @Simeon knows about it and said he’ll get it back in.

@dave1707 - I have been downloading using your backup and generally without problem, but, a couple of downloads have thrown up an error at the top of the first tab beyond Main. I can’t see an obvious error I am trying to use two line the first as —# and the second as —. For comments and for sorting into tabs. Have you encountered this?

@Bri_G I’ve rewritten my backup program many times, so I’m not sure which one you’re using. The only thing I can suggest is to see what’s different between the projects that work and the ones that don’t. I haven’t used my backup because I’ve been using the Codea backup program. I just hope the Codea restore option is put back in before I need to do a restore.

@Bri_G Obviously it’s a backup you loaded from the forum. If you can find it again on the forum, I can load it and see if I can see what’s wrong.

P.S. if you can’t find it, it may be easier to post what you’re using here for me to load. I can then delete it from the forum after I copy it.

@dave1707 - don’t know which version it is, but I haven’t had any problems with it until recently. I’m still using it to reload old files since the recent re-install of Codea. Files that clash are very few. The files I have been extracting from are pretty big and some old files in them. I need to see if I can find a few small files showing the error, re-write them as new workable files then backup and try a restore. At the moment I’m too busy filtering out the files I want to keep and working on new projects. I’ll let you know when I find something.

@dave1707 - another funny observation with it is that, you know the red arrow pointer on the right hand of the transparent error bar, where the error text is shown when tapped - you normally see an error description but in this case it just gives 4. Weird!!!

I seem to remember something like this in the early days of Backup, but several generations of Codea and iOS later changes may bring new issues. Not worth pursuing at the moment unless I find a lot of files like this in the backup file.

@dave1707 - just been fiddling with your backup code to generate lists of backup files. Code below:


-- BackupLister

-- Use this function to perform your initial setup
displayMode(OVERLAY)
function setup()
    proj=listProjects("documents")
    param()
    pns="PROJ".."NAME".."START" -- project name start
    pne="PROJ".."NAME".."END"   -- project name end
    tns="TAB".."NAME".."START"  -- tab name start
    tne="TAB".."NAME".."END"    -- tab name end
    te="TAB".."END"             -- tab end
    pe="PROJ".."END"            -- project end
    init()
end

function param()
    pasteboard.text=""
    parameter.clear()
    parameter.action("Select a backup file.",selectProject)
    parameter.action("List all projects.",showProjects)
end

function draw()
    background(0, 0, 0, 255)
    title = "BackupList"
    fill(255, 14, 0, 255)
    font("Georgia-BoldItalic")
    fontSize(64)
    text(title, WIDTH/2, HEIGHT/2)
end

function selectProject()
    output.clear()
    pasteboard.text=""
    local lst=assetList("Dropbox")
    for a,b in pairs(lst) do
        if string.find(b,"bkup") then
            print(b)
        end
    end
    b=""
    nextFunction="show"
end

function showProjects()
    output.clear()
    local s=#pasteboard.text
    local name=string.sub(pasteboard.text,1,s-1)
    print(name)
    tabName = name
    bkupFile=readText("Dropbox:"..name)
    if bkupFile==nil or nextFunction~="show" then
        print("No backup file was selected.")
        return
    end
    local sss=pns.."==(%g+)=="..pne
    for projName,proj in     
            string.gmatch(bkupFile,sss) do
            print(projName)
            fileList = fileList..projName.."\
"
    end
    fileList = fileList.."--]]"
    pasteboard.text=""
    saveProjectTab(tabName, fileList)
    init()
    nextFunction="extract"
end

function init()
--
    tabName = ""
    fileList = "--[[\
"
end

I just wanted to get hold of lists of my backups so that I can annotate them to provide more information on status and uses. The code saves each backup list to a commented tab so that you can see all files in each tab. One of my lists has 275 entries. Many are dead ended project code, lots of duplication. I can use Aircode to read it on a Mac/Pc to add to a text document or database.

I’m thinking of how we could include version data etc.

Anyways hope it is of some use - you can probably clean this up further.

@Bri_G As for cleaning up the code, here’s a version that prints the project name and then indents and prints any tab name in that project. I just print the list instead of saving it in a tab. Just change the file name in readText.

function setup()
    
    str=readText("Dropbox:bkup1217-1925")
    
    ss,sp="",""
    for a in string.gmatch(str,"PROJNAME(.-)PROJEND") do           
        for b in string.gmatch(a,"START==(.-)==") do    
            ss=ss..sp..b.."\
"
            sp="   "
        end
        sp=""
        ss=ss.."\
"
    end
    print(ss)
end

Here’s a similar program that lists all the projects and the tabs with it’s size within that project for the current Codea projects.

function setup()
    ss=""
    lp=listProjects("Documents")
    for a,b in pairs(lp) do
        ss=ss..b.."\
"
        lt=listProjectTabs(b)
        for c,d in pairs(lt) do
            size=readProjectTab(b..":"..d)  
            str=string.format("   %-15s %6d\
",d,#size)          
            ss=ss..str
        end
        ss=ss.."\
"
    end
    print(ss)
end

@dave1707 - thanks for the routines, they will save me some time and add the features I was planning to add. I prefer to list in the tab as I find printing a little bit messy with the additional lines - a lot of scrolling with some of my backups. Also I just use the tab lister as a library, no need to run the program once a backup file has been added just find the tab and they are all there.

Is there any way you can add a date stamp?

@Bri_G Here’s an updated version to list projects and tabs in your backup files. It saves the list in a tab like you did. You have the option to list projects and tabs or just projects. To run, tap show projects, tap on a file name, then tap create list.

PS. I added the date to the list.

function setup()
    pasteboard.text=""
    parameter.action("show projects",selectProject)
    parameter.boolean("projectNamesOnly",false)
    parameter.action("create list",createList)
end

function createList()  
    if pasteboard.text=="" then
        print("file not selected")
        return
    else
        name=string.sub(pasteboard.text,1,#pasteboard.text-1)
    end
    str=readText("Dropbox:"..name)

    ss,sp="",""
    ss="--[[\
\
"..string.match(str,"BKUP==START..(.-)\
").."\
\
"
    for a in string.gmatch(str,"PROJNAME(.-)PROJEND") do 
        sp=""
        for b in string.gmatch(a,"START==(.-)==") do 
            if projectNamesOnly then
                if sp=="" then
                    ss=ss..b
                    sp="   "
                end
            else
                ss=ss..sp..b.."\
"
                sp="   "
            end
        end
        ss=ss.."\
"
    end
    ss=ss.."\
--]]"
    saveProjectTab(name,ss)
    print("done")
end

function selectProject()   
    output.clear()
    pasteboard.text=""
    local lst=assetList("Dropbox")
    for a,b in pairs(lst) do
        if string.find(b,"bkup") then
            print(b)
        end
    end       
end

@dave1707 - wow, very neat. I was part way through adding these features myself after reading your previous code. You must have a lot of time to devote to this or can juggle mentally whilst doing other things.

Thanks for that - makes it easier to see what my old backups involved.

@Simeon - is there any way we can programmatically see the collections and the associated project files. It would be neat to be able to backup a development collection containing all development files and analyse them at a later date using @dave1707 code and re-installing a collection if needed.

@Simeon - another question with regard to Dropbox, there have been many developments there since first integrating into Codea. Is there any way that we can now get Dropbox to recognise a Codea file so that we can run one directly without downloading and installing?

Also, are we only restricted to Dropbox, have you considered adding similar features for iCloud, Box etc.?

@Bri_G I do have a lot of time for the forum and/or Codea. I’m retired and programming keeps my mind active. As for juggling things while doing something else, I do that too. While watching TV, I’m either looking at the forum or writing code for myself or someone on the forum. Very enjoyable.