Январь
5
mssql restore DB from bash
Восстановить через «Азуру» не получилась, так как ругалось что кто-то подключен ох уж этот «микрософт», конечно я — подключен
Msg 3101, Level 16, State 1, Server name_mssqlinstallserver, Line 1
Exclusive access could not be obtained because the database is in use.
Msg 3013, Level 16, State 1, Server name_mssqlinstallserver, Line 1
RESTORE DATABASE is terminating abnormally.
даже
systemctl stop mssql-server
systemctl start mssql-server
не помогал
но в совокупности через баш получилось после перу перезагрузок
но после восстановления, нужно выполнить пару команд, чтоб подключить базу — иначе она будет висеть в восставляемых
sqlcmd -S localhost -U sa -Q "RESTORE DATABASE [BD_name name] FROM DISK = N'/var/opt/old/data/BD_name name-202515-12-51-56.bak' WITH FILE = 1, NOUNLOAD, REPLACE, NORECOVERY, STATS = 5"
sqlcmd -S localhost -U sa -Q "RESTORE DATABASE [BD_name name] WITH RECOVERY"
sqlcmd -S localhost -U sa -Q "SELECT name, state_desc FROM sys.databases WHERE name = 'BD_name name'"
в суме получится что-то подобное
root@server:/var/opt/mssql/data# sqlcmd -S localhost -U sa -Q "RESTORE DATABASE [BD_name name] FROM DISK = N'/var/opt/old/data/BD_name name-202515-12-51-56.bak' WITH FILE = 1, NOUNLOAD, REPLACE, NORECOVERY, STATS = 5"
Password:
5 percent processed
10 percent processed.
15 percent processed.
20 percent processed.
25 percent processed.
30 percent processed.
35 percent processed.
40 percent processed.
45 percent processed.
50 percent processed.
55 percent processed.
60 percent processed.
65 percent processed.
70 percent processed.
75 percent processed.
80 percent processed.
85 percent processed.
90 percent processed.
95 percent processed.
100 percent processed.
Processed 32832 pages for database 'BD_name name', file 'BD_name name' on file 1.
Processed 2 pages for database 'BD_name name', file 'BD_name name_log' on file 1.
RESTORE DATABASE successfully processed 32834 pages in 7.609 seconds (33.711 MB/sec).
root@server:/var/opt/mssql/data# sqlcmd -S localhost -U sa -Q "RESTORE DATABASE [BD_name name] WITH RECOVERY"
Password:
RESTORE DATABASE successfully processed 0 pages in 4.043 seconds (0.000 MB/sec).
root@server:/var/opt/mssql/data# sqlcmd -S localhost -U sa -Q "SELECT name, state_desc FROM sys.databases WHERE name = 'BD_name name'"
Password:
name state_desc
-------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------
BD_name name ONLINE
(1 rows affected)
root@server:/var/opt/mssql/data#