Automating Application Back up

NidhiMangtani
Contributor III

Hi All,

Is there any utility rule available which helps to take backup of all the components of the application? This can then be scheduled to take daily/weekly application back ups. 

Any leads would be appreciated.

 

Thanks,
Nidhi Mangtani
1 ACCEPTED SOLUTION

PeterFu
Contributor II

Hi Bharti,

 

Here is an Extensibility rule to extract the application (the same as Application zip file option).

 

Imports System
Imports System.Data
Imports System.Data.Common
Imports System.IO
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Linq
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports OneStream.Shared.Common
Imports OneStream.Shared.Wcf
Imports OneStream.Shared.Engine
Imports OneStream.Shared.Database
Imports OneStream.Stage.Engine
Imports OneStream.Stage.Database
Imports OneStream.Finance.Engine
Imports OneStream.Finance.Database

Namespace OneStream.BusinessRule.Extender.XFR_ExportAppMetadata
Public Class MainClass
'------------------------------------------------------------------------------------------------------------
'Reference Code: XFR_ExportAppMetadata
'
'Description: Extender buiness rule that all application metadata to a zip file for the current application.
' The files are written to the application Data Mgmt Export folder in the file share directory.
'
'Usage: Can be executed from Business Rule editor or run as part of a Data Management sequence.
'
'Created By: Inlumi - Peter Fu
'Date Created: 7-2-2022
'------------------------------------------------------------------------------------------------------------
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object
Try
Select Case args.FunctionType
Case Is = ExtenderFunctionType.Unknown, ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep
'Prepare the Stage Data Extract File path
Dim configSettings as AppServerConfigSettings = AppServerConfig.GetSettings(si)
Dim folderPath as String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder, si.AppToken.AppName) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\MetadataExtracts"
if Not Directory.Exists(folderPath) then Directory.CreateDirectory(folderPath)
Dim filePath as String = folderPath & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & " " & si.AppToken.AppName & ".zip"
If File.Exists(filePath) Then File.Delete(filePath)

'Set the extract options
Dim xmlOptions as New XmlExtractOptions
xmlOptions.ExtractAllItems = True

'Execute the Metadata Extract
Using dbConnFW as DBConnInfo = BRAPi.Database.CreateFrameworkDbConnInfo(si)
Using dbConnApp as DBConnInfo = BRAPi.Database.CreateApplicationDbConnInfo(si)
Dim zipBytes as Byte() = ApplicationZipFileHelper.Extract(dbConnFW, dbConnApp, Nothing, xmlOptions)
'Append the contents of this workflow profile to the extract file
Using FS As New FileStream(filePath, FileMode.Append, FileAccess.Write)
'Create a binary writer, and write all bytes to the FileStream at once
Using BW As New BinaryWriter(FS)
BW.Write(zipBytes)
End Using
End Using
End Using
End Using

End Select

Return Nothing
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Function
End Class
End Namespace

 

Peter

View solution in original post

8 REPLIES 8

PeterFu
Contributor II

Hi Bharti,

 

Here is an Extensibility rule to extract the application (the same as Application zip file option).

 

Imports System
Imports System.Data
Imports System.Data.Common
Imports System.IO
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Linq
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports OneStream.Shared.Common
Imports OneStream.Shared.Wcf
Imports OneStream.Shared.Engine
Imports OneStream.Shared.Database
Imports OneStream.Stage.Engine
Imports OneStream.Stage.Database
Imports OneStream.Finance.Engine
Imports OneStream.Finance.Database

Namespace OneStream.BusinessRule.Extender.XFR_ExportAppMetadata
Public Class MainClass
'------------------------------------------------------------------------------------------------------------
'Reference Code: XFR_ExportAppMetadata
'
'Description: Extender buiness rule that all application metadata to a zip file for the current application.
' The files are written to the application Data Mgmt Export folder in the file share directory.
'
'Usage: Can be executed from Business Rule editor or run as part of a Data Management sequence.
'
'Created By: Inlumi - Peter Fu
'Date Created: 7-2-2022
'------------------------------------------------------------------------------------------------------------
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object
Try
Select Case args.FunctionType
Case Is = ExtenderFunctionType.Unknown, ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep
'Prepare the Stage Data Extract File path
Dim configSettings as AppServerConfigSettings = AppServerConfig.GetSettings(si)
Dim folderPath as String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder, si.AppToken.AppName) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\MetadataExtracts"
if Not Directory.Exists(folderPath) then Directory.CreateDirectory(folderPath)
Dim filePath as String = folderPath & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & " " & si.AppToken.AppName & ".zip"
If File.Exists(filePath) Then File.Delete(filePath)

'Set the extract options
Dim xmlOptions as New XmlExtractOptions
xmlOptions.ExtractAllItems = True

'Execute the Metadata Extract
Using dbConnFW as DBConnInfo = BRAPi.Database.CreateFrameworkDbConnInfo(si)
Using dbConnApp as DBConnInfo = BRAPi.Database.CreateApplicationDbConnInfo(si)
Dim zipBytes as Byte() = ApplicationZipFileHelper.Extract(dbConnFW, dbConnApp, Nothing, xmlOptions)
'Append the contents of this workflow profile to the extract file
Using FS As New FileStream(filePath, FileMode.Append, FileAccess.Write)
'Create a binary writer, and write all bytes to the FileStream at once
Using BW As New BinaryWriter(FS)
BW.Write(zipBytes)
End Using
End Using
End Using
End Using

End Select

Return Nothing
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Function
End Class
End Namespace

 

Peter

Hi Peter,

This rule works, I am not able to understand the exported content though. 

When we take a manual backup of the application, we can see the XMLs individually as shown below:

BhartiParyani_0-1655130844086.png

The export from this rule is a .zip.xml file which is taking longer to open and on opening I see some encrypted text. Just want to ensure that .zip.xml can be used to restore application if needed. Would you please explain how to read this .zip.xml file?

 

 

Thanks,
Nidhi Mangtani

Ok, I somehow managed to save the extract as a zip folder, then it shows 8 XMLs internally. The manual backup has 16 XMLs.

BhartiParyani_1-1655131553721.png

Can we mitigate this difference somehow?

Thanks,
Nidhi Mangtani

Hi,

 

Maybe you used the wrong button to download. See print screens

 

PeterFu_0-1655131835227.png

 

 

PeterFu_1-1655131871183.png

Peter

I do not think it is normal. Did you let it finish the backup? It can take some time...
Can you add a line with a brapi log message just before the Return Nothing.
And before extracting, check your log to see if it is Done

NicolasArgente_0-1655132421631.png

 

 

Connect with me on:
LinkedIn: https://www.linkedin.com/in/nicolas-argente/
Website: https://aiqos.io
If you want to lift yourself up, lift up someone else.

I see 13 XMLs now. On downloading, the application goes to not responding state and leaves me with incomplete download I guess, may be some network issue or application backup size is huge. I will try in a different application, this works. Thanks for all the help.

Thanks,
Nidhi Mangtani

Right - when you do a full application extract, it needs sufficient system resources on server side due to its size. Always check no other system/application job is running or add dedicate server for such tasks if you are planning to automate using Data management and Task scheduler. 

NicolasArgente
Valued Contributor

To add up to what Peter Provided, you would use this extensibility rule and link it to a data management job. Then your task scheduler would call the data management job on daily/weekly/hourly basis... and job done 🙂

Connect with me on:
LinkedIn: https://www.linkedin.com/in/nicolas-argente/
Website: https://aiqos.io
If you want to lift yourself up, lift up someone else.