Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
hi to all,
this is Hem Raj Thakur, and I want to create a database backup automatically time to time.
How can I solve this problems. please help me. It's Urgent.

Thanks in advance.
Hem Raj Thakur
Posted
Comments
phil.o 6-Dec-13 5:06am    
Which version of SQL Server? Express?
Please tag your question accordingly.
Hem Raj Thakur 6-Dec-13 5:24am    
sqlserver 2005

If your SQL Server version is not an express one, as it seems, then you can use the Maintenance Plan feature of SQL Server Management Studio, that will allow you to configure and schedule your databases backups with a graphical UI.
Setting up a Maintenance Plan to Backup Databases[^]

If you have an express version, then you will not have access to SQL Server agent tasks scheduling, and will have to use the script provided in solution 2 ; this can be scheduled with the Windows Scheduler and osql Utility[^].
 
Share this answer
 
1.Create the below scrip as procedure to take the backup of all the db which is available in mssql ,except system db's

SQL
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

 
-- specify database backup directory
SET @path = 'C:\Backup\'  

 
-- specify filename format
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) 

 
DECLARE db_cursor CURSOR FOR  
SELECT name 
FROM master.dbo.sysdatabases 
WHERE name NOT IN ('master','model','msdb','tempdb')  -- exclude these databases

 
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



2. Schedule this procedure in sql agent with required time.
or Schedule it in Task Scheduler if you are using Express Edition
For more see this
Automating the Backup of a SQL Server 2008 Express Database
 
Share this answer
 
v3
Comments
Vishal Pand3y 6-Dec-13 5:14am    
but what if someone not had sql agent like in Express Edition
Vishal Pand3y 6-Dec-13 5:20am    
See this for express edition http://geekswithblogs.net/JaydPage/archive/2011/02/19/automating-the-backup-of-a-sql-server-2008-express-database.aspx
you can create daily backup job, please refer below URL:

Create a database backup job using SQL Server Management Studio
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900