LAMLE IT
  • Home
  • Thủ thuật
    • Excel
    • Facebook
    • Máy Tính
    • Mobile
    • SQL
  • Windows
    • Windows 10
    • Windows 7
  • Ghost Windows
    • Ghost win10
    • Ghost win7
  • Phần Mềm
    • Office
    • Tools
    • Mutil Boot
  • Website
    • Blogspot
    • WordPress
    • Share Theme
  • Tổng hợp
    • Game
    • Sách
    • Blog
  • Tin tức
No Result
View All Result
  • Home
  • Thủ thuật
    • Excel
    • Facebook
    • Máy Tính
    • Mobile
    • SQL
  • Windows
    • Windows 10
    • Windows 7
  • Ghost Windows
    • Ghost win10
    • Ghost win7
  • Phần Mềm
    • Office
    • Tools
    • Mutil Boot
  • Website
    • Blogspot
    • WordPress
    • Share Theme
  • Tổng hợp
    • Game
    • Sách
    • Blog
  • Tin tức
LAMLE IT
No Result
View All Result

Trang chủ » Tự động backup database đối với SQL Server Express

Tự động backup database đối với SQL Server Express

by admin
30/10/2020
in SQL, Thủ thuật
0
SHARES
10
VIEWS
Share on Facebook

 

Create the Backup Job

Run SQL Server Management Studio Express.

  1. In the tree view, expand Server Objects => New Backup Device.
    SQL Server Express New Backup Device Menu
  2. The Backup Device dialog opens
    SQL Server Express Backup Device Dialog
    1. For Device Name, type in a name for your new backup job.
    2. For Destination, select the path to store the backups. In most cases, it is best to use an location on another device.
    3. Press OK.
  3. Right click on the new backup device that you just created and select the option called “Backup Database”.
    SQL Server Express Backup Type
    1. Select the backup type (most often this is “Full”).
  4. On the left side, select Backup Options and set the following:
    Backup Database
    1. Name: Create a name for the backup job.
    2. Description (optional).
    3. Press OK.
  5. SQL Server runs the backup job to test it. If successful, it confirms this with the following message:
    Database backup confirmed
  6. To verify the backup output yourself, check the destination folder to ensure that the backup file exists. The backup of the database is in the form of a .bak file.

The setup of the backup job is now complete. Repeat these steps for each database you wish to backup.

Create a Batch Command to Run the Job

A batch file can be used to run the SQL Server backup job that you just created. Here’s an example (remember to save this file with a “BAT” file extension):

--- < Begin Code Batch Script > ---
sqlcmd -S MYSERVEROFFICESERVERS -E -Q
"BACKUP DATABASE MASTER TO T ESTBACKUP"
--- < End Code Batch Script > -----

..where “MYSERVER” is the name of the SQL Server physical machine.
..where “OFFICESERVERS” is the name of the SQL Server.
..where “TESTBACKUP” is the name of the backup job.
..where “MASTER” is the name of the database.

Schedule the Job

For this task to run automatically, it must be assigned to a scheduler program. Here are a few options:

  1. The built in Microsoft Windows Scheduler and assign the batch file created above to a scheduled event.
  2. FMS offers a program Total Visual Agent, which includes the ability to execute and run a specified batch command on the schedule that best suits your needs and maintain an audit log.




—————————————————————————————————
ví dụ: 
Tạo file .bat như sau: 

echo off
:: set folder to save backup files ex. BACKUPPATH=c:backup
set BACKUPPATH=E:123
:: set Sql Server location ex. set SERVERNAME=localhostSQLEXPRESS
set SERVERNAME=LAMLESQLSERVER_2014
:: set Database name to backup
set DATABASENAME=test
set DATESTAMP=%date:~6,4%_%date:~3,2%_%date:~0,2%_%time:~0,2%%time:~3,2%
set BACKUPFILENAME=%BACKUPPATH%%DATABASENAME%_%DATESTAMP%.bak
set zipfilename=%BACKUPPATH%%DATABASENAME%_%DATESTAMP%.zip
echo.
sqlcmd -U sa -P luakchuong -S %SERVERNAME% -d %DATABASENAME% -Q “BACKUP DATABASE [%DATABASENAME%] TO DISK = N’%BACKUPFILENAME%’ WITH INIT , NOUNLOAD , NAME = N’%DATABASENAME% backup’, NOSKIP , STATS = 10, NOFORMAT”
echo.
echo running command: creating bak file….
%cmdStr%
set cmdStr=”C:Program FilesWinRARwinrar.exe” a -afzip “%zipfilename%” “%BACKUPFILENAME%”
echo.
echo running command: %cmdStr%
%cmdStr%
set cmdStr=DEL /q /f “%BACKUPFILENAME%”
echo.
echo running command: %cmdStr%
%cmdStr%
echo.
:: In this case, we are choosing to keep the most recent 10 files
:: Also, the files we are looking for have a ‘bak’ extension
for /f “skip=2 delims=” %%F in (‘dir %BACKUPPATH%*.zip /s/b/o-d/a-d’) do del “%%F”
xcopy /y /f “E:123*.zip” “D:Backup” /c
for /f “skip=2 delims=” %%F in (‘dir D:Backup*.zip /s/b/o-d/a-d’) do del “%%F”
echo.
exit

