SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Backuping Stored procs of the Database by using scripts


Backuping Stored procs of the Database by using scripts

Author
Message
raj.prabhu001
raj.prabhu001
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 115
hi all,

i want to create a script to backup the stored procs of the database plz suggest.
sql-lover
sql-lover
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1651 Visits: 1930
raj.prabhu001 (9/30/2013)
hi all,

i want to create a script to backup the stored procs of the database plz suggest.


If this is a one time deal, you can use Management Studio and script those out. Just right click the database, then Task, then Generate Scripts, then select the objects, on this case, store procedures. Then save locally or decide if you want a script per object or a single master script.
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26854 Visits: 17557
raj.prabhu001 (9/30/2013)
hi all,

i want to create a script to backup the stored procs of the database plz suggest.


Do you not already backup the database??? All the procs will be in the backup too.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Grant Fritchey
Grant Fritchey
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41865 Visits: 32666
Another mechanism is to use PowerShell. You can pretty easily walk the structure and generate scripts. Allen White has an example where he does it for the entire database. It'd be pretty easy to pare that down to just stored procedures.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
homebrew01
homebrew01
SSCertifiable
SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)

Group: General Forum Members
Points: 5017 Visits: 9108
In SQL 2000 there was the ability to script out database objects with SQL code. I saved the files and copied them to my 2005 server and it works there. Maybe MS has included the files again in more current versions, or there is another way to do it ??

Anyway, my process is to bring these files onto the server and put them in a folder (hardcoded later) C:\ObjectScripts\:

scptxfr.exe, scptxfr.rll, scriptin.exe, sqlresld.dll

Then I built a routine to script out all the objects from all user databases into their own folders. I find this useful as a way to save all the object definitions such as stored procedure code, table definitions, triggers etc as another level of backup, without having to restore an entire database. Not sure if it could be used to just script SPs.

declare @DatabaseName varchar(100)
declare @code varchar(1000)
declare @DBCount int

-- Load non-System Database names into temp table
select name, ' ' as Run into #programs
from master.sys.databases
where database_id > 4 -- non system
order by name

NextDB:
-- Get database name to process
set @DatabaseName = ' '
set @DatabaseName = (select top 1 name from #programs where run <> 'Y')

--- Script out Database objects
set @code = '"C:\ObjectScripts\scptxfr.exe" /s DB07 ' + ' /d ' + @DatabaseName + ' /I /F '
+ 'I:\ObjectScripts\' + @DatabaseName + '_structure_'+ convert(varchar(8),getdate(),112) + '' + ' /q /A /r'

EXEC master..xp_cmdshell @code

-- Mark database as processed
update #programs set run = 'Y' where @DatabaseName = Name

-- Count if any more to process. If not, exit
set @DBCount = (select count(*) from #programs where run <> 'Y')
if @DBCount = 0 goto Finished

goto NextDB

Finished:



I also use "forfiles" periodically to delete the backups after "X" weeks.



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search