Warm SQL Backup - sql-server

We have a warm sql backup. full backup nightly, txn logs shipped every so often during the day and restored. I need to move the data files to another disk. These DB's are in a "warm backup" state (such that I can't unmark them as read-only - "Error 5063: Database '<dbname>' is in warm standby. A warm-standby database is read-only.
") and am worried about detaching and re-attaching.
How do we obtain the "warm backup" status after detach/attach operations are complete?

The only solution I know is to create a complete backup of your active database and restore this backup to a copy of the database in a 'warm backup' state. First create a backup from the active db:
backup database activedb to disk='somefile'
Then restore the backup on another sql server. If needed you can use the WITH REPLACE option to change the default storage directory
restore database warmbackup from disk='somefile'
with norecovery, replace ....
Now you can create backups of the logs and restore them to the warmbackup with the restore log statement.

It looks like you didn't complete the restore task , just do the restore task only for the TRANSACTOINAL LOG .Then it will be fine immediately when you finish that.

Related

Backup\Restore cmd to Copy db from remote server to desktop

Want to backup/restore to copy a dev database from our server to my local machine. Backup is no problem, but restore fails with 'no database specified' error.
Command:
RESTORE DATABASE [Management]
FROM DISK = N'C:\Databases_2021_Jan_14\Databases_2021_Jan_14\management.BAK'
Clearly,I've identified the database as Management. Or, that's what I think it's saying. And, I'm doing the restore from a backup file on my C: drive.
Might somebody have some insight on this? I'd really appreciate it.
Run the following to verify that the backup is valid and readable first of all. Then identify if you do have a database named Management in the backup set
RESTORE VERIFYONLY
FROM DISK = N'C:\Databases_2021_Jan_14\Databases_2021_Jan_14\management.BAK'
RESTORE HEADERONLY
FROM DISK = N'C:\Databases_2021_Jan_14\Databases_2021_Jan_14\management.BAK'

How to rename database is in Standby/read-only mode in SQL Server?

How to rename database is in Standby/read-only mode in SQL Server? I am getting this error
To change the NAME, the database must be in state in which a checkpoint can be executed
You'll have to take the database out of Standby / Read-Only mode before you can rename it.
RESTORE DATABASE database_name WITH RECOVERY;

Tail log backup message warning before restoring a backup

SSMS 2012
Production server
Production database has Full recovery option.
I want to take a copy of this and restore on to same server with different name.
So I have taken a backup and choose restore but there is a message in the top left corner of the dialog which reads:
a tail-log backup of the source database will be taken...
Additionally, at this point I would rename the destination database, make sure that the rename has renamed the mdf and ldf files and that would be good to go. In this case it hasn't renamed the files so it looks like I will have to do that manually so as not to overwrite the prod database.
I haven't dealt with full recovery databases before. So questions:
What does the tail-log message mean and what are the implications?
Why did the destination database Rename not rename the mdf and ldf files - that's pretty dangerous huh?
What does the tail-log message mean and what are the implications?
Tailog backup message translates to "there is some transaction log generated after your last log backup,so please backup this log so that you can restore to any point in time until this backup"
Why did the destination database Rename not rename the mdf and ldf files - that's pretty dangerous huh?
backup copies only the files,it won't rename them and i don't see why this is dangerous..
I see you trying to restore to the same instance with different name,so tail log backup is not required,since you tried to overwrite the existing database might be the reason for showing tail log backup message

SQL Server 2008 R2 database stuck in Restore

