Message Boards Message Boards

How to Backup and Restore my cloudwork

Posted 8 years ago

I create many objects in the Wolfram Cloud. They are all connected by menu bars and form a complete application. All objects are stored in a cloud folder. As we create a release for every sprint it becomes more and more important to backup the different versions of the application.

I tried the following to backup my app to a local folder:

create two deployed objects:

CloudDeploy[
 FormFunction[{"x" -> "Integer"}, #x! &], "/appdir3/myobject1"]
CloudDeploy[
 FormFunction[{"y" -> "Integer"}, #y! &], "/appdir3/myobject2"]

Ask your desktop frontend to create a backup of all objects:

CopyDirectory[CloudObject["/appdir3"], "E:\\folder\\backup06"]

Works as expected. Two files contain Mathematica code in text. Copy it back to the cloud using CopyDirectory

CopyDirectory["E:\\folder\backup6", CloudObject["/appdir4/"]]

The Cloudobject folder is created but no files are copied to the cloud.

Lets try this file by file.

SetDirectory["E:\\folder\\backup06"]
myfilenames = FileNames[]
CopyFile[#, CloudObject["/appdir4/" <> ToString[#]]] & /@ myfilenames

Works as expected. The two cloudobjects are now visible via the Cloud WebFrontend. Using CloudObjects["/appdir4"] proves the objects are there and can be contacted.

The only issue is that the links CloudObjects produces don't work. The WebFrontend just opens a notebook with the expression in text. Clicking the link in the desktop FrontEnd results in the browser asking what to do with the file because it probably does not recognize the mime type.

Backup and restore cloudfiles is essential for my work. Let me know if I made a mistake or should follow another set of steps.

Here's how to backup and restore your Wolfram Cloud Folders:

The backup procedure is easy because CloudObjects and Data can be copied to your local disk via CopyDirectory.

(*set new backup folder*)
directorytobackupto = "160204 full backup"

(* set local destination root for backups *)
SetDirectory["E:\\CLOUD BACKUPS\\BAC-PREP\\"]

(* list of folder for backup *)
cloudfolderstocopy = {"/BAC", "/Base/ApplicationData", "/Base/Applications"}

(* change cloud path to local path *)
localfolderstostore =  StringReplace[#, "/" -> "\\"] & /@ cloudfolderstocopy

(*Copy all folders to local disk *)
MapThread[
 (CopyDirectory[
    CloudObject[#1], directorytobackupto <> #2]; 
   Print[ #1 <> " finished"  ]) &,
 {cloudfolderstocopy, localfolderstostore}
 ]

The restore procedure is different for CloudObjects and other files. The CloudObjects on your local disk need to be re-CloudDeployed to be recognized/seen by the Wolfram Cloud server. Note the use of ExternalBundle as a BULK CloudDeploy. Restoring the data files is done by a CopyFile.

restore for cloudobjects:

(*set location to be restored folder *)
SetDirectory["E:\\BAC\\BACdir\\BACdir\\FORMS"];

(*read files, directories and all subdirs *)
myfilenames = FileNames["*", {""}, Infinity];

(* remove paths pointing to folder (and not to a file) *)
onlyfilenames = DeleteCases[myfilenames, x_?DirectoryQ];

(* replace local path escaped backslash by a foreward web slash *)
cloudfilenames = StringReplace[#, "\\" -> "/"] & /@ onlyfilenames;

(* target web folder taken as root *)
cloudappfolder = "/BAC/FORMS/";

(* External Bundle can be used in the current Wolfram Cloud to BULK CloudDeploy *)
b = ExternalBundle[cloudappfolder <> # -> Get[#] & /@ cloudfilenames];

(* if you prefer a 1 by 1 CloudDeploy use line below *)
Map[CloudDeploy[#1[[2]], #1[[1]]] &, b[[1]] ] 

restore for data

(* does not need a re-CloudDeploy, just a CopyFile*)

(* set restore local folder *)
SetDirectory["E:\\BAC\\BACdir\\BACdir\\DATA"];

(* read file names in this dir only *)
myfilenames = FileNames[]
(* copy files one by one to target cloud path *)
CopyFile[#, CloudObject["/BAC/DATA/" <> ToString[#]]] & /@ myfilenames;

Backup and restore keeps your code and data safe but the CloudObjects are not very readable. For obvious reasons the source code is also backup-ed.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract