Question
Evgeny Shvarov · Apr 1, 2017

Is there an option to export globals in archive?

Hi, Community!

Is there an option to get an archived file of globals in one command. Say for:

Do $System.OBJ.Export("Class1*D.GBL,Class2*D.GBL","data_gbl.xml")

get something like:

Do $System.OBJ.Export("Data*D.GBL","data_gbl.gz","gzip")

And also to have the convenient one click way to  import it to the namespace via terminal or Control Panel?

If anyone already has this module, share please?

It would be very convenient for import/export/continuous integration purposes cause globals can be really heavy.

0
0 749
Discussion (8)4
Log in or sign up to continue

Hi Evgeny,

Not exactly one command, but it can be done on one line...

set file="foo.zip" do $System.OBJ.ExportToStream("foo*.GBL",.s) open file:("WNS":/GZIP=1) use file Do s.OutputToDevice() close file do s.Clear()

This should work in reverse opening the file with the GZIP flag, read the contents to a temporary binary stream and then using the $System.OBJ.LoadStream on the temp binary stream.

Sean.

It can be done with Gzip stream directly:

set ^dbg=123
set s=##class(%Stream.FileBinaryGzip).%New()
do s.LinkToFile("1.xml")
do $System.OBJ.ExportToStream("dbg*.GBL", s)
do s.%Save()
kill
kill ^dbg
set s=##class(%Stream.FileBinaryGzip).%New()
do s.LinkToFile("1.xml")
do $System.OBJ.LoadStream(s)
write ^dbg
>123

Finally, have the following for globals export/import in gzip:

// export gbl
set gbl="foo*D.GBL,boo*D.GBL"
set s=##class(%Stream.FileBinaryGzip).%New() do s.LinkToFile("1.xml.gz") do $System.OBJ.ExportToStream(gbl,s) do s.%Save() kill s
// gbl import
set s=##class(%Stream.FileBinaryGzip).%New() do s.LinkToFile("1.xml.gz") do $System.OBJ.LoadStream(s) kill s

Don't you think that naming the file "1.xml.gz" would be more clear?

Dot would be unrequired and even misleading here.

Thanks, Sean, Ed, Alexey!

That works perfectly! Ed, please add a dot to s in ExportToStream?

I'm using it in one line, and think would add in some "Dev.Utils" class to make it shorter.

 

kill ^dbg

BTW, kill ^dbg is not mandatory here, cause import from XML format everytime kills the global first.