SQL Server 2008R2 agent job not deleting old bak file - sql-server

Noone on my company's IT is proficient with SQL and servers and an issue has arisen, which no one seems to be able to fix nor is particular eager to. I know a bit but I'm not in IT hence trying to figure out the issue myself.
Anyway, there is a sql server agent job which is supposed to take a daily backup file of a database and delete the previous backup file. The part of creating the .bak file is working but the deletion of the previous day's file is not.
I've found the code, i think, which refers to this delete bit, or rather the parameters (again I think):
EXECUTE master.dbo.xp_sqlmaint N''-D CompanyLive -WriteHistory -VrfyBackup -BkUpDB "J:\Backups" -BkExt "BAK" -BkUpMedia DISK -DelBkUps 1days''',
#database_name=N'CompanyLive',
#flags=4
Shot in the dark, but any glaring errors in this??
Thanks

Related

SQL Server Management Studio 17.7 AutoRecover NOT IN THIS VERSION

I am tearing my hair out because I was working on some SQL scripts and I executed them to ALTER stored procedure, however when I came in this morning I have lost all my work, it was showing the previous day's script. Somehow it didn't save even though I watched it Execute Successfully Completed!.
Now I thought that using Microsoft SQL Server Management Studio v17.7 there will be an auto recovery temp folder with SQL files somewhere, and from looking online its states to go here; C:\Users[User]\Documents\SQL Server Management Studio\Backup Files\Solution1\ and you will see Autorecovery.sql files lots of them.
However this is completely empty, and I got no idea where clever Microsoft has moved this new location too or removed it all together. I went to settings in my SQL studio under Tools->Options->Environment->AutoRecover and both are ticked for "Save AutoRecover Info every 5 minutes" and "keep autorecover info for 7 days". Which tells me it is somewhere on my PC.
I then thought that I might have lost my work and though it would be a good idea to test this scenario on some new scripts and guess what the folder path still shows empty whilst using MSSMS so I got no idea how to utilise this auto recovery feature for the future.
Any ideas.
Try searching in visual studio directories if you have it installed :
C:\Users\<your_user>\Documents\Visual Studio <your_version_visual_studio>\Backup Files\Solution1
SSMS 2017 seems to just keep the recovery files in %TEMP%\ (with name ~vsXXXX.sql)
I have realised the only way to make sure you are safe is to have a folder specified with all your scripts stored there.
This way the autosave only works when you have saved the file prior not unsaved files, so it will be a case of Save + Execute.
I have lost my work for now, but this is why people learn from there mistakes.

Restore SQL Server database from bak file to different partition (Permission Denied)

On Ubuntu 17.04, I have a .bak file in /var/opt/mssql/backup/ that I am trying to restore to a separate partition because the partition I have SQL Server installed on does not have enough room for the database to be restored to.
I am getting an error like the following: The operating system returned the error '5(Access is denied.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on '/media/<my-user-name>/<some-folder>/<mdf-file>.mdf'.
I've tried to use chmod and chown to change the permissions of that folder on the second partition, but I'm not getting it quite right because I still get the error.
What user is trying to write to that folder in the second partition?
How do I get that user account permissions to successfully restore the database to that folder?
I had this second hard drive connected via a caddy and was able to perform this task no problem. But as soon as I installed the ssd internally, Ubuntu has not allowed whatever user account I'm using in the SQL Server CLI for it this time.
Thanks!
Update
I changed the owner of the second partition/ssd to mssql and now I have permission to restore the database to this location. I would assume that if the owner of that whole ssd is mssql, I might have other permission issues down the road using this ssd for other things. Is there a way to configure this so that my personal user account as well as mssql has permissions to this folder enough to own it? I don't think two different accounts can own a folder, but is there a way to permit multiple accounts with sufficient access to perform these actions?
I won't pretend to be knowledgeable about this, but I had a permissions issue while trying to restore a .bak that was on a network vm to my local device, it worked when I added it to a .zip with 7-share, then copied it to the location I wanted and extracted it.
I had the permissions issue when I tried to move it without zipping, and as far as I remember I still had this issue when I used send to compressed (zipped) folder. I'm not sure why, maybe someone else can elaborate
I solve the problem by deleting the old database, creating a new one and restoring the backup to the new one.
My problem was probably cause by the fact that I had created the database in evalutation edition of MS SQL Server and I wanted to rewrite it by backup in new instalation of developer edition.

SSIS 2008 - File Delete not working, but File Move does

We've run into a strange issue. We have some SSIS 2008 packages that had been working fine for quite a while. As part of the work flow they copy files to a backup folder, and then delete the original file. (No, I don't know why they didn't just make it a File Move task.) Suddenly, the delete task has stopped working. It's not just our packages either, it's the packages of a different group on a different SSIS server. Same target folders though.
The server team has gone over the folder permissions, the account the jobs run under have full access. And, if it was an access issue, how could we move the file but not delete it?
We finally found the answer. The file server we're using is Linux based. It is case sensitive, but doesn't throw an error if you use the wrong case. Was a very tough issue for us to track down.

Access file not opening.Error Messag you and another user are attempting to change the same data at same time

Access file not opening. Error Message: The Microsoft Access database engine stopped the process because you and another user are attempting to change the same data at same time.
It is not repairing / compacting through database Jet Engine.
Are you positive you are the only user in the database? If it's on a network drive, try copying it to your local hard drive, doing the compact/repair there, and then copy it back to the network. If it's on your local drive, try rebooting your computer, deleting the .LDB locking file in the same directory as your database (if it exists) and compact/repair again.
I know the original question was posted half a year ago so this is too late to help the poster.
If there is no .ldb file, the database is copied locally (so no possibility of it being locked), you can't repair and JetComp (download from Microsoft) also won't repair then your database is corrupt and the only way forward is to restore from a backup. Sorry.

SQL Server Restore Error - Access is Denied

I created a database on my local machine and then did a backup called tables.bak of table DataLabTables.
I moved that backup to a remote machine without that table and tried to do a restore but get the following error:
System.Data.SqlClient.SqlError: The operating system returned the
error '5(Access is denied.)' while attempting
'RestoreContainer::ValidateTargetForCreation' on 'c:\Program
Files\Microsoft SQL Server\MSSQL.1\MSSQL\DataLabTables.mdf'.
How do I fix my rights, if that is the problem?
I have just had this issue with SQL Server 2012.
It turns out all I had to do was tick the box marked 'Relocate all files to folder' on the 'Files' section:
(Click to see image full size)
This of course assumes you have the correct version of SQL Server installed.
From the error message, it says there's an error when validating the target (c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DataLabTables.mdf) of your restore operation.
That sounds like:
a) that file already exists (because you've already restored it previously) and is in use by SQL Server
or
b) that directory doesn't exist at all
In your question, you mentioned you created a backup for that table - that's not how SQL Server backups work. Those backups are always the whole database (or at least one or several filegroups from that database).
My hunch is: you've already restored that database previously, and now, upon a second restore, you didn't check the checkbox "Overwrite existing database" in your restore wizard - thus the existing file cannot be overwritten and the restore fails.
The user that's running the restore on your remote server obviously doesn't have access to that directory on the remote server.
C:\program files\.... is a protected directory - normal (non-admin) users don't have access to this directory (and its subdirectories).
Easiest solution: try putting your BAK file somewhere else (e.g. C:\temp) and restore it from there
I was having the same problem. It turned out that my SQL Server and SQL Server Agent services logon as were running under the Network Services account which didn't have write access to perform the restore of the back up.
I changed both of these services to logon on as Local System Account and this fixed the problem.
Recently I faced this issue with SQL 2008 R2 and the below solution worked for me:
1) Create a new database with the same name as the one you are trying to restore
2) While restoring, use the same name you used above and in the options, click the overwrite option
You might give the above a shot if the other solutions don't work.
The backup creator had MSSql version 10 installed, so when he took the backup it also stores the original file path (to be able to restore it in same location), but I had version 11, so it could not find the destination directory.
So I changed the output file directory to C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\, and it was able to restore the database successfully.
Source
I had a similar problem. I tried to restore a 2005 .bak file, and i received exactly the same error. I selected the overwrite option as well to no avail.
my solution was to grant the SQL user access to the directory in question, by going to the folder and editing the access rights through the property screen.
lost a couple of hours to this problem too. got it going though:
"access denied" in my case really did mean "access denied". mssqlstudio's user account on my windows device did NOT have full control of the folder specified in the error message. i gave it full control. access was no longer denied and the restore succeeded.
why was the folder locked up for studio ? who knows ? i got enough questions to deal with as it is without trying to answer more.
I had this issue, I logged in as administrator and it fixed the issue.
Another scenario could be the existence of multiple database paths. First, make note of the path where new databases are currently being stored. So if you create a new empty database and then do Tasks/Restore, make sure that the path the restore is trying to use is the same directory that the empty database was created in. Even if the restore path is legal, you will still get the access denied error if it is not the current path you are working with. Very easy to spot when the path is not legal, much harder to spot when the path is legal, but not the current path.
Sorry because I cannot comment...
I had the same problem. In my case the problem was related to trying to restore in an old sql server folder (that existed on the server). This is due to old sql server backup (i.e. SQL Server 2012 Backup) restored in a new sql server (SQL Server 2014). The real issue is not too different from #marc_s answer. Anyway, I changed only the target folder to the new SQL Server DATA folder.
This may not be the best solution, but I was trying to do the restore at SQL Server 2005, but I changed to SQL Server 2008 and it worked.
Got problem like this. Error caused by enabled compression on SQL Server folders.
Frnds... I had the same issue while restroring database and tried every solution but could nt get resolved. Then i tried to re install SQL 2005 and the problem solved. Actully last time i forgot to check on customize option while instlling SQL.. It comes two times while installing and i checkd it for ones only..
In my case - I had to double check the Backup path of the database from where I was restoring. I had previously restored it from a different path when I did it the first time. I fixed the Backup path to use the backup path I used the first time and it worked!
I ended up making new folders for Data and Logs and it worked properly, must have been a folder/file permission issue.
This also happens if the paths are correct, but the service account is not the owner of the data files (yet it still has enough rights for read/write access). This can occur if the permissions for the files were reset to match the permissions of the folder (of course, while the service was stopped).
The easiest solution in this case is to detach each database and attach it again (because when attaching the owner is changed to be the service account).
Try this:
In the Restore DB wizard window, go to Files tab, Uncheck "Relocate All files to folder" check box then change the restore destination from C: to some other drive. Then proceed with the regular restore process. It will get restored successfully.
I had the same problem but I used sql server 2008 r2, you must check in options and verify the paths where sql going to save the files .mdf and .ldf you must select the path of your sql server installation. I solved my problem with this, I hope it helps you.
Then try moving it to a sub folder under the C:, but verify that the user has full rights on the folder your use.

Resources