Skip to content

How to deal with spaces on the DB for MSSQL? #306

@farzadha2

Description

@farzadha2

HI
Currently was wondering how to deal with db which have spaces in their name?

example-mssql-db-backup | 2023-12-08.12:00:29 [INFO] ** [16-192.168.2.244__'Reportes\ SAP'] Next Backup at 2023-12-08 21:00:00 -05
i tried the following

- DB16_NAME=Reportes\ SAP
but not sure what's the correct way?

As
in the log i was seeing this

[tiredofit/db-backup:4.0.29 12:07:37 /] $ backup16-now
2023-12-08.12:08:00 [INFO] ** [db-backup16] Starting Manual Backup for db-backup16
2023-12-08.12:08:00 [NOTICE] ** [16-192.168.2.244__'Reportes\ SAP'] Dumping MSSQL database: ''Reportes\ SAP''
2023-12-08.12:08:01 [INFO] ** [16-192.168.2.244__'Reportes\ SAP'] DB Backup of 'mssql_'reportes\ sap'_192.168.2.244_20231208-120800.bak.gz' completed successfully
stat: cannot stat '/tmp/backups/mssql_'\''reportes\ sap'\''_192.168.2.244_20231208-120800.bak.gz': Invalid argument
date: '/tmp/backups/mssql_'\''reportes\ sap'\''_192.168.2.244_20231208-120800.bak.gz': Invalid argument
stat: cannot stat '/tmp/backups/mssql_'\''reportes\ sap'\''_192.168.2.244_20231208-120800.bak.gz': Invalid argument
2023-12-08.12:08:01 [NOTICE] ** [16-192.168.2.244__'Reportes\ SAP'] Backup of 'mssql_'reportes\ sap'_192.168.2.244_20231208-120800.bak.gz' created with the size of  bytes
chmod: cannot access '/tmp/backups/mssql_'\''reportes\ sap'\''_192.168.2.244_20231208-120800.bak.gz': Invalid argument
mv: cannot stat '/tmp/backups/mssql_'\''reportes\ sap'\''_192.168.2.244_20231208-120800.bak.gz': Invalid argument
2023-12-08.12:08:01 [ERROR] ** [16-192.168.2.244__'Reportes\ SAP'] Moving of backup 'mssql_'reportes\ sap'_192.168.2.244_20231208-120800.bak.gz' reported errors
2023-12-08.12:08:01 [NOTICE] ** [16-192.168.2.244__'Reportes\ SAP'] DB Backup for ''Reportes\ SAP'' time taken: Hours: 0 Minutes: 00 Seconds: 01
2023-12-08.12:08:01 [ERROR] ** [16-192.168.2.244__'Reportes\ SAP'] Skipping Cleaning up old backups because there were errors in backing up
2023-12-08.12:08:01 [INFO] ** [16-192.168.2.244__'Reportes\ SAP'] Backup 16 routines finish time: 2023-12-08 12:08:01 -05 with exit code 0
2023-12-08.12:08:01 [NOTICE] ** [16-192.168.2.244__'Reportes\ SAP'] Backup 16 routines time taken: Hours: 0 Minutes: 00 Seconds: 01


debug version

+ silent run_as_user /opt/mssql-tools18/bin/sqlcmd -C -S 192.168.2.244,1433 -U sa -P 'thepassword' -Q 'BACKUP DATABASE ['\''Reportes\ SAP'\''] TO DISK = N'\''/tmp/backups/mssql_'\''reportes\ sap'\''_192.168.2.244_20231208-121442.bak'\'' WITH NOFORMAT, NOINIT, NAME = '\'''\''Reportes\ SAP'\''-full'\'', SKIP, NOREWIND, NOUNLOAD, STATS = 10'
+ '[' true = true ']'
+ run_as_user /opt/mssql-tools18/bin/sqlcmd -C -S 192.168.2.244,1433 -U sa -P 'thepassword' -Q 'BACKUP DATABASE ['\''Reportes\ SAP'\''] TO DISK = N'\''/tmp/backups/mssql_'\''reportes\ sap'\''_192.168.2.244_20231208-121442.bak'\'' WITH NOFORMAT, NOINIT, NAME = '\'''\''Reportes\ SAP'\''-full'\'', SKIP, NOREWIND, NOUNLOAD, STATS = 10'
+ sudo -Eu root /opt/mssql-tools18/bin/sqlcmd -C -S 192.168.2.244,1433 -U sa -P 'thepassword' -Q 'BACKUP DATABASE ['\''Reportes\ SAP'\''] TO DISK = N'\''/tmp/backups/mssql_'\''reportes\ sap'\''_192.168.2.244_20231208-121442.bak'\'' WITH NOFORMAT, NOINIT, NAME = '\'''\''Reportes\ SAP'\''-full'\'', SKIP, NOREWIND, NOUNLOAD, STATS = 10'
Msg 102, Level 15, State 1, Server HERCULES, Line 1
Incorrect syntax near '\ '.
Msg 319, Level 15, State 1, Server HERCULES, 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.
+ exit_code=0
+ var_true ''
+ '[' '' = true ']'
+ '[' '' = yes ']'

also tried with putting it together without space says db not found

also tried with normal space this is the other debug

+ silent run_as_user /opt/mssql-tools18/bin/sqlcmd -C -S 192.168.2.244,1433 -U sa -P 'thepassword' -Q 'BACKUP DATABASE ['\''Reportes SAP'\''] TO DISK = N'\''/tmp/backups/mssql_'\''reportes sap'\''_192.168.2.244_20231208-121816.bak'\'' WITH NOFORMAT, NOINIT, NAME = '\'''\''Reportes SAP'\''-full'\'', SKIP, NOREWIND, NOUNLOAD, STATS = 10'
+ '[' true = true ']'
+ run_as_user /opt/mssql-tools18/bin/sqlcmd -C -S 192.168.2.244,1433 -U sa -P 'thepassword' -Q 'BACKUP DATABASE ['\''Reportes SAP'\''] TO DISK = N'\''/tmp/backups/mssql_'\''reportes sap'\''_192.168.2.244_20231208-121816.bak'\'' WITH NOFORMAT, NOINIT, NAME = '\'''\''Reportes SAP'\''-full'\'', SKIP, NOREWIND, NOUNLOAD, STATS = 10'
+ sudo -Eu root /opt/mssql-tools18/bin/sqlcmd -C -S 192.168.2.244,1433 -U sa -P 'thepassword' -Q 'BACKUP DATABASE ['\''Reportes SAP'\''] TO DISK = N'\''/tmp/backups/mssql_'\''reportes sap'\''_192.168.2.244_20231208-121816.bak'\'' WITH NOFORMAT, NOINIT, NAME = '\'''\''Reportes SAP'\''-full'\'', SKIP, NOREWIND, NOUNLOAD, STATS = 10'
Msg 102, Level 15, State 1, Server HERCULES, Line 1
Incorrect syntax near 'sap'.
Msg 319, Level 15, State 1, Server HERCULES, 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.
+ exit_code=0
+ var_true ''
+ '[' '' = true ']'
+ '[' '' = yes ']'

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions