# BACKUP - RESTORE SQL

## BACKUP

### **Full/Database**

```sql
Backup database <TEN DATABASE> to disk = '<DUONG DAN FILE BACKUP + TEN FILE>'
```

### **Differential/Incremental**

```sql
Backup database <TEN DATABASE> to
disk = '<DUONG DAN FILE BACK UP + TEN FILE>' with differential
```

### **Transactional Log/Log**

```sql
Backup log <TEN DATABASE> to disk = '<DUONG DAN FILE BACKUP + TEN FILE>'
```

### Ví dụ:&#x20;

```sql
Backup database DTECH_HN to disk = 'D:\DTECH\BACKUP_DTECH_HN.bak'
```

### RESTORE

### Tạo ra 1 database mới từ file backup

```sql
// Ví dụ tạo ra database TEST từ Database DTECHNEW
ALTER DATABASE [TEST] 
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE
--use master
RESTORE DATABASE [TEST] 
FROM DISK = N'D:\DTECH\BACKUP\DTECHNEW.bak'   -- Đường dẫn file backup của DTECHNEW
WITH FILE = 1,
 REPLACE,
MOVE N'DtechPRO' TO N'D:\DTECH\DATA\TEST.mdf', -- Đường dẫn file mdf của database TEST
MOVE N'DtechPRO_log' TO N'D:\DTECH\DATA\TEST_Log.ldf'  -- Đường dẫn file log của database TEST
,
 NOUNLOAD,  REPLACE,  STATS = 10
ALTER DATABASE [TEST]  SET MULTI_USER
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kythuat.dtechvn.com/sql-server/backup-restore-sql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
