ApexSQL Backup CLI examples

The ApexSQL Backup Command Line Interface (CLI) supports full backup, restore, and transaction log functionality right from the command line. Beside scheduled jobs CLI supports direct backup, restore, and transaction log execution.

CLI switches are split into five different categories:

  1. Backup CLI switches
  2. Restore CLI switches
  3. Transaction Log CLI switches
  4. Scheduler CLI switches
  5. Monitoring or print switches

To illustrate CLI usage each command line switch will be covered with a simple example.

Database Backup through CLI

Execute a database backup with direct execution

Comparing with the Windows GUI, direct execution is selected via the “Execute command immediately” radio button option:

Command line example:

apexsqlbackup.com /cmd: backup /server: APEXSQLSERVER_2 /databases: test

The command line example contains several different parts:

apexsqlbackup.com – the ApexSQL Backup Console line CLI application, command line tool which executes the command line options.

/cmd – the main switch that defines which command will be executed by the apexsqlbackup.com application. Possible options are: backup, restore, tlog (transaction log), and print.
/server – the source SQL Server instance name
/database – the database name

If a destination argument is omitted a default backup location will be used by the apexsqlbackup.com application.

If the backup type switch /bt is omitted, a Full Backup type is a default one.

The below screen shot presents the CLI backup execution result in comparison vs the Windows GUI:

Execute scheduled database backup job

Compared with the Windows GUI, scheduled execution is selected via the Schedule radio button:

CLI example:

apexsqlbackup.com /cmd: backup /server: APEXSQLSERVER_2 /databases: test /scheduler: daily every: 1 onceat hh: 5 mm: 10 ss: 00

This command line contains a same structure as the previous command line related to a direct backup CLI execution, except it contains one additional switch called /scheduler. With the /scheduler switch all backup CLI commands are treated as scheduled SQL Server Agent jobs, not directly executed by apexsqlbackup.com application.

The screenshot below shows the CLI backup execution result in comparison vs the Windows GUI:

The ApexSQL Backup CLI supports all the same types of scheduler options as does the Windows GUI. The scheduler command line switch arguments are the same no matter is it related to backup, restore or transaction log command.

Examples:

ONCE:

/scheduler: once dd: 21 mm: 4 yyyy: 2015 hh: 5 mm: 10 ss: 00
Description: “Occurs on 4/21/2015 at 5:10:00 AM.”

DAILY:

/scheduler: daily every: 1 onceat hh: 5 mm: 10 ss: 00
Description: “Occurs every 1 day(s) at 5:10:00 AM. Schedule will be used starting on 4/23/2015.”

/scheduler: daily every:1 every hh:8 mm:22 shh:5 smm:20 sss:54 ehh:8 emm:8 ess:10
Description: “Occurs every 1 day(s) every 8 hour(s) 22 minute(s) between 5:20:54 AM and 8:08:10 AM. Schedule will be used starting on 4/23/2015.”

WEEKLY:

/scheduler: weekly every:2 wd: mon,tue,wed,thu,fri,sat,sun onceat hh:5 mm:10 ss:00
Description: “Occurs every 2 week(s) on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday at 5:10:00 AM. Schedule will be used starting on 4/23/2015.”

/scheduler: weekly every:1 wd:monday,tuesday,sunday onceat hh:5 mm:10 ss:00
Description: “Occurs every 1 week(s) on Monday, Tuesday, Sunday at 5:10:00 AM. Schedule will be used starting on 4/23/2015.”

MONTHLY:

/scheduler: monthly every: 2 onday: 3 onceat hh: 5 mm: 10 ss: 00
Destination: “Occurs every 2 month(s) on day 3 of that month at 5:10:00 AM. Schedule will be used starting on 4/23/2015.”

/scheduler: monthly every:2 on:first,monday onceat hh:5 mm:10 ss:00
Description: “Occurs every first Monday of every 2 month(s) at 5:10:00 AM. Schedule will be used starting on 4/23/2015.”

Database Restore through CLI

The ApexSQL Backup Console application supports direct and scheduled restore job execution. Here are the restore command line with base options.

Command line example:

apexsqlbackupe.com /cmd: restore /server: APEXSQLSERVER_3 /databases: test_restored /sbf:
d:\SQLServerInstances\MSSQL12.APEXSQLSERVER_3\MSSQL\Backup\ test-Fulldatabasebackup201504231638.bak

The command line example contain several different parts:

/cmd – specifies restore to be executed by the apexsqlbackup.com application.
/server – a destination SQL Server instance.
/databases – a target database name.
/sbf – specifies specific database file location.

The screenshot below shows the CLI restore execution result vs the GUI:

Database Transaction Log through CLI

The ApexSQL Backup Console application supports all the relevant options as the GUI:

Below is an example related to the CLI transaction log command in order to present how a transaction log backup could be done from the CLI:

apexsqlbackup.com /cmd: tlog /tlogsource: s:APEXSQLSERVER_3 db:testing_db nl:\\VLADA-PC\SharedFolder /tlogdests: s:APEXSQLSERVER_2 db:testing_db_tlog rc:norecovery fo:d:\SharedFolder dc:true /initdest:

Beside the /cmd switch set to tlog (transaction log) the command above contains two main switches relevant for a transaction log execution: /tlogsource and /tlogdests.

The screen shot example below shows CLI transaction execution results in comparison vs Windows GUI:

Monitoring through CLI

The ApexSQL Backup Console application also supports monitoring of alerts and jobs. Here are the CLI command examples for alerts and jobs monitoring:

apexsqlbackup.com /cmd: print alerts
apexsqlbackup.com /cmd: print jobs

These examples are only a part of ApexSQL Backup CLI support. TheCLI supports all backup, restore, and transaction log options available in the Windows GUI.