patternsqlMinor
SQL Server 2008 backup script
Viewed 0 times
script2008sqlserverbackup
Problem
I have a lot of SharePoint 2013 databases to backup and if update fail to restore, so I want to automate this operations.
But there is and error msg:
Msg 942, Level 14, State 4, Line 1
Database 'TEST_1' cannot be opened because it is offline.
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.
Is it possbile to switch database offline, make backup and turn it in online mode after this?
ALTER DATABASE [TEST_1] SET OFFLINE WITH ROLLBACK IMMEDIATE
GO
BACKUP DATABASE [TEST_1]
TO DISK = 'C:\path\test_1.bak' WITH NOINIT, STATS = 10
GO
ALTER DATABASE [TEST_1] SET ONLINE WITH ROLLBACK IMMEDIATEBut there is and error msg:
Msg 942, Level 14, State 4, Line 1
Database 'TEST_1' cannot be opened because it is offline.
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.
Is it possbile to switch database offline, make backup and turn it in online mode after this?
Solution
It is not possible, because you cannot create a backup of an offline database.
From MSDN:
Without the NO_TRUNCATE option, the database must be in the ONLINE
state. If the database is in the SUSPENDED state, you might be able to
create a backup by specifying NO_TRUNCATE. But if the database is in
the OFFLINE or EMERGENCY state, BACKUP is not allowed even with
NO_TRUNCATE
From MSDN:
Without the NO_TRUNCATE option, the database must be in the ONLINE
state. If the database is in the SUSPENDED state, you might be able to
create a backup by specifying NO_TRUNCATE. But if the database is in
the OFFLINE or EMERGENCY state, BACKUP is not allowed even with
NO_TRUNCATE
Context
StackExchange Database Administrators Q#104792, answer score: 3
Revisions (0)
No revisions yet.