SQL Server 2K backup failing as bak files is used by another process - sql

Our backup job failed with error The operating system returned the error '32(The process cannot access the file (XXX_DB.bak) because it is being used by another process.)'. What amuses me is when the SQL Server is creating a new .bak file, how it is possible to be used by another process? There is no anti-virus/tape backup running during this period. Please help me understand how it possible by a process to access this .bak file during the backup operation?
Job details:
Step 1: Deletes old backups
Step 2: performs backup operation

Related

SQL server : mapping network drive - Insufficient system resources exist to complete the requested service

Hello I am trying to create a new plan on SQL server to backup all my database.
My goal is to backup them to a network drive thus if I do have some trouble with my server, I will be able to restore databases to other server thanks to backup present in the network drive.
When my plan is executed, I do have some error so I try to execute manually the relative query.
After some investigation, it seems even net use command doesn't work (whereas it is working and I do it from cmd)
EXEC XP_CMDSHELL 'net use Z: \\ServerName\loggin/user:loggin password'
error is
System error 1450 has occurred. Insufficient system resources exist to complete the requested service.
Beside, I do have another server where it is working so I suppose some configuration missing but can't find them
as my network drive is also accessible via FTP, I chose this way to make the job : create a batch file that run winscp and use this batch file in a SQL agent job . I need to add right to batch file to SQL Server agent account. I also need to define a credential and a proxy to be used in the job.

Need to make a .bat file to stop and then restart a SQL Server database

We have a Dexis dental xray installation that uses SQL Server 2005 as the database. In order to back up the data, I have to open SQL Server Configuration Manager, stop the database, and then run Backup Exec. When it finishes, I have to restart the database.
I need to be able to automate this in Backup Exec 16, so I figured I would create a batch file that runs before the backup to stop the database. I could then execute a second batch to restart.
Can anyone give me a Dos box command that will stop and then restart a SQL Server database?
Thanks.
I thought that backing up the MDF and LDF files only backed up the database, and would not back up the actual data. I also thought that you had to stop the database in order to be given access to the data.
Amazingly, Dexis tech support people have no white papers, no protocols, and no suggestions on how to back up the data.
What is the proper method for backing the entire thing up so that if the server melts down, we can easily recreate the database AND the data?
On the WIndows command prompt, just use the NET STOP command to stop the MSSQLSERVER service, and NET START to restart it again:
NET STOP MSSQLSERVER
.....
REM do your backup here
.....
NET START MSSQLSERVER
Update: however, copying around the SQL Server database files (.mdf and .ldf) to do a server backup is not the recommended way of doing this.
Instead, you should use SQL Server's own BACKUP DATABASE ... functionality to generate .bak files, and then include those .bak files in your file-based backup and skip the .mdf and .ldf files
I am totally agreed with #marc_s answer but have added few more things. We will require Admin permission for such action, so added that check. Here is my batch file -
#echo off
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
NET STOP MSSQL$SQL2017 /y
NET START MSSQL$SQL2017
timeout 5
NET STOP SQLAgent$SQL2017
NET START SQLAgent$SQL2017
timeout 5
NET STOP SQLBrowser
NET START SQLBrowser
Have tested that with Win 10, powershell is used for checking admin rights.

How to create sql script to dump sql server table data?

I am new to sql scripting. I have a problem where I sometimes run a standalone mode that doesn't allow a connection from my database to my actual program. I am trying to automate a way to take the data out of my sql server database and push it to my program somehow. Just as a backup.
Is this possible?
Source: fmsinc.com/free/NewTips/SQL/SQLServerExpr..
Download and install the SQL Server Management Studio Express interface from the following URL (if you do not already have this utility installed on your server):
http://www.microsoft.com/downloads/details.aspx?FamilyID=c243a5ae-4bd1-4e3d-94b8-5a0f62bf7796&displaylang=en
Please note that an installation of SQL Server Express does not install this interface (at the time this article was created for the 2005 version). This is a separate download.
Open the SQL Server Management Studio Express interface.
Create a new backup device using the wizard (expand Server Objects => New Backup Device).
Right click on the new backup device and select the database that you wish to backup.
Select the backup type (most often this is “Full”).
Choose a name for the job. Insert a description if you would like.
Click the Add button to add a Device Destination (this is where you would like the backup .bak output file to be placed).
Click Ok. The backup device is now setup. Repeat steps 3-7 for each database that you wish to backup.
Create a batch file using the following syntax (this is used to execute the backup device).
A syntax example is below (remember to save this file with a “BAT” file extension):
===< Begin Code Batch Script >===
sqlcmd -S MYSERVER\OFFICESERVERS -E -Q "BACKUP DATABASE MASTER TO TEST"
===< End Code Batch Script >=====
..where “MYSERVER” is the name of the SQL Server machine.
..where “OFFICESERVERS” is the name of the SQL Server.
..where “Test” is the name of the backup job.
..where “MASTER” is the name of the database.
Finally, open the Microsoft Windows Scheduler and assign the batch file created above to a scheduled event. Set the event to run at the point you wish.
EDIT: As you asked if 2 peoples are working remotely - in that case one will be server or both will be clients. What you can do is to create backup file on Server & the get that backup file for client OR in other case define 2 different Jobs & set their starting points for each of them. A backup file will be created for each job that will be executed & get that from destination for each client.

Restore Database from URL (Azure storage) fails without further details

