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.