Qlik Community

Qlik Sense Documents

Documents about Qlik Sense.

Announcements
Coming your way, the Qlik Data Revolution Virtual Summit. October 27-29. REGISTER

Automating a Qlik Sense Site backup

Partner
Partner

Automating a Qlik Sense Site backup

I recently had to back up a site and found that the documentation supplied for doing this did not fully meet my requirements, especially when it came to the step where it asks for the PostgreSQL superuser password.

To overcome this I did the following:

In C:\Program Files\Qlik\Sense\Repository\PostgreSQL\9.3\share\ I made sure that there was a file named pg_hba.conf with a at least the following fields:

# TYPE    DATABASE    USER    ADDRESS    METHOD

local          all                    all                              trust

Then you should create a file in C:\Program Files\Qlik\Sense\Repository\PostgreSQL\9.3\bin\ called pgpass.conf with the following contents:

localhost:4432:QSR:your_service_account:postgresql_superuser_password

where the last two fields are your service account username and postgresql superuser password. These fields are separated by a colon.

I then created a Powershell script to backup all the relevant data:

$PostGreSQLLocation = "C:\Program Files\Qlik\Sense\Repository\PostgreSQL\9.3\bin"

$PostGresBackupTarget = "\\some_shared_backup_location"

$SenseProgramFiles = "C:\Program Files\Qlik\Sense"

$SenseProgramData = "C:\ProgramData\Qlik\Sense"

$Today = Get-Date -UFormat "%Y%m%d_%H%M"

$StartTime = Get-Date -UFormat "%Y%m%d_%H%M"

md $PostGresBackupTarget\$StartTime\Log

md $PostGresBackupTarget\$StartTime\Apps

md $PostGresBackupTarget\$StartTime\Repository\Content

md $PostGresBackupTarget\$StartTime\Repository\Extensions

write-host "Folders Created..."

& 'C:\Program Files\Qlik\Sense\Repository\PostgreSQL\9.3\bin\pg_dump.exe' --host localhost --port 4432 --username "postgres" --no-password  --format tar --blobs --verbose --file "$PostGresBackupTarget\$StartTime\QSR_backup_$Today.tar" QSR

write-host "PostgreSQL database backed up..."

copy $SenseProgramData\Log\*.* $PostGresBackupTarget\$StartTime\Log

copy $SenseProgramData\Apps\*.* $PostGresBackupTarget\$StartTime\Apps

copy $SenseProgramData\Repository\Content\*.* $PostGresBackupTarget\$StartTime\Repository\Content

copy $SenseProgramData\Repository\Extensions\*.* $PostGresBackupTarget\$StartTime\Repository\Extensions

write-host "Data Copied..."

$EndTime = Get-Date -UFormat "%Y%m%d_%H%M%S"

write-host "This backup process started at " $StartTime " and ended at " $EndTime

#pause

You can add steps to stop and then start the relevant service by using the stop-service and start-service commands, or even the stop-process and start-process commands, in Powershell.

Comments
Contributor
Contributor

I applied some changes too ; only the last 7 backups are kept

$SenseProgramData = "D:\QlikShared\"

$PostGreSQLLocation = "C:\Program Files\Qlik\Sense\Repository\PostgreSQL\9.6\bin"

$WeekDay = (get-date).DayOfWeek

$BackupTarget = "D:\QlikShared_Backups\$WeekDay"

if (!(Test-Path $BackupTarget)) { md $BackupTarget }

 

$StartTime = Get-Date –f "dd-MM-yyyy HH:mm"

write-host "Backing up PostgreSQL Repository Database ...."cd $PostGreSQLLocation

.\pg_dump.exe --host=localhost --port=4432 --username=postgres --no-password --format=tar --blobs --file="$BackupTarget\QSR_backup.tar" QSR

write-host "PostgreSQL backup Completed"

write-host "Backing up Shared Persistance Data from $SenseProgramData ...."Copy-Item  $SenseProgramData -Destination $BackupTarget -Recurse -Force

write-host "File Backup Completed"

$EndTime = Get-Date –f "dd-MM-yyyy HH:mm"

write-host "This backup process started at " $StartTime " and ended at " $EndTime

Automating a Qlik Sense Site backup

Specialist III
Specialist III

Hi Oliver,

Can you please help me to understand, in your above code which statement removes backup file before 7 days ?

Thanks,
Rohit

0 Likes
Specialist III
Specialist III

Hi Oliver,

