Link Search Menu Expand Document

SqlBak-CLI documentation

Get Started

The application is a console utility, the main purpose of which is to run a backup job described in a special JSON file.

Preparation for Use

SqlBak-CLI does not require administrator permission to perform backups. However, in order to avoid permission issues, it is advisable to run the following command on behalf of the administrator (sudo):

Windows

sqlbak-cli config 

Linux

sudo sqlbak-cli config

This command creates the needed directory structure and grants the necessary permission for the correct work of the application.

Backup

To start using the utility, you need to create a JSON file that contains a description of the settings for connecting to the storage locations where backups will be sent.

You can create a file in any text editor. Create a backup-job.json file:

{
	"source": {
		"type": "mssql",
		"data_source": ".",
		"is_integrated_security": false,
		"trust_server_certificate" : true,
		"user_name": "sa",
		"user_password": "my-secret-pwd",
		"database_types":[ "mssql_custom" ]
	},
	"storages":
		 [
			{
				"type": "folder",
				"path": "/tmp/",
				"keep_settings": [
					{ "backup_type": "full", "hours": 1 }
				]
			}
		]

}
{
	"source": {
		"type": "mssql",
		"data_source": ".",
		"is_integrated_security": true,
		"trust_server_certificate" : true,
		"database_types": [ "mssql_custom" ]
	},
	"storages":
		 [
			{
				"type": "folder",
				"path": "c:\\Temp",
				"keep_settings": [
					{ "backup_type": "full", "hours": 1 }
				]
			}
		]

}

Replace the values of sql-server-sa-password and my-db-name with your values. In the Path field, enter the path where the backups should be stored.

That JSON file should be specified in the --job-settings parameter during running a backup job:

sqlbak-cli run-backup --job-settings=backup-job.json

This command will start performing a full backup according to the settings in the backup-job.json file.

To run a transaction log or differential backup, you need to specify the corresponding parameter in the --backup-type parameter. Use the following command to perform an incremental backup::

sqlbak-cli run-backup --job-settings=backup-job.json --backup-type=transaction-log

SqlBak-CLI will display the backup job execution log. If the job is completed successfully, the application will return a zero exit code.

[17:52:10 INF] Starting backup job.
[17:52:10 INF] Taking backups of "." Microsoft SQL Server DBMS with Full backup type.
[17:52:10 INF] The maximum file size for "/tmp/backup" Folder destination is 16 TB.
[17:52:10 WRN] If necessary, compressed backups will be split into volumes with size 16 TB.
[17:52:10 INF] Taking backup of "DataOne" Database with Full backup type... 100%
[17:52:11 INF] Compressing the backup of "DataOne"... 100%
[17:52:13 INF] Uploading the "DataOne" backup to "/tmp/backup" Folder destination.
[17:52:13 INF] Uploading "DataOne_MSSQL_20220908175210Z_msf.zip" (367.56 KB) file to "/tmp/backup" Folder destination. Completed 100%
[17:52:13 INF] Taking backup of "MediaOne" Database with Full backup type... 100%
[17:52:14 INF] Compressing the backup of "MediaOne"... 100%
[17:52:14 INF] Uploading the "MediaOne" backup to "/tmp/backup" Folder destination.
[17:52:14 INF] Uploading "MediaOne_MSSQL_20220908175213Z_msf.zip" (367.43 KB) file to "/tmp/backup" Folder destination. Completed 100%
[17:52:15 INF] Deleting old backups of "DataOne" on "/tmp/backup" Folder destination.
[17:52:15 INF] Deleting old backups of "MediaOne" on "/tmp/backup" Folder destination.
[17:52:15 INF] The backup job has been successfully finished.

Restore

A backup can be restored manually. But it’s easier to do it via sqlbak-cli. The application will find the backup, download and restore it.

To restore, please create a JSON settings file for a restore job.

{
	"type": "restore",
	"target": {
		"type": "mssql",
		"data_source": ".",
		"is_integrated_security": false,
		"trust_server_certificate" : true,
		"user_name": "sa",
		"user_password": "my-secret-pwd",
		"databases": [
			{
				"source_name": "DataOne",
				"target_name": "DataOne"
			},
			{
				"source_name": "MediaOne",
				"target_name": "MediaOne"
			}
		],
	},
	"storages": {
		"type": "folder",
		"path": "/tmp/backup"
	}
}

Use --job-settings argument in the run-restore command to specify the file with the settings:

sqlbak-cli run-restore --job-settings=restore-job.json

SqlBak-CLI will display the restore job execution log. If the job is completed successfully, the application will return a zero exit code.

[14:49:11 INF] Starting restore job.
[14:49:11 INF] Restore "DataOne" Database to "DataOne" Database at "2022-11-13 14:40:06Z" restore point on "Default instance" Microsoft SQL Server.
[14:49:11 INF] Download "DataOne_MSSQL_20221113144006Z_msf.zip" (375.63 KB) file from "/tmp/backup" Folder storage. Completed 100%
[14:49:12 INF] Extract files from archive with "DataOne" Database Full backup at "2022-11-13 14:40:06Z" (375.63 KB). Completed 100%
[14:49:14 INF] Restore "DataOne" Database from "Full" backup at "2022-11-13 14:40:06Z". Completed 100%
[14:49:16 INF] "DataOne" Database restore completed.
[14:49:16 INF] Restore "MediaOne" Database to "MediaOne" Database at "2022-11-13 14:40:19Z" restore point on "Default instance" Microsoft SQL Server.
[14:49:16 INF] Download "MediaOne_MSSQL_20221113144019Z_msf.zip" (375.41 KB) file from "/tmp/backup" Folder storage. Completed 100%
[14:49:16 INF] Extract files from archive with "MediaOne" Database Full backup at "2022-11-13 14:40:19Z" (375.41 KB). Completed 100%
[14:49:18 INF] Restore "MediaOne" Database from "Full" backup at "2022-11-13 14:40:19Z". Completed 100%
[14:49:19 INF] "MediaOne" Database restore completed.
[14:49:19 INF] The restore job has been successfully finished.