Best Practices - Leapwork database backup for Trial & Platform version

Best Practices - Leapwork database backup for Trial & Platform version

Introduction

The backup and restore feature is an essential safeguard for protecting critical data stored in our Leapwork databases. To minimize the risk of catastrophic data loss and to preserve data configurations, we should perform a backup of our databases on a regular basis. A well-planned backup and restoration strategy for our databases can provide timely protection against the unforeseen:

Cloud data storage solutions minimize the loss of data when compared to natural disasters affecting on-premise data. Additionally, database backups are useful for performing several routine administrative tasks, such as database migration, mirroring, and archiving.

What Data Should I Backup?

The Leapwork Controller holds all data, such as flows, sub-flows, images, schedules, and locators, etc., in the form of multiple .sqlite database files. The Controller also holds automation runs containing test flow execution artifacts, similar to automation run video and screenshots. If we have sufficient disk space, it is recommended that we create a backup of everything under the assets folder, including AutomationRunMedia.
Note: A backup of all .sqlite files is mandatory.

Backup Procedure

You can manually or automatically initiate the backup process using a PowerShell script.

Preconditions

Manual Backup

To perform a manual backup:

The Leapwork data backup is now complete.

Script-based Backup

The script-based backup automatically performs the same process as the manual backup process. The following is an example of the script-based backup in PowerShell script:

##############################################################################################################
# Leapwork DATA BACKUP SCRIPT
##############################################################################################################

# Variables to be altered by user
# $assetsFolderPath- This is path to Assets folder in Controller machine- Change only if you custom path
# $backupPath- This is safe location where user should keep backup of Assets(Could be UNC/network path)
##############################################################################################################

Write-Host "Backup Process Started"
Write-Host "Step1: Stopping LEAPWORK Controller Service.."

$ServiceName = "LEAPWORK Controller"
Stop-Service $ServiceName

Write-Host "Step2: Check Controller Service State.."
do
{
    Start-Sleep -Seconds 2
    Write-Host "Getting the service status.."
    $ServiceStatus = (Get-Service -Name $ServiceName).Status
    Write-Host $ServiceName "-" $ServiceStatus
}
while ($ServiceStatus -ne 'Stopped')

Write-Host "Step3: Taking Backup.."
$assetsFolderPath = "C:\Program Files\LEAPWORK\Assets" #Path to Assets folder in Controller Machine
$dateTimeOfBackup= Get-Date -format "dd-MMM-yyyy-HH-mm-ss" #Date time to be added in the folder name to identify daily backup
$backupPath = "D:\Backup-$dateTimeOfBackup" #Path of safe location to backup Assets, it can be UNC/network path
Copy-Item -Path $assetsFolderPath -Recurse -Destination $backupPath

Write-Host "Step4: Backup Finished.."

Write-Host "Step5: Starting LEAPWORK Controller.."
Start-Service "LEAPWORK Controller"

Write-Host "Backup Finished !!"

##############################################################################################################

On a Controller machine, we can create a schedule using the Windows task scheduler to run the previously supplied PowerShell script, for creating a backup during a defined interval of time.

Restore Database

The restore process copies data from a backup by converting the backup file into a database. Perform the following steps to restore our Leapwork databases.

After performing the previous steps, open Leapwork studio and verify that the data is present. You can also automate this process by creating a restore PowerShell script.

Note: It is suggested that we test our strategy by backing up and restoring databases, to better prepare us for any unforeseen disaster situations.

How often should I perform a backup?

The frequency in performing backups depends on how often automation flows and data changes.