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.