IT Blog

  • Blog
  • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
Experience IT
In a World of Technology, People Make the Difference.
  1. 首页
  2. Technology
  3. Database
  4. 正文

SQL Server Database Backup - 3 Methods

2016-11-01 529点热度 0人点赞 0条评论
Loading...
Database backup is not the DBA only work. Most of developers and even small business owners also need to perform this task. This article will introduce 3 methods to back up database from SQL Server.
  1. Method 1 – from management studio
    1. Connect to database server
    2. Expend Databases folder
    3. Right click on the database that you want to backup
    4. from Context menu click Task
    5. from sub menu click on Back Up…
    6. on the popup window click on Add
    7.  on Select Backup Destination window you could enter file location and file name directly or click on … button to specify a backup file.
    8. Click on OK button to close the window, then click on OK again and wait for the completion.

2. Method 2 – using T-SQL script

You could either to execute the script on Management Studio or store it as stored procedure to execute.
Here’s the script for backing up all user databases:
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:\DB\MSSQL11.MSSQLSERVER\MSSQL\Backup\' 
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 system db
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

    3. Method 3 – using SSIS Service

In order to use SSIS Service, you need SQL Server Development Tool (SSDT) or SQL Server Business Intelligence Development Studio (BIDS) for SQL 2008 and older to create a package. You can deploy the package to SQL Server and schedule a job to auto-run it. 
  1. Create a SSIS project from Visual Studio (SSDT installed). Note that the project template is under Business Intelligence folder, not SQL Server.


  2. Create a package and open it, drag and drop “Back Up Database Task” onto the Control Flow work space.
  3. Double click on the task, “Back Up Database Task” window will popup.
  4. Click on New… button to specify the database connection.
  5. On “Back Up Database task” window click on Database(s) drop down button, and select the database option you want to back up.
  6. In Destination tab, specify Folder location and click OK.
  7. Save the package.

  8. You could execute the task right inside the studio. Right click on the task and select Execute Task from context menu.
    You will see the green check mark when the execution completed.

  9. Now you can run the package or debug the package directly in the Visual Studio, or you can deploy the package to SQL Server to run.
error
fb-share-icon
Tweet
fb-share-icon
IT Team
Author: IT Team

Loading...
标签: Blog
最后更新:2016-11-01

IT Team

stay absorbed stay excellent

点赞
下一篇 >

文章评论

取消回复
最新 热点 随机
最新 热点 随机
Controling Category List on Sidebar Widget Restoring the Links Manager Adding reCaptcha for user forms in WordPress Scheduling Background Job in WordPress WordPress database access with $wpdb CSS Tricks
Scheduling Background Job in WordPressRestoring the Links Manager恢复链接管理器AdSense合规指南Controling Category List on Sidebar WidgetAdding reCaptcha for user forms in WordPress
Post tweets with Power Automate Develop undo feature with trigger Covid-19 open data Feature points sampling method validating reports MS security patches lead to ams login failure Hide author information from WordPress
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • Digital Marketing
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.