ApexSQL Backup CLI support

Description
This article explains how to use ApexSQL Backup command line interface (CLI) and create output files.

To start the ApexSQL applications GUI via the command line interface enter the product name. For example apexsqlbackup.exe

The CLI must be started using apexsqlbackup.com

Switches

Format of switches

  • Switches are case insensitive, i.e. /S: = /s:
  • Switches are preceded with one forward slash (/), i.e. /db:pubs
  • Switches are followed with a colon (:), i.e. /dbs:pubs
  • There are two types of switches – abbreviated/alias (1-3 chars) and full – with full name of switch. i.e. /p and /project
  • Default values for omitted parameters are used in most cases. Default values are specified in the following format in /help switch (“<default>” if omitted), i.e. (“(local)” if omitted)
  • Switches can be placed in arbitrary order
  • Switches and parameters are delimited with a white space

The following ApexSQL Backup switches are available:

Command:

/c:arg [ /cmd ]: Command: [Backup | Restore | LogShipping | Policy | Print]

Server options:

/s:arg [ /server ]: SQL Server instance name ((local) if omitted)
/dbs:arg [ /databases ]: Database name

Backup options:

/bt:arg [ /backuptype ]: Backup type: [Full | Differential | Transaction Log]
/bsn:arg [ /name ]: Backupset name (if omitted default destination is used)
/des:arg [ /description ]: Backupset description
/l:arg [ /destinations ]: Backup destination
/m:arg [ /mirror ]: Backup mirror (if omitted mirror is not executed)
/com:arg [ /compression ]: Native compression type Default (if omitted): [Default | Enabled | Disabled]
/ui [ /useinit ]: Initialize media (suppressed by default)
/uf [ /useformat ]: Format media (suppressed by default)
/co [ /copyonly ]: Copy only (suppressed by default)
/rbsd:arg [ /retainbackupsetdays ]: Retain backup sets
/nbs [ /donotcheckbackupset ]: Do not check backup set
/vb [ /verifybackup ]: Verify backup when finished
/pc [ /performchecksum ]: Perform checksum before writing to media
/coe [ /continueonerror ]: Continue on error
/encalg:arg [ /encryptionalghoritm ]: Encryption algorithm: [AES 128 | AES 192 | AES 256 | Triple DES]
/enctyp:arg [ /encryptiontype ]: Encryption type: [Server certificate | Asymmetric key]
/encn:arg [ /encryptionname ]: Encryptor name
/fg:arg [ /filegroups ]: Database filegroups

Backup to Azure options:

/cr:arg [ /credential ]: Credential for connecting to Azure
/url:arg [ /URL ]: Backup destination

Restore options:

/kconn [ /killconn ]: Kill all existing connections
/ow [ /overwrite ]: Overwrite existing database
/sbf:arg [ /specificbackupfiles ]: Specific backup files
/rt:arg [ /restoretype ]: Restore type [LatestFull (Last full backup) | latestfulldiff (Last full and differential backups) | latestfulldifftlog (Last full, differential and transaction log backups)]
/uddf [ /usedefaultdatafolder ]: Use default data folders
/dff:arg [ /datafilesfolder ]: Data files folder
/lff:arg [ /logfilesfolder ]: Log files folder
/fs:arg [ /folderscan ]: Folder scan (Path Filename-pattern subfolders true/false) i.e. C:\Temp Filename_Pattern true

Log shipping options:

/tls:arg [ /tlogsource ]: Log shipping source format: server_name database_name local_folder network_folder backup_name backup_description backup_filename

backup_name (if omitted default value “%Database% – %BackupType% backup” is used)

backup_description (if omitted default value “%BackupType% backup of %Database% on %Date% %Time24h%” is used)

backup_filename (if omitted default value “%Database%_%BackupType%_%Date%_%Time24h%.bak” is used)

/tld:arg [ /tlogdests ]: Log shipping destination format: server_name database_name recovery_model local_folder data_folders
/ides [ /initdest ]: Initialize destinations with full backup (True | False) (enabled if omitted)

Scheduler options:

/sch:arg [ /scheduler ]: Scheduled job (Frequency (Once | Daily | Weekly | Monthly) dd: (day) mm: (month) yyyy: (year) hh: (hour) mm: (minute) ss: (second)) (optional wb: (weekday), on: (on specific day), first: (first specific day in a month) shh: smm: sss: (starting hour, minute, second) ehh: emm: ess: (ending hour, minute, second))
i.e. /scheduler: weekly every:1 wd:monday,tuesday every hh:8 mm:22 shh:5 smm:20 sss:54 ehh:8 emm:8 ess:10
i.e. /scheduler: monthly every:2 on:first,Monday,Wednesday every hh:8 mm:22 shh:5 smm:20 sss:54 ehh:8 emm:8 ess:10
/bsch:arg [ /backupscheduler ]: Log shipping backup scheduled job
/rsch:arg [ /restorescheduler ]: Log shipping restore scheduled job

Deploy policy options:

/pn:arg [ /policyname ]: Deploy backup policy
/pe:arg [ /policyencryptor ]: Deployer policy encryptor (per SQL server instance)
/ps:arg [ /policysource ]: Deploy policy to multiple databases (per SQL server instance)

Notification options (alerting):

