3

I am writing a backup script for a database and want to use mysqlshell util.dumpSchemas() utility.

But how on earth can I make it work from within a shell script?

The basic process I have is this:

filename_1: backup.sh
. . .
mysqlsh --file mysqlshell_backup.js

filename_2: mysqlshell_backup.js \connect backup_user:<password>@127.0.0.1:3306 util.dumpSchemas(<options........>) \q

But when I run it all I get are errors:

SyntaxError: Invalid or unexpected token at mysqlshell_backup.js:2:0
in \connect backup_user:<password>@127.0.0.1:3306

but if I run the code manually, e.g:

mysqlsh
MySQL  JS > \connect backup_user:<password>@127.0.0.1:3306

it works fine.

MySQL  127.0.0.1:3306 ssl  JS > 

I tried making the file an executable in it's own right and running it on it's own by adding:

#!/usr/local/mysql-shell/bin/mysqlsh --file
\connect backup_user:<password>@127.0.0.1:3306
util.dumpSchemas(<options........>)
\q

but then I get:

mysqlshell_backup.js: line 2: connect: command not found
mysqlshell_backup.js: line 3: syntax error near unexpected token `[<options>],'
mysqlshell_backup.js: line 3: `util.dumpSchemas(<options>)

But again, if I run it directly from within mysqlshell the code works fine, so I know there are no syntax errors.

Is there actually a way to run a mysqlshell command as part of a bigger script, or am I just wasting my time here?

Peter Vandivier
  • 5,485
  • 1
  • 25
  • 49
IGGt
  • 2,266
  • 6
  • 35
  • 49

1 Answers1

3

OK I figured this out. In the main script I can run:

mysqlsh backup_user:<password>@127.0.0.1:3306 --file mysqlshell_backup.js

meaning I can remove that line (and the \q) from the JS script.

IGGt
  • 2,266
  • 6
  • 35
  • 49