Database Experiment 10 (Backup and Restore)

1. Create a full database backup set SM.bak for database SM.

Create a full backup for the first time:

If the above situation occurs, you need to go to the properties of the database (sm) to be backed up and set the recovery mode from "simple" to "full". This backup will add a "transaction log" backup type.

Then we start the backup:

2. Create a new test table in the database SM, customize the content, and then create a differential backup for the database SM.

In fact, it is to change the backup type from "full" to "differential".

create table test(
	sno char(20) not null,
	sname char(20),
	sage smallint,
	primary key(sno)
);
insert into test values('001','李白',20);
insert into test values('002','陈平',24);

3. Insert some records into the test table in the database SM, and then create a transaction log backup for the database SM.

insert into test values('003','沈长青',28);
insert into test values('004','张荣芳',18);

4. Restore the database to the original state of SM.

After restoration, we search for test:

Proof of successful restoration to original state

5. Restore the database to the state after creating the test table.

6. Restore the database to the state after inserting records into the test table.

7. Use T-SQL to realize the above functions.

-- 完整备份
backup database sm 
to disk='D:\大二\数据库原理\实验系列\第14周实验10\SM.bak'

-- 差异备份
backup database sm 
to disk='D:\大二\数据库原理\实验系列\第14周实验10\SM.bak'
with differential

-- 事务日志备份
backup log sm 
to disk='D:\大二\数据库原理\实验系列\第14周实验10\SM.bak'

-- 完整备份还原
restore database sm
from disk='D:\大二\数据库原理\实验系列\第14周实验10\SM.bak'
with file=1,replace,norecovery

-- 差异备份还原
restore database sm
from disk='D:\大二\数据库原理\实验系列\第14周实验10\SM.bak'
with file=2,norecovery

-- 事务日志备份还原
restore log sm
from disk='D:\大二\数据库原理\实验系列\第14周实验10\SM.bak'
with file=3,recovery

8. Set up a regular backup plan for the database SM, requiring regular backups.

First check if the sql server agent is started, if not, start it!

Admin under Server has a maintenance plan;

Right click on it and select Maintenance Plan Wizard;

Here select "Schedule each task separately", and then my full backup will be once a week, and the differential backup will be once a day.

Select the database to be regularly backed up here

Schedule each task individually

On the way, you will press the next step many times;

After planning, is the placement of reports

Successfully set up a regular backup plan!

If you fail, you can only get ahead, and it is generally easy to make mistakes in planning.

I hope my articles are useful to you, and your likes and collections are a great motivation for my creation!

Guess you like

Origin blog.csdn.net/m0_64206989/article/details/130818901