Skip to main content

Qlik Sense Documents

Qlik Sense documentation and resources.

Backing up your Qlik Apps into Stream Folders using Qlik-Cli

cancel
Showing results for 
Search instead for 
Did you mean: 
MichelLalancette

Backing up your Qlik Apps into Stream Folders using Qlik-Cli

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:

MichelLalancette_0-1620052751460.png

 

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:

  • Add timestamps to the filename
  • Keep the most recent copy and Archive the rest.
  • Add qvf file retention
Comments
MichelLalancette

@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

0 Likes
richnwide
Contributor
Contributor

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

 

0 Likes
MichelLalancette

@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

MichelLalancette_0-1655905554034.png

 

0 Likes
richnwide
Contributor
Contributor

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

0 Likes
MichelLalancette

@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.

0 Likes
Version history
Last update:
‎2021-05-13 07:41 AM
Updated by:
Contributors