SqlBak on Linux Reference Manual

The SqlBak application connects your computer to sqlbak.com and allows you to manage database backups from the web. In this post, you will see what commands and parameters it supports on Linux.

There are full and short forms of each command. The full form looks like:

sqlbak --<command> --<parameter1>=<value1> --<parameter2>=<value2> ...

Example: sqlbak --test-connection --connection-id=20878

The short form is like:

sqlbak -<c> -<p1> <value1> -<p2> <value2>

Example: sqlbak -tc -ci 20878

Note also that you need to run any command under a user with root rights.

Get the help

sqlbak --help [--command=<command_name>]
sqlbak -h [-c <command_name>]

This command outputs the complete list of supported commands with short descriptions.

To get help for a specific command add the –command (-c) parameter with the name of the command, for example:

sqlbak --help --command=update-settings

sqlbak -h -c us

Get app’s version

sqlbak --version

sqlbak -v

Get the current status

sqlbak --info
sqlbak -i

This command outputs the server’s name, sqlbak.com account it’s connected to and other useful information. For example, you may see something like

Server name: sqlbak_server
SqlBak.com account: SqlBakAccount
Status: the computer is registered SqlBak.com service
Logging: the app logging is activated

Register the server in sqlbak.com

sqlbak --register --key=<secret_key> 
      [--name=<server_name>] 
      [--mysqldump-path=<path>]
      [--mysql-path=<path>] 
      [--pgdump-path=<path>]
      [--psql-path=<path>]
      [--sqlcmd-path=<path>]
      [--mssql-data=<path>]

sqlbak -r -k <secret_key> 
      [-n <server_name>]
      [-md <path>]
      [-ms <path>]
      [-pd <path>]
      [-ps <path>]
      [-sq <path>]
      [-sqd <path>]

This command registers your computer as a server in sqlbak.com. After that, you will see it on the dashboard and will be able to run backup and maintenance jobs on your machine.

The only required parameter here is –key (-k). It receives your secret key that you can find on the download page when you’re logged in to sqlbak.com.

Example:

sqlbak --register --key=b9acdefc-9c57-4114-9772-9ba058c55196 --name=my_server

sqlbak -r b9acdefc-9c57-4114-9772-9ba058c55196 -n my_server

The optional parameters are:

  • –name (-n) specifies the name of the server that will be displayed on sqlbak.com (if omitted the hostname is used)
  • –mysql-path (-ms) sets path to MySQL (default is /usr/bin/mysql)
  • –mysqldump-path (-md) sets path to mysqldump utility (default is /usr/bin/mysqldump)
  • –psql-path (-ps) sets path to PostgreSQL (default is /usr/bin/psql)
  • –pgdump-path (-pd) sets path to pg_dump utility (default is /usr/bin/pg_dump)
  • –sqlcmd-path (-sq) sets path to sqlcmd utility (default is /opt/mssql-tools/bin/sqlcmd)
  • –mssql-data (-sqd) sets path to path to MS SQL data directory (default is /var/opt/mssql/data/)

Update server’s settings

sqlbak --update-settings 
      [--name=<server_name>] 
      [--mysqldump-path=<path>]
      [--mysql-path=<path>] 
      [--pgdump-path=<path>]
      [--psql-path=<path>]
      [--sqlcmd-path=<path>]
      [--mssql-data=<path>]

sqlbak -us 
      [-n <server_name>]
      [-md <path>]
      [-ms <path>]
      [-pd <path>]
      [-ps <path>]
      [-sq <path>]
      [-sqd <path>]

With this command you can change server’s name along with paths to DBMS and utilities mentioned in previous section.

Example:

sqlbak --update-settings --name=my_server --mysqldump-path=/usr/local/bin/mysqldump --pgdump-path=/usr/local/bin/pg_dump

sqlbak -us -n my_server -md /usr/local/bin/mysqldump -pd /usr/local/bin/pg_dump

Unregister the server from sqlbak.com

sqlbak --unregister
sqlbak -u

This command removes the connection between the computer and sqlbak.com. After the connection is removed you will no longer see this computer on the dashboard and in the list of available servers on sqlbak.com.

Connect to DBMS

sqlbak --add-connection --db-type=mysql|postgresql|mssql 
       --user=<user_name>
      [--password=<password>]
      [--connection-type=<type>]
      [--host=<host>]
      [--port=<port>]
      [--use-ssh=Y|N]
      [--ssh-host=<host>]
      [--ssh-user=<user>]
      [--ssh-password=<password>]
      [--ssh-port=<port>] 
      [--ssh-local-mapped-port=<port>]
      
sqlbak -ac -dt mysql|postgresql|mssql
       -u <user_name>
      [-p <password>]
      [-ct <type>]
      [-h <host>]
      [-P <port>]
      [-ssh Y|N]
      [-sshh <host>]
      [-sshu <user>]
      [-sshup <password>]
      [-sshp <port>]
      [-sshmp <port>]   