Previous Post

Cách Tính Dung Lượng Ổ Cứng Cho Camera

Next Post

Ghi ngày tháng và thời gian tự động khi dữ liệu thay đổi trong excel

Đọc thêm

Xây dựng sổ chi tiêu – kết nối giữa Google Sheet và Telegram
Blog

Xây dựng sổ chi tiêu – kết nối giữa Google Sheet và Telegram

27/03/2025
Tạo lệnh ping tự động ghi log kèm thời gian mất kết nối và khi có kết nối lại
Máy Tính

Tạo lệnh ping tự động ghi log kèm thời gian mất kết nối và khi có kết nối lại

30/07/2024
Khắc phục lỗi mở file đính kèm pdf trong excel “Cannot start the source application for this object”
Excel

Khắc phục lỗi mở file đính kèm pdf trong excel “Cannot start the source application for this object”

25/06/2024
Lỗi Name Conflict trong Excel – cách khắc phục lỗi này 100%
Excel

Lỗi Name Conflict trong Excel – cách khắc phục lỗi này 100%

24/06/2025

Để lại một bình luận Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Bài viết xem nhiều

  • Tô màu để tạo cảnh báo nhắc nhở trong Google Sheet

    Tô màu để tạo cảnh báo nhắc nhở trong Google Sheet

    0 shares
    Share 0 Tweet 0
  • Khắc phục lỗi mở file đính kèm pdf trong excel “Cannot start the source application for this object”

    0 shares
    Share 0 Tweet 0
  • Hướng dẫn sửa lỗi treo logo khởi động windows 10 trên laptop Dell

    0 shares
    Share 0 Tweet 0
  • Lấy dữ liệu từ Google Sheets tạo web tra cứu sử dụng Apps Script

    0 shares
    Share 0 Tweet 0
  • Sửa lỗi không sử dụng được phím tắt ẩn hiện dòng cột trong Excel

    0 shares
    Share 0 Tweet 0
  • Hướng dẫn tự động sao lưu trong SQL Server

    0 shares
    Share 0 Tweet 0
LAMLE IT

Xin chào, tôi tên Lâm là Founder của website Lamleit.com. Chào mừng bạn đến với website này, đây là nơi bạn có thể tìm thấy những kiến thức và thông tin hữu ích về công nghệ. Cũng là nơi tôi chia sẻ về những sở thích, kiến thức và trải nghiệm của bản thân trong cuộc sống. Welcome!

Chuyên mục

  • Blog
  • Blogspot
  • Chưa phân loại
  • Excel
  • Facebook
  • Game
  • Ghost win7
  • Máy Tính
  • Mobile
  • Mutil Boot
  • Office
  • Phần Mềm
  • Sách
  • Share Theme
  • SQL
  • Thủ thuật
  • Tin tức
  • Tổng hợp
  • Tools
  • Website
  • Windows
  • Windows 10
  • Windows 7
  • Wordpress

Tag

Blog Blogspot Excel facebook Mobile office PC SQL Thủ thuật
No Result
View All Result
  • Home
  • Thủ thuật
    • Excel
    • Facebook
    • Máy Tính
    • Mobile
    • SQL
  • Windows
    • Windows 10
    • Windows 7
  • Ghost Windows
    • Ghost win10
    • Ghost win7
  • Phần Mềm
    • Office
    • Tools
    • Mutil Boot
  • Website
    • Blogspot
    • WordPress
    • Share Theme
  • Tổng hợp
    • Game
    • Sách
    • Blog
  • Tin tức

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?