1. Home
  2. Docs
  3. Job Settings
  4. Backup Job
  5. Scripts
  6. SQL Scripts

SQL Scripts

The SQL scripts specified in the backup job settings are executed in the DBMS (Database Management System) specified in the connection settings of that backup job.

Two variables will be available in the script:

  • @SQL_BACKUP_TYPE — This variable contains a string with the backup type code, for example DIFF for Differential SQL Server backups.
  • @SQLBAK_JOB_SUCCESS — This variable contains a flag (1or 0) indicating whether the backup job was completed successfully or with errors. This variable is only available to scripts that are run at the end of the job.

By default, the script executes in the context of the default database. To change the context to a different database, you can use the standard SQL command USE [db_name]

For PostgreSQL, the connection is made to the default database postgres. However, since PostgreSQL does not support changing the database context within a single connection to the database, a special syntactic sugar is provided: --@psql /c postgres;. Instead of the postgres database, you can specify a custom database.

For example, with SQL Server, you can add the execution of the DBCC CHECKDB operation before creating a backup to avoid perpetuating errors in the database.