In order to backup databases, you need to establish connection between sqlbak application and one or more DBMS and this is what this command for.

There are two required parameters:

  • –db-type (-dt) specifies the type of database you add connection to it should be one of the following values: mysql, postgresql or mssql
  • –user (-u) specifies a user name for DMBS connection

For example:

sqlbak --add-connection --db-type=mysql --user=admin --password=my_password

sqlbak -ac -dt mysql -u admin -p my_password

The optional parameters are:

  • –connection-type (-ct) specifies a connection type, at the moment the only supported value is tcp/ip
  • –host (-h) specifies a host address where DBMS is installed (default is localhost)
  • –password (-p) allows you to specify user’s password right in the command line (which is not secure enough); if you omit this parameter the password will be asked interactively
  • –port (-P) specifies a port for DBMS connection, the default values are: MySQL = 3306, PostgreSQL = 5432, MS SQL = 1433
  • –use-ssh (-ssh) allows you to establish DBMS connection through an ssh tunnel, can be either Y or N, default is N

If you’re using ssh tunnel then you need to specify some additional parameters:

  • –ssh-host (-sshh) specifies the remote host for ssh session
  • –ssh-port (-sshp) specifies the port to connect to the host (optional, default is 22)
  • –ssh-user (-sshu) specifies ssh user name
  • –ssh-password (-sshup) specifies ssh user password
  • –ssh-local-mapped-port (-sshmp) specifies the local mapped port for ssh tunnel (optional, default is 3306)

Get existing DBMS connections

sqlbak --connections

sqlbak -c

This command outputs all DBMS connections in the following format:

Connection-Id: 1, DBMS-Type: mssql, Connection-Name: localhost:1433
Connection-Id: 2, DBMS-Type: mysql, Connection-Name: localhost:3306 

Get current DBMS connection settings

sqlbak --show-connection --connection-id=<connection_id>

sqlbak -sc -ci <connection_id>

This command requires a connection identifier that you can get from the list of existing connections (see the previous section). As a result, you will see something like:

Connection-Id: 2, DBMS-Type: mysql, Connection-Name: localhost:3306, Host: localhost, Port: 3306, User: root, Use-SSH: 0, SSH-Host: None, SSH-Port: 22, SSH-Local-Mapped-Port: 3306, SSH-User: None

Update DBMS connection

sqlbak --update-connection --connection-id=<id>
      [--db-type=mysql|postgresql|mssql]
      [--user=<user_name>]
      [--password=<password>]
      [--connection-type=<type>]
      [--host=<host>]
      [--port=<port>]
      [--use-ssh=Y|N]
      [--ssh-host=<host>]
      [--ssh-user=<user>]
      [--ssh-password=<password>]
      [--ssh-port=<port>] 
      [--ssh-local-mapped-port=<port>]
      
sqlbak -uc -ci=<id>
      [-dt mysql|postgresql|mssql]
      [-u <user_name>]
      [-p <password>]
      [-ct <type>]
      [-h <host>]
      [-P <port>]
      [-ssh Y|N]
      [-sshh <host>]
      [-sshu <user>]
      [-sshup <password>]
      [-sshp <port>]
      [-sshmp <port>]   

This command allows to change settings of an existing DBMS connection. It requires only one parameter: –connection-id (-ci). You can retrieve this identifier from the list of existing connections (see Get existing DBMS connections section).

Other parameters are optional and described in Connect to DBMS section.

Test DBMS connection

sqlbak --test-connection --connection-id=<id>

sqlbak -tc -ci <id>

This command checks whether the sqlbak app is able to connect to DBMS using the current connection settings. If everything is fine you should see:

Connection-Id: 2, DBMS-Type: mysql, Connection-Name: localhost:3306
The connection is tested successfully.

Remove DBMS connection

sqlbak --remove-connection --connection-id=<id>

sqlbak -rc -ci <id>

This command removes a DBMS connection.

Get job list

sqlbak --jobs

sqlbak -j

This command shows information of all jobs configured for this server on sqlbak.com. The output will be like this:

Job-Id: 23668, Job-Name: New Backup job, Connection-Id: 1, DBMS-Type: mysql, Connection-Name: localhost:3306

Run a job

sqlbak --run-job --job-id=<job_id>

sqlbak -rj -ji <job_id>

This command allows you to immediately start job execution. The only thing you need to know is a job identifier that you can get from the job list (see the previous section). While the job is running you will see the detailed log on the console.

Set logging ON and OFF

sqlbak --set-logs --activate=Y|N

sqlbak -sl -a Y|N

This command activates or deactivates sqlbak app logging. These logs can be sent to the support team for the support case investigation. The logging is activated by default.

Upload logs to the support team

sqlbak --upload-logs

sqlbak -ul

This command uploads sqlbak logs to the support team for the future support case investigation

When the logs are uploaded you should see the following message:

The logs have been successfully uploaded.

Leave a Reply

Your email address will not be published. Required fields are marked *