I want to take backup of jobs.I know all of these are stored in MSDB database,so i had taken a backup of the msdb database but i'm not able to restore that database as i'm getting a error while restoring on another system that the process terminated abnormally.So,what should i do to restore that.
Thanks Nick Kavadias
But the problem is that when i script my job,there r four steps.I dont get these four steps in detail. There is a condition which is used in those four steps which automatically generates an exception.But i'm not able to find that condition in the script
probably belongs on serverfault. But i think i know what Tarun is talking about.
IMHO the best way to take a copy of all your SQL Server agent jobs is to script them out using management studio. You can do this by clicking on jobs in object explorer, then object explorer details window. All jobs in this instance will be listed here, Select all, and pick script jobs from the right click context window. This will generate a t-sql script with all the jobs on the server.
If you do wish to restore the msdb database ( to keep job history ect.) then you will need to stop the SQL Server Agent service first.
Recently I got a chance to transferred the jobs from SQL Server 2000 to SQL Server 2005 using SSIS (BIDS)
In SSIS there Jobs Transfer Task, you needs to select and give the name and select the source and destination servers, you can transfer all the jobs or specific jobs.
Please try this option, I think it will solve your problem
Cheers
Venkat
Related
I have created a database in SQL Server 2012 with mdf and ldf pointing to a external hard drive attached to my machine. I created tables, stored procedures, populated tables, etc. etc.
I removed the hard drive at the end of the day.
Today, when I attached the hard drive and tried to access the DB in Management Studio, I see the name of the database with (Recovery Pending).
What does this mean? I see the mdf and ldf files in the D drive.
What worked for me was to take the database offline*, then back online - no RESTORE DATABASE was necessary in this case, so far as I can tell.
In SQL Server Management Studio:
right-click on the database
select Tasks / Take Offline ... breathe deeply, cross fingers...
right-click on the database again
select Tasks / Take Online
When you removed the drive, you forcefully disconnected the database from the SQL Server service. SQL Server does not like that.
SQL Server is designed by default so that any database created is automatically kept open until either the computer shuts down, or the SQL Server service is stopped. Prior to removing the drive, you should have "Detached" the database, or stopped the SQL Server service.
You "may" be able to get the database running by executing the following command in a query window: RESTORE DATABASE [xxx] WITH RECOVERY;
You could, although I would not normally recommend this, alter the database to automatically close after there are no active connections.
To accomplish this, you would execute the following query:
ALTER DATABASE [xxx] SET AUTO_CLOSE ON WITH NO_WAIT;
Another way that works is to "Restart" the Database Engine. If feasible and/or practical for this server, it may be faster whenever you have several DB in the external drive.
In SQL Server Management Studio:
Attach the external drive
right-click on the database engine : Server Name(SQL Server
12.0.2000 ... etc)
Select "Restart"
Answer Yes when asked if you want to proceed
Below worked for me:
Run SQL Management Studio as Administrator (right click on SQL
Management Studio icon and select 'Run As')
Take database offline
Detach the database using DROP option
Attach the database
If you were using this database with a Web App running on IIS then you may need to restart the IIS Server
Hope this helps someone
If the SQL Server knows that database recovery needs to be run but something is preventing it from starting, the Server marks the db in ‘Recovery Pending’ state. This is different from the SUSPECT state because it cannot be said that recovery is going to fail – it just hasn’t started yet.
Check this thread: How to fix Recovery Pending State in SQL Server Database?
I'm in the process of doing a large scale server migration, as such I have to move 50+ SQL 2005 databases to a new SQL 2008 server installation.
The DB guys have only given me a backup of each database, so I have a directory with some 50 .bak files sitting in a directory (ie c:\db) that I need to restore.
I need to restore each database to the new server.
I can do this individually in Management Studio, but that would be time consuming. Is there a more efficient way of solving this problem.
So my question is:
What is the most efficient way of restoring all of these databases.
Machine background:
The server is Win 2k8, with SQL 2008 Workgroup Edition, .net 4 is installed along with Powershell 2.
Thanks in advance.
Edited after comment: you can script restores, like:
restore database DatabaseName
from disk = N'c:\dir\BackupFileName.bak'
with file = 1,
move N'DatabaseName' to N'c:\dir\DatabaseName.mdf',
move N'DatabaseName_log' to N'c:\dir\DatabaseName.ldf',
stats = 10,
recovery
The two move lines move the files to a location on the new server. Usually the names are DatabaseName and DatabaseName_log, but they can vary.
With recovery means: bring database online without waiting for additional log restores.
To generate a script like this, click the Script button (top left) in the Restore Database wizard window, and click Script action to....
Write a custom application/script? You could extend SSMS or use SQL server tools to write an application that just reads these files and restores them to the database. I know it is possible in .net, might be possible using powershell scripts as well.
This is efficient if this task is to be done in a short period of time during the production migration, otherwise the overhead of writing the app is more than doing 50 restores manually! But if you are a developer and you choose manually, then shame on you! :).
I've ran some "ALTER" scripts on the database [SQL Server Server 2005], and overwrote some sprocs. Is there any way to undo changes and get my old sprocs back?
Is there a way to get the scripts that were executed out of the .LDf file? That way i can re-run my initial "create" script for my sprocs.
I don't have a backup file with old sprocs.
p.s. i backed the DB up as per #Gulzar's deleted answer, and looks like I'm "hosed".
#Pittsburgh DBA: thanx for the solution, but it doesn't seem to work after the backup.
MORAL: Wait for 10 minutes before trying the suggested answers out
Update from Gulzar: What I meant was a file backup before trying anything (to be safe). Not a SQL Server backup.
FIRST: DO NOT TAKE ANY BACKUPS JUST YET.
There are several tools on the market to do this sort of thing.
You might try this one:
ApexSQL Log
In case anybody else has the same problem - Were you doing transaction log backups every X minutes? If so, you can use Quest LiteSpeed's log reader or Quest Toad for SQL Server's log reader to read the log file backups. It gives undo/redo scripts too for any transaction in the log backups or the ldf.
And after that, look into using ApexSQLScript to script out your databases on a regular basis (and store in version control).
yo do can!!
go to sql server managment studio,connect to your db, left click on your db and go to "tasks".
select restore -> database.
then click the "timeline" button and select 'especific date' and select the day before your mistake.
All programs that have access to your db mus be closed.
It worked for me, i had this very same probelm.
I have been developing in VB.NET and SQL Server 2008 for a while now, but haven't got into live installs yet. In the database system I used be on it had the ability to archive multiple tables into a .dga file, as it was called. I could then restore the .dga file into another database or on another server.
I'm looking for the easiest way to accomplish something similar in SQL Server.
If you want to transfer specific tables, then using Data Transformation Services (right click on the database in SQL Server Management studio and select "Import Data" and it will bring the dialog up for it). Of course, this assumes that you have both databases available to you.
If you are comfortable with replacing the database as a whole, you can easily backup the database and then restore it into a new one through SQL Server Management studio (or through calling the appropriate SP).
I would go for one of the following :
From MS SQL Management Studio, right click on the database / Tasks / Generate scripts
From Visual Studio, in the Server Explorer tab, "publish to provider"
Both will launch a wizard allowing you to export the tables you want the way you want (including data or not, creation scripts or not, etc etc.)
If you want to move tabless without data, the simpliest thing is to script the tables you want and run the script.
We script all our db changes and commit them to subversion and then run them as part of the deplyment process.
If you want to put the whole database on prod including data (scrub out test records first!), then do a backup and restore onthe other server.
For future changes, wescript all our db changes and commit them to subversion and then run them as part of the deployment process. There also are tools that look at the structural differnces bewteen the two servers and creates scripts. REd-Gate's SQL Compare is really good for this.
In addition to HLGEM's suggestions, you can look into SSIS if this is an ongoing process.
I have two queries saved on my SQL Server 2005 and I would like to have them running at certain intervals, e.g. every 24 hours. Is there a way to automate these queries and schedule them via SQL Server Management Studio?
You need to use the SQL Server Agent, installed as part of SQL Server. This is the background service that's responsible for running scheduled maintenance and backup tasks.
Expand the SQL Server Agent node in SQL Server Management Studio, you should see a tree node called "Jobs"
Right-clicking this will give you the option to add a new job. Jobs consist of a series of steps to be executed in order, and when you add a new step to your job, you can choose various types of step, including "Transact-SQL Script"
Create a new job, add a single T-SQL step, put the queries that you want to run into the step properties, and then use the "Schedule" option in the Job properties to create a recurring schedule that'll run the job every 24 hours (or whenever).
You can use the SQL Server Agent, which will allow the server to run the script/stored procedure.
You can also use the Windows Task Scheduler, either on the server or on any other server or workstation to schedule isqlw/sqlcmd to execute your script/stored procedure.
Create a job with a step in which you execute your queries; the job can be scheduled at your needs.
At a previous employer the operations department had a task sheduling application. They prefered to use the command line tools that come with sql server to execute jobs (stored procedures) on a scheduled basis. This way the "task scheduling application" could recieve an exit status (pass/fail, ok/error) and hold up dependent jobs.
I'm sorry I don't remember the name of the command line tool, but it was part of the sql server distro. I also do not remember the name of the task scheduling application. It was not the windows task scheduler. It was something enterprise level used to manage the nightly cycle.
Not sure of the scale of your project, but this is another way to go.
SKapsal's comment on a command line tool for executing SQL commands is a reference to osql (for SQL2000) or sqlcmd (for SQL2005+). You could save your script a file and run it from that command line using Windows Task Scheduler or something similar.
SQL Agent is still the preferred solution, however, as it provides GUI controls for job creation, scheduling, logging and viewing job execution history/results.
how to schedule a job for sql query to run daily?
This is similar question with helpful answer.
Covering simple step by step manual.