When I am executing following command below message is displaying:

CMD.PNG

Can you please add your input

Thanks,

Rohit

0 Likes
Partner
Partner

Great Article driesman

I have added small addition which could be useful for others

1) Zipping the Folder and removing the uncompressed version(Compression command can change according to PowerShell Version you are using)

2)Deleting Backups older than 7 days.

$PostGreSQLLocation = "C:\Program Files\Qlik\Sense\Repository\PostgreSQL\9.6\bin"


$PostGresBackupTarget = "D:\QlikSense_Backup"


$SenseProgramFiles = "C:\Program Files\Qlik\Sense"


$SenseProgramData = "C:\ProgramData\Qlik\Sense"


$SenseSharedFolder = "C:\Qlik Share"


$Today = Get-Date -UFormat "%Y%m%d_%H%M"


$StartTime = Get-Date -UFormat "%Y%m%d_%H%M"




write-host "Stopping Qlik Services ...."


stop-service QlikSenseProxyService -WarningAction SilentlyContinue


stop-service QlikSenseEngineService -WarningAction SilentlyContinue


stop-service QlikSenseSchedulerService -WarningAction SilentlyContinue


stop-service QlikSensePrintingService -WarningAction SilentlyContinue


stop-service QlikSenseServiceDispatcher -WarningAction SilentlyContinue


stop-service QlikSenseRepositoryService -WarningAction SilentlyContinue



md $PostGresBackupTarget\$StartTime\Log


md $PostGresBackupTarget\$StartTime\Apps


md $PostGresBackupTarget\$StartTime\StaticContent\Content


md $PostGresBackupTarget\$StartTime\StaticContent\Extensions


md $PostGresBackupTarget\$StartTime\StaticContent\AppContent



write-host "Folders Created..."



& 'C:\Program Files\Qlik\Sense\Repository\PostgreSQL\9.6\bin\pg_dump.exe' --host localhost --port 4432 --username "postgres" --no-password  --format tar --blobs --verbose --file "$PostGresBackupTarget\$StartTime\QSR_backup_$Today.tar" QSR



write-host "PostgreSQL database backed up..."




copy $SenseProgramData\Log\*.* $PostGresBackupTarget\$StartTime\Log


copy $SenseSharedFolder\Apps\*.* $PostGresBackupTarget\$StartTime\Apps


copy $SenseSharedFolder\StaticContent\Content $PostGresBackupTarget\$StartTime\StaticContent -Recurse -Force


copy $SenseSharedFolder\StaticContent\Extensions $PostGresBackupTarget\$StartTime\StaticContent -Recurse -Force


copy $SenseSharedFolder\StaticContent\AppContent $PostGresBackupTarget\$StartTime\StaticContent -Recurse -Force


write-host "Data Copied..."




write-host "Restarting Qlik Services ...."



start-service QlikSenseRepositoryService -WarningAction SilentlyContinue


start-service QlikSenseEngineService -WarningAction SilentlyContinue


start-service QlikSenseSchedulerService -WarningAction SilentlyContinue


start-service QlikSensePrintingService -WarningAction SilentlyContinue


start-service QlikSenseServiceDispatcher -WarningAction SilentlyContinue


start-service QlikSenseProxyService -WarningAction SilentlyContinue




Write-host "Compressing Folder and removing the Uncomressed Version"


$source = "$PostGresBackupTarget\$StartTime"

$Zipped = "$PostGresBackupTarget\$StartTime.zip"


Add-Type -assembly "system.io.compression.filesystem"

[io.compression.zipfile]::CreateFromDirectory($source,$Zipped )


Remove-Item $PostGresBackupTarget\$StartTime -Recurse  




Write-Host "Removing Folder older than 7 Days"


Get-ChildItem –Path  $PostGresBackupTarget –Recurse |

Sort-Object LastWriteTime -Descending |

Select-Object -Skip 7 |

Remove-Item -Force -Recurse



$EndTime = Get-Date -UFormat "%Y%m%d_%H%M%S"


write-host "This backup process started at " $StartTime " and ended at " $EndTime



#pause

0 Likes
Partner
Partner

Hello Community,

I was reading the comment where a user adds service restart. It is mandatory the restart of services for QlikSense to do the backup?

0 Likes
Partner
Partner

Hey @driesman 

Can you provide documentation for this

0 Likes
Version history
Revision #:
1 of 1
Last update:
‎2016-07-08 02:19 AM
Updated by: