bcgov / bcgov/backup-container
Mssql: Incorrect syntax near the keyword 'with'. plugin syntax problem.
- Dominant language
- Shell
- Stars
- 44
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Description
When backing up I get
`Msg 102, Level 15, State 1, Server mssql-server-1-lrjmh, Line 1
Incorrect syntax near '-'.
Msg 319, Level 15, State 1, Server mssql-server-1-lrjmh, Line 1
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.`
I tracked this to the `backup.mssql.plugin` line 19:
`sqlcmd -S ${_hostname}${_portArg} -U ${_username} -P ${_password} -Q "BACKUP DATABASE ${_database} TO DISK = N'${_fileName}' WITH NOFORMAT, NOINIT, SKIP, NOREWIND, NOUNLOAD, STATS = 10"`
The database name should be wrapped in square [ ] brackets, as per Microsoft documentation.
https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-backup-and-restore-database?view=sql-server-ver15
Without it backup gets created but are empty.
Should be
`sqlcmd -S ${_hostname}${_portArg} -U ${_username} -P ${_password} -Q "BACKUP DATABASE [${_database}] TO DISK = N'${_fileName}' WITH NOFORMAT, NOINIT, SKIP, NOREWIND, NOUNLOAD, STATS = 10"`
Haven't tried restore yet, might also need to make changes to that.
Contributor guide
Assessment
This issue has not been assessed yet.