This topic provides example commands and scripts to help you perform backups of your server for several typical backup scenarios. These examples presume you are using PostgreSQL, which LabKey Server uses by default. They can be customized to your needs.

In the each example,
  • backupFile is the file in which the backup is stored.
  • dbName is the name of the database for the LabKey Server. This is normally labkey
If you are using our recommended installation folder structure, you'll have these two locations, referred to generally by variable names and using forward slashes in our documentation. <LABKEY_HOME> is the same as <LK_ROOT>/labkey.
VariableLinux defaultWindows default
<LK_ROOT>/labkeyC:\labkey
<LABKEY_HOME>/labkey/labkeyC:\labkey\labkey

The <LK_ROOT>/backupArchive directory is a safe place to store your own backups. Do NOT use <LABKEY_HOME>/backup as it will be overwritten by the LabKey jar.

Perform a Full Backup of the PostgreSQL Database

The following command will perform a full backup of the database named dbname and store it in the file backupFile.

Linux:

pg_dump --compress=5 --format=c -f backupFile dbName

Windows: (substitute your local path to pg_dump.exe)

C:/Program Files/PostgreSQL/bin/pg_dump.exe --compress=5 --format=c -f backupFile dbName

Perform a Full Backup on a Linux Server, where the PostgreSQL Database is Being Run as the PostgreSQL User

Use this command to store the backup of the 'labkey' database in <LK_ROOT>/backupArchive.

su - postgres -c '/usr/bin/pg_dump --compress=5 --format=c -f /labkey/backupArchive/labkey_database_backup.bak labkey'

Perform a Full Backup of your PostgreSQL Database and All Files Stored in Site-level File Root

Learn more about the site level file root in this topic: File Terminology

The sample Perl script lkDataBackup.pl works on a Linux Server, but can be easily changed to work on other operating systems.

You can customize the script to fit your LabKey installation by changing the variables at the top of the file. To customize the script, you can change the variables:

  • $labkeyHome: this is the directory where have installed LabKey. Referred to as <LABKEY_HOME> and the same as <LK_ROOT>/labkey.
  • $labkeyFiles: this is the site-level file root. By default this is located in <LABKEY_HOME>/files
  • $labkeyBackupDir: the directory where the backup files will be stored. We suggest using <LK_ROOT>/backupArchive. Do NOT use <LABKEY_HOME>/backup as it will be overwritten by the LabKey jar.
  • $labkeyDbName: the name of the LabKey database. By default this is named labkey.
The script assumes:
  • You have perl installed on your server
  • You are using the PostgreSQL database and it is installed on the same computer as the LabKey server.
  • PostgreSQL binaries are installed are on the path.
  • See the script for more information
Error and status messages for the script are written to the log file data_backup.log. It will be located in the $labkeyBackupDir you provide.

Example Backup Script for Windows

Modify this example as needed to suit your versions and environment:

  • Example backup script for Windows
    • Edit to set BACKUP_DIR to your backup location, such as "C:\labkey\backupArchive\database". The script assumes this location already exists.
    • Set your POSTGRES_HOME and user details.
    • You may also need to modify other files (such as PGPASS.conf) to provide the necessary access.
This example performs two backups: one for the LabKey database, and one for the default postgres database. This default postgres DB backup is not always necessary, but is included in the script.
  • Note that this script does not back up the file root. You will need to back that up separately.

Related Topics

Was this content helpful?

Log in or register an account to provide feedback


previousnext
 
expand allcollapse all