I have two SQL Server 2008 R2 servers one for PROD and the other for DR. I am trying to add log shipping for a database called School.
Steps so far
Back up School database
Restore with database using the UI or using the following SQL statement i.e.
Restore database "School"
From disk ='t:\Data\School.bak'
with NoRecovery
The result is database is stuck in Restoring
If I restore the database with
Restore database "School"
From disk ='t:\Data\School.bak'
With recovery
The database restore completes but the log shipping fails.
I have deleted the database and recreated it again using
Restore database "School"
From disk ='t:\Data\School.bak'
With **NoRecovery**
but it is still stuck in Restoring state.
Is there a way that I can restore the database without having the database been stuck in the restoring state.
This seems like expected behavior to me. Am I misreading something?
After you've restored the database and any differential or required transaction log backups with the NORECOVERY option, you need to tell SQL Server you're done restoring files. The NORECOVERY option is specifically there to let you restore multiple files.
You should just need to run:
RESTORE DATABASE [School] WITH RECOVERY;
That will tell SQL Server you're done, and it will complete the restoration and it will no longer show up as restoring.
I have deleted the database and recreated it again using Restore database "School" from disk ='t:\Data\School.bak' with NoRecovery
you have to use below command as well,if you dont have any further logs
restore database databasename with recovery
some more info:
Restore with database using the UI or using the following SQL statement i.e.
next time try to issue restore statement using tsql,so that you can know status
restore database databasename from disk="path"
with stats=5
now if you want to know indepth details on where it is and what it is doing,you can use a trace flag like below
dbcc traceon(3004,3605,-1)
GO
restore database databasename from disk="path"
with stats=5
this logs output to errorlog like below
2008-01-23 08:59:56.26 spid52 RestoreDatabase: Database dbPerf_MAIN
2008-01-23 08:59:56.26 spid52 Opening backup set
2008-01-23 08:59:56.31 spid52 Restore: Configuration section loaded2008-01-23 08:59:56.31 spid52 Restore: Backup set is open
2008-01-23 08:59:56.31 spid52 Restore: Planning begins
2008-01-23 08:59:56.32 spid52 Halting FullText crawls on database dbPerf_MAIN
2008-01-23 08:59:56.32 spid52 Dismounting FullText catalogs
2008-01-23 08:59:56.32 spid52 X-locking database: dbPerf_MAIN
2008-01-23 08:59:56.32 spid52 Restore: Planning complete
2008-01-23 08:59:56.32 spid52 Restore: BeginRestore (offline) on dbPerf_MAIN
2008-01-23 08:59:56.40 spid52 Restore: PreparingContainers
2008-01-23 08:59:56.43 spid52 Restore: Containers are ready
For your current problem, you can look at event log as it will log current phase
Is there a way that I can restore the database without having the database been stuck in the restoring state.
you will have to get the spid of the backup and see the wait type and troubleshoot accordingly
select * from sys.dm_Exec_requests where sessionid=backupspid

Copying a local SQL Server database (not on Azure)

To back up my SQL Azure database periodically I have been using the simple tSQL statement
CREATE DATABASE FiveModes10_12_12 AS COPY OF FiveModes
But for this project (analysing some experimental results) my database is a local SQL Server 2012 one and I cannot run that statement (I get the error Incorrect syntax near 'COPY'). Looking at the documentation for the CREATE DATABASE command for SQL Server 2012 there is no AS COPY OF option. What is the simplest alternative?
For long lived copies take e database backup instead:
backup database FiveModes to disk = 'path to .bak file' with init, copy_only;
You can the restore this when needed:
restore database FiveMode from disk = 'path to .bak file';
You can even restore the backup as a new database, but you'll need to move the location of the MDF/LDF files during the restore:
restore database FiveMode_12_12 from disk = 'path to .bak file'
with move 'FiveMode' to '<path to place the new copy of MDF>',
move 'FiveMode_log' to '<path to place the new copy of LDF>'
If you need only short lived copy (eg. create a copy, do some experiment, revert to the copy) you can use database snapshots, but it requires Enterprise license. See Database Snapshots:
create database FiveModes10_12_12 on
(Name = 'FiveMode', FileName = '<path to MDF snapshot file>')
as snapshot of FiveModes;
But be aware that snapshots are not at all like Azure copies, is very detrimental to keep them along for long time. For long time copies use backups.

Resources