PDA

View Full Version : Rất cần cách backup va restore datbase in SQL



dinhtyhue
24-03-2006, 22:58
Hiện nay tôi đang học SQL và Java, xin cho hỏi làm thế nào để backup dữ liệu rồi sau đó restore lại, để khỏi bị sự cố về mất dữ liệu. thì phải làm như thế nào? trong SQL ? code?
Thank! tran_mouse0705@yahoo.com

DigiPower
25-03-2006, 08:17
Hiện nay tôi đang học SQL và Java, xin cho hỏi làm thế nào để backup dữ liệu rồi sau đó restore lại, để khỏi bị sự cố về mất dữ liệu. thì phải làm như thế nào? trong SQL ? code?

SQL phổ biến hiện nay có 2 loại: MSSQL ( Windows ) + MySQL ( Linux + Windows )

*** Đối với MSSQL thì bạn dùng Tools: SQL Enterpise Manager kèm theo bộ cài đặt của SQL Server.

*** Đối với MySQL: hiện tại trên internet có cung cấp rất nhiều script quản lý mySQL bạn có thể search tại địa chỉ: http://www.hotscripts.com ( VD: phpMyAdmin dùng PHP - đây là 1 tool quản lý mySQL cực mạnh, còn bạn dùng Java thì chịu khó search thêm nhé )

nobitavietnam
25-03-2006, 11:42
Có công cụ nào có thể backup và restore database MSSQL bằng ASP hoặc ASP.net không vậy?
Nếu có cho tôi xin với. :shifty:

VietDuc
25-03-2006, 13:47
Cái script đó phải connect được với SQL Server với quyền sysadmin.

nobitavietnam
25-03-2006, 13:51
Cái script đó phải connect được với SQL Server với quyền sysadmin.
Sao phải là sysadmin ?
Chỉ cần user và pass của userDatabase đó thôi chứ :)

VietDuc
25-03-2006, 14:37
Sao phải là sysadmin ?
Chỉ cần user và pass của userDatabase đó thôi chứ :)
Database Owner chỉ backup được chứ ko restore được.
If you have any question about that, please ask Microsoft :bawling:

nobitavietnam
25-03-2006, 14:39
:| Vậy có cái script nào để backup không vậy :(
asp or aspx cũng được :D

bpmtri
25-03-2006, 14:41
Sao phải là sysadmin ?
Chỉ cần user và pass của userDatabase đó thôi chứ :)

Trích trong SQL Server Online Book!


Permissions
If the database being restored does not exist, the user must have CREATE DATABASE permissions to be able to execute RESTORE. If the database exists, RESTORE permissions default to members of the sysadmin and dbcreator fixed server roles and the owner (dbo) of the database.

RESTORE permissions are given to roles in which membership information is always readily available to the server. Because fixed database role membership can be checked only when the database is accessible and undamaged, which is not always the case when RESTORE is executed, members of the db_owner fixed database role do not have RESTORE permissions.

In addition, the user may specify passwords for a media set, a backup set, or both. When a password is defined on a media set, it is not enough that a user is a member of appropriate fixed server and database roles to perform a backup. The user also must supply the media password to perform these operations. Similarly, RESTORE is not allowed unless the correct media password and backup set password are specified in the restore command.

Defining passwords for backup sets and media sets is an optional feature in the BACKUP statement. The passwords will prevent unauthorized restore operations and unauthorized appends of backup sets to media using SQL Server 2000 tools, but passwords do not prevent overwrite of media with the FORMAT option.

Thus, although the use of passwords can help protect the contents of media from unauthorized access using SQL Server tools, passwords do not protect contents from being destroyed. Passwords do not fully prevent unauthorized access to the contents of the media because the data in the backup sets is not encrypted and could theoretically be examined by programs specifically created for this purpose. For situations where security is crucial, it is important to prevent access to the media by unauthorized individuals.

It is an error to specify a password if none is defined.

dinhtyhue
30-03-2006, 22:35
có nhiều phần mềm có các chức năng là backup và restore vẫn được, ý tôi muốn hỏi cách làm như vậy đó:
Ví dụ tôi click vao button backup thì bacup còn click vào restore thì restore lại, tôi lập trình giao diện trong java và MSSQL SERVER 2000

lannguyen
31-03-2006, 17:35
Mình làm với VB.NET cách sau: lập trình GUI cho chọn Database, rồi thực thi store procedure sau: BACKUP DATABASE @db TO DISK = @path, tương tự cho phục hồi RESTORE DATABASE @db FROM DISK = @path. Nếu chỉ muốn export dữ liệu thì tìm hiểu về lệnh bcp, có thể export/import từng table :)

lytamhoana6cntt
02-06-2006, 11:12
Phải kill process thì mới backup được. U có thể giải thích rõ hơn đi

peijia2007
27-06-2010, 13:51
Bài viết này có thể giúp bạn http://blogtinhoc.freevnn.com/index.php?ent=138

MưaCaoNguyen
28-06-2010, 08:16
There is 50 ways to love your lover (Có 50 cách (chứ không phải là 36 kiểu) để yêu người yêu của mình)

Thứ nhất, nếu muốn backup với những thao tác bằng tay (manual backup), thì dùng SQL Management Studio. SQL-2000 không gọi là SQL Management Studio, mà có một tên khác (quên mất rồi). Bạn nào còn dùng SQL-2000 chắc phải biết.

Thứ hai, nếu có tiền mua backup tape drive, thì phần cứng dùng để backup này thường bán chung với một phần mềm để backup. Đọc tài liệu của nó.

Thứ ba, có thể dùng lệnh SQL BACKUP để back up:

http://msdn.microsoft.com/en-us/library/ms186865.aspx

Thí dụ như (trong link)


-- To permit log backups, before the full database backup, modify the database
-- to use the full recovery model.
USE master;
GO
ALTER DATABASE AdventureWorks2008R2
SET RECOVERY FULL;
GO
-- Create AdvWorksData and AdvWorksLog logical backup devices.
USE master
GO
EXEC sp_addumpdevice 'disk', 'AdvWorksData',
'Z:\SQLServerBackups\AdvWorksData.bak';
GO
EXEC sp_addumpdevice 'disk', 'AdvWorksLog',
'X:\SQLServerBackups\AdvWorksLog.bak';
GO

-- Back up the full AdventureWorks2008R2 database.
BACKUP DATABASE AdventureWorks2008R2 TO AdvWorksData;
GO
-- Back up the AdventureWorks2008R2 log.
BACKUP LOG AdventureWorks2008R2
TO AdvWorksLog;
GO


Không cần phải có SysAdmin, mà chỉ cần có quyền BACKUP và RESTORE thôi.

Thật sự ra, backup và restore chỉ là những thao tác vỡ lòng. Chỉ cần có một chút xiú kiến thức về CSDL và chịu khó ngồi mò mẫm, đọc tài liệu chừng 15 phút là tìm ra thôi.

Nhưng thiết kế một phương án để hồi phục CSDL (disaster recovery) mới là một điều đòi hỏi nhiều kiến thức.

mailsaveword
29-06-2010, 09:16
Backup Database [Database Name] To Disk = [Path]
---> Example: Backup Database dtb_mail To Disk = 'c:\database\mail.bak'
---> Example ASP : CN.ExeCute("Backup Database dtb_mail To Disk = 'c:\database\mail.bak'")

Restore Database [Database Name] From Disk = [Path]
---> Example: Restore Database dtb_mail From Disk = 'c:\database\mail.bak'
---> Example ASP : CN.ExeCute("Restore Database dtb_mail From Disk = 'c:\database\mail.bak'")