Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
May 13, 2021 7:41:01 AM
May 3, 2021 10:48:25 AM
Today, I'd like to share with you our current App backup solution using Powershell and Qlik-Cli.
As you know, a production environment needs backups and Qlik Sense Enterprise does not offer such a thing by default so I decided to build a solution.
Using Qlik-Cli for Windows, I put in place a solution that will not only backup my published and unpublished apps but will also create a folder structure to match your streams.
The unpublished apps are backed up inside the "My Work" folder using the app owner's name as a directory name. This allows to easily find the app owner when performing a search in the folders.
Square brackets in the App's name will be removed because you cannot create a file with these characters in Windows.
The script is scheduled using the Windows Task Scheduler with the following command:
Here's the code:
$ErrorActionPreference = "Stop"
Try
{
# set export drive and directory
D:
cd D:\QlikBackups
# connect to the Qlik Server. Replace <ServerName> with your Qlik Sense hostname
Connect-Qlik -ComputerName <ServerName> -UseDefaultCredentials -TrustAllCerts
# Export each apps from the previously defined streams to qvf
Get-QlikStream | % {New-Item -Name ".\$($_.name)" -Force -ItemType 'Directory'} | foreach {Get-QlikApp -filter "stream.name eq '$($_.name)'"} | foreach {Export-QlikApp -skipdata -id $_.id -filename "$($_.stream.name)\$($_.name -replace '[[\]]','').qvf"}
# set the export folder to the My Work area for unpublished apps
cd "D:\QlikBackups\My Work"
# Create a folder structure for all the app owners
Get-QlikApp -full -filter "published eq False" | % {New-Item -Name ".\$($_.owner.userId)" -Force -ItemType 'Directory'}
# Export each app into their folder
Get-QlikApp -full -filter "published eq False" | foreach {Export-QlikApp -skipdata -id $_.id -filename "$($_.owner.userId)\$($_.name -replace '[[\]]','').qvf"}
}
Catch # In case of error, send an email to the Qlik administrators
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
$Time=Get-Date
"Error: $FailedItem Message: $ErrorMessage Time: $Time" | out-file d:\log\QlikBackup.log -append
$FailMailParams = @{
To = 'qlikadmin@MyCompany.com'
From = 'MyQlikServer@MyCompany.com'
Port = '25'
SmtpServer = 'smtprelay.MyCompany.com'
Subject = 'MyQlikServer Backup Failure'
Body = "The backup failed. The error message was: $ErrorMessage"
}
Send-MailMessage @FailMailParams
}
My next steps are:
@richnwide I'm not sure exactly when it was made available. Can you provide the error message?
Are you sure you are using this CLI call here? https://ahaydon.github.io/Qlik-Cli-Windows/Export-QlikApp.html
Hello,
This is the code I'm trying to run:
Export-QlikApp -id $_.id -filename "Deployments\$($_.stream.name)\$($_.name).qvf" -SkipData
And this is the error I get:
Export-QlikApp : A parameter cannot be found that matches parameter name 'SkipData'.
Any ideas?
Thanks
@richnwide Are you sure your stream of file names are not causing any issues? In my script I had to replace some characters as they were breaking the export, hence the usage of
-replace '[[\]]',''
Does it fail for all of your apps or a specific one?
I looked into the powershell script installed on my server and I found the SkipData flag. Can you confirm on your end?
C:\Program Files\WindowsPowerShell\Modules\Qlik-Cli
Thanks for responding @MichelLalancette .
The script works perfectly without the parameter, but adding it causes the error.
Apologies for my ignorance, but where would I find the screenshot of the Export-QlikApp code you've shared? I can't find it anywhere
Thanks again
@richnwide My app is installed in the following folder:
C:\Program Files\WindowsPowerShell\Modules\Qlik-Cli
Inside there should be a PowerShell file Qlik-Cli.psm1. Edit it and search for the keyword Skipdata
You can always search for the Qlik-Cli folder on your machine.
Hi @MichelLalancette ,
This helped me a lot, I was able to export all unpublished apps. Now I am setting up a development environment, and I need to import these apps to this new environment. In this case, how do I import the applications for each user in their respective work areas?
Regards
Hi @MichelLalancette , @joseph_morales ,
I know this is an old subject. But do you have the answer to joseph_morales' question?
How do you re-import applications by stream or by workspace?
Thank you in advance for your help.
Hi @Jean-Paul I'm sorry but I was never able to reproduce Joseph's question sadly.
We've also since moved to qlik cloud and I no longer have an on-prem tenant to test the scripts.
Connect-Qlik -ComputerName <ServerName> -UseDefaultCredentials -TrustAllCerts
The above command is returning HTML code for the login page of QlikHUB. It worked fine before.
Don't know what changed. Please let me know what could be the possible issue here.