On a Windows Azure VM running Windows 2008 R2 and SQL 2012 Enterprise SP1 CU5, I'm trying to restore a backup stored in Azure as a page blob with the new functionality RESTORE DATABASE FROM URL.
So far I've done it several times with backups up to 60GB in size (uncompressed) and it works like a charm.
However, there is a particular backup 32GB in size that I can't restore. It fails with the following error message:
Msg 3013, Level 16, State 1, Line 2
RESTORE DATABASE is terminating abnormally.
No further information is provided as to why it fails. If I download the same backup from to the local hard drive I can restore it without problem. I tried executing
dbcc traceon(3004,3605,-1)
to get more info and I can see that the DB is restored successfully, then it zeroes in the log file and after that completes is when it fails.
There isn't any error message in the SQL logs, neither in Windows Event log.
There is plenty of free space on that hard drive.
VM and storage are in the same datacenter and I've followed all best practices in building the environment.
EDIT> I noticed the following lines in Event viewer AFTER the database is restored and BEFORE it starts restoring the LOG file (in other words, while the log file is being zeroed)
SQLVDI: Loc=CVDS::Close. Desc=Open devices!. ErrorCode=(0). Process=2900. Thread=1104. Client. Instance=MSSQLSERVER. VD=Global\https://url/stuff/xx.bak_SQLVDIMemoryName_0.
SQLVDI: Loc=SignalAbort. Desc=Client initiates abort. ErrorCode=(0). Process=2900. Thread=1104. Client. Instance=MSSQLSERVER. VD=Global\https://url/stuff/xx.bak_SQLVDIMemoryName_0.
SQLVDI: Loc=TriggerAbort. Desc=invoked. ErrorCode=(0). Process=1508. Thread=2008. Server. Instance=MSSQLSERVER. VD=Global\https://url/stuff/xx.bak_SQLVDIMemoryName_0.
Is it possible that the connection to Azure storage times out before the zeroing finishes and thus the RESTORE fails? If so, how do I change this timeout?
You may wish to try enabling instant file initialization (it solved the problem for me). To do this you need to grant the SQL service account the 'Perform volume maintenance tasks' permission in security policy.
For instructions, see:http://blogs.msdn.com/b/sql_pfe_blog/archive/2009/12/23/how-and-why-to-enable-instant-file-initialization.aspx
With thanks to this 'question' for providing the answer:https://stackoverflow.com/questions/20692592/restoring-large-database-backups-from-azure-blob-storage-to-sql-server-2012-in-a
For anyone having this issue i found a different workaround.
Rather than creating the backup Log file to store on Azure blob storage, i changed that part of the script generated before execution to store it to local disk.
I'm unsure as to why the log file is not successfully being created when SQL attempts to write it to the blob storage.
Here is a segment of the script in questiona fter my amendmants :-
USE [master]
BACKUP LOG [RealTime] TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQL14\MSSQL\Backup\YourDb_LogBackup_2015-07-07_09-04-17.bak'
WITH NOFORMAT, NOINIT, NAME = N'YourDb_LogBackup_2015-07-07_09-04-17', NOSKIP, NOREWIND, NOUNLOAD, NORECOVERY , STATS = 5
Leave the rest of the script generated to RESTORE the database as is.

SQL Server 2005 Restore Hanging

I have a database showing up in SQL Enterprise Manager as "(Restoring...)"
If i do SP_WHO there is no restore process.
The disk and CPU activity on the server is very low
I think it is not restoring at all.
How can I get rid of this?
I've tried renaming the underlying MDF file, but even when I do "NET STOP MSSQLSERVER" it tells me the file is open.
I've tried using PROCEXP to find what process has the file open, but even the latest PROCEXP can't seem to do that on Windows Server 2003 R2 x64. The lower pane view is blank.
In the SQL Server log it says "the database is marked RESTORING and is in a state that does not allow recovery to be run"
Sql Server has two backup types:
Full backup, contains the entire database
Transaction log backup, contains only the changes since the last full backup
When restoring, Sql Server asks you if you want to restore additional logs after the full backup. If you choose this option, called WITH NORECOVERY, the database will be left in Restoring state. It will be waiting for more transaction logs to be restored.
You can force it out of Restoring mode with:
RESTORE DATABASE <DATABASE_NAME> WITH RECOVERY
If this command gives an error, detach the database, remove the MDF files, and start the restore from scratch. If it keeps failing, your backup file might be corrupted.
Here's a screenshot of the restore options, with the default selected. The second option will leave the database in Restoring state.
Image of the restore options http://img193.imageshack.us/img193/8366/captureu.png
P.S.1. Are you running the 64 bit version of process explorer? Verify that you see procexp64.exe in the task manager.
P.S.2. This is more like a question for serverfault.
WITH RECOVERY option is used by default when RESTORE DATABASE/RESTORE LOG commands is executed. If you're stuck in "restoring" process you can bring back a database to online state by executing:
RESTORE DATABASE YourDB WITH RECOVERY
GO
You can look for more options and some third party tools on this SO post https://stackoverflow.com/a/21192066/2808398
If you are trying to get rid of the lock on the file I would recommend getting Unlocker http://www.emptyloop.com/unlocker/
It'll give you an option to unlock the file, or kill the process that has locked the file. Run this on the mdf and ldf files.
Another option is to try to Detach the files from Enterprise Manager or Sql Management Studio and then reattach the db. You can try this before running unlocker to see if sql server will just release the mdf and ldf files.
CAUTION: If you kill the process you might lose data or the data might get corrupted so use this only if you are trying to get rid of it and you have a good and tested backup.