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 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

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

su - postgres -c '/usr/bin/pg_dump --compress=5 --format=c -f /labkey/backups/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 easily 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 the LabKey binaries. Normally /usr/local/labkey
  • $labkeyFiles: this is the site-level file root. By default this located in the files subdirectory of $labkeyHome
  • $labkeyBackupDir: the directory where the backup files will be stored
  • $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 backup directory.

Example Backup Script for Windows

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

Note that 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.

Related Topics

Was this content helpful?

Log in or register an account to provide feedback


previousnext
 
expand allcollapse all