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 restoral strategy for our databases can provide timely protection against the unforeseen:
- Media failures
- User errors
- Hardware failures
- Natural disasters
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.
What is the backup procedure?
You can manually or automatically initiate the backup process using a PowerShell script.
Precondition
- It is recommended that we create a backup of our Leapwork database encryption key. The following article, How to migrate Leapwork Controller from one machine to other, explains how to create a database encryption key backup.
- To backup and restore our Leapwork databases, we must remember at least one admin user account password or create a secondary admin user account. Read more about the admin password here.
Manual backup
To perform a manual backup:
- Log in to the Controller machine
- Stop the Leapwork Controller service:
- Press the Win+R key combination to open the Run dialog
- Type services.msc and press OK to open the Services window
- Find the Leapwork Controller and stop it by right-clicking the mouse button, then by clicking Stop.
- Open File Explorer and navigate to the C:\Program Files\LEAPWORK folder
- Copy the Assets folder
- Navigate to our selected backup location
- Paste the Assets folder and wait until the file copy process is completed
- Start the Controller service:
- Press the Win+R key combination to open the Run dialog
- Type services.msc and press OK to open the Services window
- Find the Leapwork Controller and restart it by right-clicking the mouse button, then by clicking Start.
When finished with the previous steps, 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.
What is the Restore procedure?
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:
Steps to Restore a Database
- Navigate to our backup folder location
- Copy the Assets folder from our backup folder
- Log in to the Controller machine
- Stop the Leapwork Controller services
- Press the Win+R key combination to open the Run dialog
- Type services.msc and press OK to open the Services window
- Find the Leapwork Controller and stop it by right-clicking the mouse button, then by clicking Stop.
- Go to C:\Program Files\LEAPWORK folder and replace the existing Assets folder with the backup Assets folder, wait until the file copy has completed
- Start the Leapwork Controller service
- Press Win+R combination to open the Run dialog
- Type services.msc and press OK to open Services window
- Find the Leapwork Controller and restart it by right-clicking the mouse button, then by clicking Start.
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.
- Automation flows and data that changes frequently may be sufficient for hourly or daily backups
- Automation flows and data that changes every few days may be sufficient for performing a weekly or monthly backup
- For some data, a user may run our backup whenever we make a change
If you have any questions, contact our Priority Support.
Comments
0 comments
Please sign in to leave a comment.