Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example of database operation script for SQL

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

-- execute statement:

Restore headeronly from tapedump1

In the returned result set

Through:

The location of the Position backup set in the volume, which is used to distinguish each backup (backup number)

Start date and time of the BackupStartDate backup operation.

Date and time when the BackupFinishDate backup operation was completed.

These two fields can determine which backup this is.

Then, during the restore, you can restore the backup made at the specified time with a statement similar to the following:

Restore database pubs

From tapedump1 with file=N-- n is the backup number queried above.

-- full backup

Backup Database NorthwindCS

To disk='G:\ Backup\ NorthwindCS_Full_20070908.bak'

-- differential backup

Backup Database NorthwindCS

To disk='G:\ Backup\ NorthwindCS_Diff_20070908.bak'

With Differential

-- Log backup, which truncates logs by default

Backup Log NorthwindCS

To disk='G:\ Backup\ NorthwindCS_Log_20070908.bak'

-- Log backup without truncating the log

Backup Log NorthwindCS

To disk='G:\ Backup\ NorthwindCS_Log_20070908.bak'

With No_Truncate

-truncated logs are not retained

Backup Log NorthwindCS

With No_Log

-- or

Backup Log NorthwindCS

With Truncate_Only

-- the log file will not become smaller after truncation

Contraction can be carried out if necessary

-- File backup

Exec Sp_Helpdb NorthwindCS-View data files

Backup Database NorthwindCS

File='NorthwindCS'-logical name of the data file

To disk='G:\ Backup\ NorthwindCS_File_20070908.bak'

-- filegroup backup

Exec Sp_Helpdb NorthwindCS-View data files

Backup Database NorthwindCS

FileGroup='Primary'-logical name of the data file

To disk='G:\ Backup\ NorthwindCS_FileGroup_20070908.bak'

With init

-split backups to multiple destinations

-- you are not allowed to lose any targets during recovery.

Backup Database NorthwindCS

To disk='G:\ Backup\ NorthwindCS_Full_1.bak'

, disk='G:\ Backup\ NorthwindCS_Full_2.bak'

-- Mirror backup

Every goal is the same.

Backup Database NorthwindCS

To disk='G:\ Backup\ NorthwindCS_Mirror_1.bak'

Mirror

To disk='G:\ Backup\ NorthwindCS_Mirror_2.bak'

With Format-format the target the first time you make a mirror backup

-- Mirror backup to local and remote

Backup Database NorthwindCS

To disk='G:\ Backup\ NorthwindCS_Mirror_1.bak'

Mirror

To disk='\\ 192.168.1.200\ Backup\ NorthwindCS_Mirror_2.bak'

With Format

-- generate a backup file every day

Declare @ Path Nvarchar 2000

Set @ Path ='G:\ Backup\ NorthwindCS_Full_'

+ Convert (Nvarchar,Getdate (), 112) + '.bak'

Backup Database NorthwindCS

To disk=@Path

-- from NoRecovery or

-- Standby mode restores the database to be available

Restore Database NorthwindCS_Bak

With Recovery

-- View the backup set in the target backup

Restore HeaderOnly

From Disk ='G:\ Backup\ NorthwindCS_Full_20070908.bak'

-- View the information of the first backup set of the target backup

Restore FileListOnly

From Disk ='G:\ Backup\ NorthwindCS_Full_20070908_2.bak'

With File=1

-- View the volume label of the target backup

Restore LabelOnly

From Disk ='G:\ Backup\ NorthwindCS_Full_20070908_2.bak'

-- backup Settings password protected backup

Backup Database NorthwindCS

To disk='G:\ Backup\ NorthwindCS_Full_20070908.bak'

With Password = '123 hundred and thirty-three minutes init

Restore Database NorthwindCS

From disk='G:\ Backup\ NorthwindCS_Full_20070908.bak'

With Password = '123'

RESTORE HEADERONLY FROM Tape ='\.\ tape0' WITH NOUNLOAD

-this tries to fetch the header information from

The tape for a specified amount of time.

Step 4: Obtain the list of files present in the backup set/media.

RESTORE FILELISTONLY FROM Tape ='\\.\ tape0' WITH NOUNLOAD, FILE = (file_number)

Step 5: Perform the actual restore operation.

RESTORE DATABASE [Database name] FROM DISK = Tape ='\\.\ tape0'

WITH FILE = (file_number), NORECOVERY, NOUNLOAD, STATS = (percentage)

In GUI this fails for large databases due to the fact that certain operations

Like the below sequence have a built-in timeout of 20 seconds.

Right click on a database > Tasks > > Restore > > Database > > From Device > >

Click on button > Backup Media = TAPE > > Add > > Select Backup tape > > OK > > OK.

The timeout will happen on the "Specify Backup" dialog.

This timeout is to prevent these dialog boxes from hanging forever when

There is no tape present in the drive.

If you run the "RESTORE HEADERONLY" command from Tsql, you can see that it

Takes several minutes to complete which is much longer than the 20 second timeout for GUI.

To work around the issue, we can need to use T-SQL from Management Studio.

For the restore:

RESTORE DATABASE

FROM TAPE ='\.\ tape0'

WITH

NOREWIND

NOUNLOAD

STATS = 1

GO

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report