|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 11:59 AM
Points: 72,
Visits: 223
|
|
I am more on the Access Programming and SQL Query side with basic setup. SQL scripting for task is not my primary business.
While the IT has a backup system in place, they asked me to make a full backup of the production database on a nightly basis and put it into a folder named Archive on the same virtual machine. They will grab it for archives. This file backup is in addition to the enterprize network going on from the national location. the production is only 90 MB in size, but the data is very important.
I have administrator rights. The Master, Model, and Production DB's need to be backed up - to the same C:\Archive folder with the names plus a date (i.e. Master 09-01-2012)
This seems like a fairly routine application. If there is already a topic on this, please point the way. Thanks!
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 2:24 PM
Points: 64,
Visits: 70
|
|
There is a script here http://www.sqlservercentral.com/scripts/Administration/73478/ posted by Pavle-192195 that should do everything you need with the proper parameters. It also does an actual restore to a test DB and then drops it. If you don't want to do an actual restore I would suggest commenting out or removing that part from both the system DB and user DB parts of the script.
Once you're sure the script works how you want just schedule job with at least 2 steps for it to execute twice (once for the system DBs and once for the user DBs) with enough time to finish before the files are moved or copied and you're good to go. Also, if the files are copied, you'll want an additional job step to remove the old files after a certain period of your choice.
I have not tested this script so make sure you do so in a development environment prior to deploying in production.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 11:59 AM
Points: 72,
Visits: 223
|
|
Wow, thanks! That was a lot to digest - cut it way down and looked at some other solutions. Will post some code here that appears to work.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 11:59 AM
Points: 72,
Visits: 223
|
|
Wow, thanks! That was a lot to digest - cut it way down and looked at some other solutions. Will post some code here that appears to work. This works from the TSQL query window. But, when I created a job and schedule it out 4 minutes ahead, it dosn't run. Added it to Master in the Job. Any other advice?
DECLARE @name VARCHAR(50) -- database name DECLARE @path VARCHAR(256) -- path for backup files DECLARE @fileName VARCHAR(256) -- filename for backup DECLARE @fileDate VARCHAR(20) -- used for file name SET @path = 'C:\Archive\' SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) + '_' + REPLACE(CONVERT(VARCHAR(20),GETDATE(),108),':','') DECLARE db_cursor CURSOR FOR SELECT name FROM master.dbo.sysdatabases WHERE name IN ('RegulatoryDB') /* WHERE name NOT IN ('master','model','msdb','tempdb') */ OPEN db_cursor FETCH NEXT FROM db_cursor INTO @name WHILE @@FETCH_STATUS = 0 BEGIN SET @fileName = @path + @name + '_' + @fileDate + '.BAK' BACKUP DATABASE @name TO DISK = @fileName FETCH NEXT FROM db_cursor INTO @name END CLOSE db_cursor DEALLOCATE db_cursor
Here is the steps for scheduling a job To create a Transact-SQL job step 1.In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.
2.Expand SQL Server Agent, create a new job or right-click an existing job, and then click Properties.
3.In the Job Properties dialog, click the Steps page, and then click New.
4.In the New Job Step dialog, type a job Step name.
5.In the Type list, click Transact-SQL Script (TSQL).
6.In the Command box, type the Transact-SQL command batches, or click Open to select a Transact-SQL file to use as the command.
7.Click Parse to check your syntax.
8.The message "Parse succeeded" is displayed when your syntax is correct. If an error is found, correct the syntax before continuing.
9.Click the Advanced page to set job step options, such as: what action to take if the job step succeeds or fails, how many times SQL Server Agent should try to execute the job step, and the file or table where SQL Server Agent can write the job step output. Only members of the sysadmin fixed server role can write job step output to an operating system file. All SQL Server Agent users can log output to a table.
10.If you are a member of the sysadmin fixed server role and you want to run this job step as a different SQL login, select the SQL login from the Run as user list.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 11:59 AM
Points: 72,
Visits: 223
|
|
Tried ot go bak and edit, and got an error. Noticed that SQL Server Agent was not running. Tried to start and received: Property PagerSendSubjectOnly is not available for AlertSystem '[denregsql\denregulator]'. This property may not exist for this object, or may not be retrievable due to insufficient access rights. (Microsoft.SqlServer.Smo)
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 9:19 AM
Points: 316,
Visits: 1,484
|
|
Ola hollengren, DB maint script.
Don't reinvent the wheel.
Download. Run script (it creates sql agent jobs) Edit job step as needed (number of days to keep, target directory, etc) Schedule job to run daily. Miller time.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 9:34 AM
Points: 6,722,
Visits: 11,762
|
|
SpringTownDBA (8/1/2012) Ola hollengren, DB maint script.
Don't reinvent the wheel.
+1
http://ola.hallengren.com/sql-server-backup.html
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 2:24 PM
Points: 64,
Visits: 70
|
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 11:59 AM
Points: 72,
Visits: 223
|
|
Thanks again, I got sidetracked with the SQL Server Agent failing to start and displaying many errors. While my DBA contact was out for training, another IT person changed the virtual server password. Evidently, we needed to change the passwords on each of the services. We rebooted the SQL Server 2008 R2 to see if the SQL Server Agent service would start and couldn't get back into SQL Server. So we worked that problem out this morning from the top down. In retrospect, glad this happened. Lots of good experience gained about SQL 2008 R2.
My previous experience with SQL Server 2000 is being updated. The demand for front-end MS Access and Excel Object Model Data Mining has kept me away from SQL for too long. All of these responses were very valuable. Including the books. Does SQL Server Central have a Book Review area? Many Thanks!
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 2:24 PM
Points: 64,
Visits: 70
|
|
|
|
|