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
anderseriksson
Partner - Specialist
Partner - Specialist

Backing up the Qlik Sense share folder and the repository database you have all the data you need without running any scripts.
Add to that backing up any local file system storage used by your applications and you should be good.
Backup should always be done on storage off the server in case the server is toast.

0 Likes
MichelLalancette

@anderseriksson  Sure you could backup

%ProgramData%\Qlik\Sense\Apps, but that's not quite as convenient if you do need to restore since it's only the AppId that's visible. What if someone deletes the app and you don't know what AppId file to restore?

This method is not intended to be a replacement for Qlik full backups or VM backups and is intended to recover accidental app deletes/changes without the need to implement full source control. In our case, the entire VM is backed up and all our data is offloaded to an external server (outside the data center).

This is obviously intended for on-premise usage as I'm not familiar with how SaaS apps are handled.

0 Likes
anderseriksson
Partner - Specialist
Partner - Specialist

That's why you should also have the Repository database, there is the name and owner of every application.
Ordinary a user can only delete applications in the hubs workarea.
Administrators in QMC depends on what privileges you give them.

0 Likes
MichelLalancette

It could just be that the app has not been published ever and has been sitting in the user's "My Work" for a while and he accidentally deletes it.

But even administrators can accidentally delete content and having the app file with a proper name without the need to consult a repo database makes restoring content much faster in case of mishaps.

Don't get me wrong, you still need proper backups for your whole server and there are multiple ways to backup the content. This is just one of them.

0 Likes
didierodayo
Partner - Creator III
Partner - Creator III

Ok I found my issue I had to adjust the custom property for the stream filter

 

 

Get-QlikStream -filter "customProperties.definition.name eq 'MyStreamCustompropertyname' 

 

MichelLalancette

@didierodayo  Glad you were able to get it working.

0 Likes
benoithervochon
Partner - Contributor III
Partner - Contributor III

@MichelLalancette A lot of good ideas !

How to change/manage rights on folders/apps after exporting using poweshell script ? (done it with external program tasks in qmc 🙂 )

With some tuning, i get a date folder and a sub folder for each stream and apps i want to backup/export with no data - very fast execution 🙂 (filtered using tags) 

0 Likes
MichelLalancette

@benoithervochon  I'm curious what is the purpose of changing/managing rights on the folders after export? I'm asking because our backup folder already has limited access.

 

I'm glad you were able to get it to work and tweaked it to your liking.

benoithervochon
Partner - Contributor III
Partner - Contributor III

@MichelLalancette , found solution by setting my backup folder to another location 🙂

Thx a lot

0 Likes
richnwide
Contributor
Contributor

Hi,

I've tried the Export-QlikApp with the -skipdata , but this parameter isn't recognised. Is there a versioning aspect to using this?

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