/notify:arg [ /notifyevents ]: Notification options: events [failed|success] and email addresses
i.e. /notify: events:failure,success emails:email1@domain1.com,email2@domain2.com

Print options:

/fi:arg [ /filter ]: Filter options: [numeletoprint | lastndays], where numeletoprint = last number of elements to print, lastndays = last N days

Additional options:

/? [ /help ]: Shows CLI help
/af:arg [ /argfile ]: An XML file with options
/cw:arg [ /console_width ]: Specifies the width of console output
/f [ /force ]: Overrides existing file of same name
/out:arg [ /out_to ]: Redirects console output to specified file
/t [ /test ]: Outputs parsed command line switches without taking any actions
/v [ /verbose ]: Prints messages that are suppressed by default
/slt [ /silent ]: Disables all output to console

Special keys

To abort program execution, use Ctrl+C or Ctrl+Break

Examples

The following CLI example creates a backup of DEMO01 database

  • The DEMO01 database is hosted on the SQL Server instance named ZWERKA\SQL2014
  • Full database backup is created
  • Default compression (native) is used
  • Backup is verified on finish
  • Process continues on error
  • Backup is scheduled for: Every week on Monday, Tuesday at 08:22 starting from 00:20:30 ending at 08:08:45

apexsqlbackup.com /s: ZWERKA\SQL2014 /dbs: DEMO01 /c:Backup /bt:Full /com:Default /vb /pc /coe /scheduler: weekly every:1 wd:monday,tuesday every hh:8 mm:22 shh:00 smm:20 sss:30 ehh:8 emm:8 ess:45

The following CLI example creates a differential backup of DEMO02 database

  • The DEMO2 database is hosted on the SQL Server instance named ZWERKA\SQL2012
  • Differential database backup is created
  • Backupset name is %DATABASE% – %BACKUPTYPE%
  • Backupset description is %DATABASE%%TIME12H%
  • Encryption algorithm ‘AES 192’ with encryption type ‘Server certificate’ is used
  • Backup is scheduled for: Every 2 months, on first Monday and first Wednesday on every 8h 30 minutes, starting at 05:20 and ending at 22:45
  • Email notification will be sent in case of event fail on the email address email1@domain1.com

apexsqlbackup.com /s: ZWERKA\SQL2014 /dbs: DEMO02 /c:Backup /bt:Differential /bsn:”%DATABASE% – %BACKUPTYPE%” /des: %DATABASE%%TIME12H% /encalg:AES256 /enctyp:Server /scheduler: monthly every:2 on:first,Monday,Wednesday every hh:4 mm:30 shh:5 smm:20 sss:54 ehh:22 emm:45 /notify:events:failure emails:email1@domain1.com

The following CLI example perform a restore of DEMO03 database

  • The DEMO3 database is hosted on the SQL Server instance named ZWERKA\SQL2008
  • Existing database will be overwritten
  • Any existing connections to the database will be killed
  • Specific backup file C:\Temp\DEMO03-January.bak will be used
  • Database will be restored to the latest full backup in the backup file
  • Default folders are used
  • messages that are suppressed by default will be displayed in the command prompt window

apexsqlbackup.com /s: ZWERKA\SQL2014 /dbs: DEMO01 /c:Restore /ow /kconn /sbf: C:\Temp\DEMO03-January.bak /rt:LatestFull /uddf /v

The following CLI example perform a log shipping of DEMO04 database to DEMO05 database

  • Source database DEMO04 is located on the SQL Server instance named ZWERKA\SQL2014
  • Local folder C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\Backup
  • Network folder C:\Temp
  • Destination database DEMO05 is located on the SQL Server instance named ZWERKA\SQL2012
  • Recovery model is ‘Read-only’
  • Local folder is D:\Temp
  • Default data folders are used (switch is omitted)
  • Disconnect users when restoring
  • Backup will occur once and is scheduled for 05/08/2015 at 05:00
  • Restore will occur once and is scheduled for 05/08/2015 at 05:30

apexsqlbackup.com /c:LogShipping /tls:server:ZWERKA\SQL2014 database:DEMO4 local:C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\Backup netlocation:C:\Temp /tld:server:ZWERKA\SQL2012 /database:DEMO5 recovery:Read-only folder:D:\Temp disconn:True /backupscheduler: once dd:05 mm:08 yyyy:2015 hh:05 mm:00 ss:00 /restorescheduler: once dd:05 mm:08 yyyy:2015 hh:05 mm:30 ss:00

The following CLI example creates a backup of DEMO01 database on Azure server with credential backupToAzure

  • The DEMO01 database is hosted on the SQL Server instance named ZWERKA\SQL2014
  • The backupAzure are predefined credential in SQL Server
  • The url must contain blob backup storage (example: https:\\zwerkabackup.blob.core.windows.net\backups\ ). Here blob folder is backup folder.
  • Backup type is always full and with format
  • Backup is scheduled for: Every week on Monday, Tuesday at 08:22 starting from 00:20:30 ending at 08:08:45

apexsqlbackup.com /s: ZWERKA\SQL2014 /dbs: DEMO01 /cr: BackupAzure /url: https:\\zwerkabackup.blob.core.windows.net\backups /cr: backupToAzure /scheduler: weekly every:1 wd:monday,tuesday every hh:8 mm:22 shh:00 smm:20 sss:30 ehh:8 emm:8 ess:45