LucidDbScriptingLucidUsingBASH

From LucidDB Wiki
Jump to: navigation, search

Scripting Lucid

At some point you will want to perform backups of your database and execute scripts against LucidDB to fill it with data or take other actions.
In a Linux environment using the BASH shell this is extremely easy:
bjackson@sc-vm01-lnx:/opt/luciddb-0.9.4/bin$ echo '!run /path/to/script/myscript.sql' | ./sqllineClient

The above example would cause the command !run /path/to/scripts/myscript.sql to be issued once ./sqllineClient had loaded and cause each line in the sql script to be executed in turn. All commands beginning with an exclamation point (!run, !quit, etc.) come from the software sqlline. sqlline is a terminal based java SQL client packaged by default with LucidDB. sqlline documentation can be found here [sqlline documentation].

Backing up is another useful case for this:
echo '-e "CALL SYS_ROOT.BACKUP_DATABASE( '/backups', 'FULL', 'UNCOMPRESSED' )"' | ./sqllineClient

You can discover more about performing backup and restore as well as other operations by reading documentation here: LucidDbSystemProcedures

BASH: Live by the character escaping rules of the shell

While scripting the execution of commands both to sqllineClient and within it, remember that the character escaping rules of your shell apply. For example if you intend to write the following SQL and execute it against LucidDB through sqllineClient you would take your idea:

0: jdbc:luciddb:http://localhost> select statement from table(sys_root.generate_ddl_for_schema('LOCALDB', 'TESTING'));

Translating to the final command at the BASH shell of:

echo select statement from table\(sys_root.generate_ddl_for_schema\(\'LOCALDB\', \'TESTING\'\)\)\; | ./sqllineClient > report.txt

Notice the \ which escape all the ( ) ' ; marks in the SQL command being pipped over to the ./sqllineClient command. If you fail to escape like this and just single quote your string, BASH will strip out your single quotes or similar thing before the command is passed over to sqllineClient.

External References

The Official GNU BASH Documentation: Quoting

BLOG: BASH: Single-quotes inside of single-quoted strings

Personal tools
Product Documentation