Knowledge Base Article

Extender: Automate Application Metadata Backup

This is an example Extender rule that extracts all application metadata to a zip file, for the current application.
The file is created in the application Data Management Export folder, in the File Share directory.

'Prepare the Stage Data Extract File path
Dim configSettings As AppServerConfigSettings = AppServerConfig.GetSettings(si)

'Folder path to save export
Dim folderPath As String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, _
	True, configSettings.FileShareRootFolder, si.AppToken.AppName) & _
	"\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\MetadataExtracts"

'Check if folder path for export exists
If Not Directory.Exists(folderPath) Then
	Directory.CreateDirectory(folderPath)
end if

Dim filePath As String = folderPath & "\" & si.AppToken.AppName & ".zip"

'Check if file already exists.  If so then delete exsiting copy
If File.Exists(filePath) Then
	File.Delete(filePath)
end if

'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)

		'Push the resulting content to a new zip file we create
		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
Updated 2 years ago
Version 2.0