BCDevOps / backup-container

A simple container for a simple backup strategy.
Apache License 2.0
42 stars 56 forks source link

Mssql: Incorrect syntax near the keyword 'with'. plugin syntax problem. #81

Open Exist2Resist opened 3 years ago

Exist2Resist commented 3 years ago

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.

WadeBarnes commented 3 years ago

Feel free to submit a PR with your changes once you've completed your testing.