SQL Server Backup

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Lab 4 Manual

SQL Server Backup


The data files, filegroups, and log files that make up a SQL Server database can, and generally should, be
backed up as part of your database backup and recovery strategy. This includes both user and system
databases. There are three broad categories of backup that a DBA can perform: database backups, file
backups and transaction log backups, and within these categories several different types of backup are
available.

1. SQL Server database backups


Activity 1.
1. Open SQL Server Management Studio Express and connect to the SQL server.
2. Expand Databases.
3. Right-click on the database you want to back up, then select Tasks > Back up. (This is not available for
version 2018/2019)
4. On the Back Up Database window, make sure the Database field contains the name of the database you
want to back up.
5. Select the Backup Type. By default, it is Full - leave it set to that.
6. Click Remove to remove the default/last backup file name.
7. Click Add to open the Select Backup Destination window.
8. Click [...] next to the File Name field.
9. On the Locate Database Files window, select the folder where you want the backup file to go. By default,
it is ..\Microsoft SQL Server\MSSQL.1\MSSQL\Backup.
10. In the File Name field, type the name for this backup, with a .bak extension. For
example, xyz_20080221.bak for a backup of the XYZ database created on 21 February 2023.
11. Click OK to close the Locate Database Files window.
12. Click OK to close the Select Backup Destination window.
13. Click OK to start the backup. The progress icon displays in the lower-left corner, and a ‘completed
successfully’ message displays when it's done.
Alternatively, you can run the following Transact-SQL command to back up your database. The path may
be different on your computer:

Database backups – copy into a backup file the data and objects in the primary data file and any secondary
data files.

• Full database backup – backs up all the data and objects in the data file(s) for a given database.

• Differential database backup – backs up any data and objects in data file(s) for a given database that
have changed since the last full backup.
a) Full database backups
Activity 2
1. Expand Databases, and either select a user database or expand System Databases and select a
system database.
2. Right-click the database that you wish to backup, point to Tasks, and then select Back Up....
3. In the Back Up Database dialog box, the database that you selected appears in the drop-down list
(which you can change to any other database on the server).
4. In the Backup type drop-down list, select a backup type - the default is Full.

1. You must perform at least one full database backup before you can perform a differential or a
transaction log backup.
2. Under Backup component, select Database.
3. In the Destination section, review the default location for the backup file (in the ../mssql/data
folder).

You can use the Back up to drop-down list to select a different device. Select Add to add backup
objects and or destinations. You can stripe the backup set across multiple files for increased backup
speed.

To remove a backup destination, select it and select Remove. To view the contents of an existing
backup destination, select it and select Contents.

4. (optional) Review the other available settings under the Media Options and Backup Options pages.

For more information about the various backup options, see General page, Media options page,
and Backup options page.

5. Select OK to start the backup.


6. When the backup completes successfully, select OK to close the SQL Server Management Studio
dialog box.

Additional information
 After creating a full database backup, you can create a differential database backup or
a transaction log backup.
 (optional) You can select the Copy-only backup checkbox to create a copy-only backup. A copy-
only backup is a SQL Server backup that is independent of the sequence of conventional SQL
Server backups. For more information, see Copy-Only Backups (SQL Server). A copy-only backup
isn't available for the Differential backup type.
 The Overwrite media option is disabled on the Media Options page if you're backing up to a URL.
b) Differential database backups

Activity 3.
In the Database list box, verify the database name. You can optionally select a different database from
the list.

1. In the Backup type list box, select Differential.

When you select Differential , verify that the Copy Only Backup check box is cleared.

2. For Backup component, click Database.


3. Either accept the default backup set name suggested in the Name text box, or enter a different
name for the backup set.
4. Optionally, in the Description text box, enter a description of the backup set.
5. Specify when the backup set will expire:
 To have the backup set expire after a specific number of days, click After (the default option),
and enter the number of days after set creation that the set will expire. This value can be
from 0 to 99999 days; 0 days means the backup set will never expire.

The default value is set in the Default backup media retention (in days) option of the Server
Properties dialog box (Database Settings page). To access this, right-click the server name in
Object Explorer and select properties; then select the Database Settings page.

 To have the backup set expire on a specific date, click On, and enter the date on which the
set will expire.
6. Choose the type of backup destination by clicking Disk or Tape. To select the path of up to 64 disk
or tape drives containing a single media set, click Add. The selected paths are displayed in
the Backup to list box.

To remove a backup destination, select it and click Remove. To view the contents of a backup
destination, select it and click Contents.

7. To view or select the advanced options, click Options in the Select a page pane.
8. Select an Overwrite Media option, by clicking one of the following:
 Back up to the existing media set

For this option, click either Append to the existing backup set or Overwrite all existing
backup sets. Optionally, check the Check media set name and backup set expiration check
box and, optionally, enter a name in the Media set name text box. If no name is specified, a
media set with a blank name is created. If you specify a media set name, the media (tape or
disk) is checked to see if the actual name matches the name you enter here.

If you leave the media name blank and check the box to check it against the media, success
will equal the media name on the media also being blank.
 Back up to a new media set, and erase all existing backup sets

For this option, enter a name in the New media set name text box, and, optionally, describe
the media set in the New media set description text box.

9. In the Reliability section, optionally, check:


 Verify backup when finished.
 Perform checksum before writing to media, and, optionally, Continue on checksum error.
For information about checksums, see Possible Media Errors During Backup and Restore (SQL
Server).
10. If you are backing up to a tape drive (as specified in the Destination section of the General page),
the Unload the tape after backup option is active. Clicking this option activates the Rewind the
tape before unloading option.

Note

The options in the Transaction log section are inactive unless you are backing up a transaction log
(as specified in the Backup type section of the General page).

11. SQL Server 2008 Enterprise and later supports backup compression. By default, whether a backup
is compressed depends on the value of the backup-compression default server configuration
option. However, regardless of the current server-level default, you can compress a backup by
checking Compress backup, and you can prevent compression by checking Do not compress
backup.

2. File backups
In addition to the database backups discussed previously, it's also possible to take file backups. Whereas
database backups back up all data files for a given database, with file backups we can back up just a single,
specific data file, or a specific group of data files (for example, all the data files in a particular filegroup).
File backups can decrease the time and disk space needed for the backup strategy and also, in certain
circumstances, make disaster recovery much quicker.

a) Full and differential file backups


1. In the Database list, verify the database name. You can optionally select a different database from
the list.
2. In the Backup type list, select Full or Differential.
3. For the Backup component option, click File and Filegroups.
4. In the Select Files and Filegroups dialog box, select the files and filegroups you want to back up.
You can select one or more individual files or check the box for a filegroup to automatically select
all the files in that filegroup.
5. Either accept the default backup set name suggested in the Name text box, or enter a different
name for the backup set.
6. (optional) In the Description text box, enter a description of the backup set.
7. Specify when the backup set will expire:
 To have the backup set expire after a specific number of days, click After (the default option)
and enter the number of days after set creation that the set will expire. This value can be
from 0 to 99999 days; a value of 0 days means that the backup set will never expire.

The default value is set in the Default backup media retention (in days) option of the Server
Properties dialog box (Database Settings page). To access this option, right-click the server
name in Object Explorer and select properties; then select the Database Settings page.

 To have the backup set expire on a specific date, click On, and enter the date on which the
set will expire.
8. Choose the type of backup destination by clicking Disk or Tape. To select the paths of up to 64 disk
or tape drives that contain a single media set, click Add. The selected paths are displayed in
the Backup to list.

Note

To remove a backup destination, select it and click Remove. To view the contents of a backup
destination, select it and click Contents.

9. To view or select the advanced options, click Options in the Select a page pane.
10. Select an Overwrite Media option, by clicking one of the following:
 Back up to the existing media set

For this option, click either Append to the existing backup set or Overwrite all existing
backup sets.

For information about backing up to an existing media set, see Media Sets, Media Families,
and Backup Sets (SQL Server).

o (optional) Select Check media set name and backup set expiration to cause the backup
operation to verify the date and time at which the media set and backup set expire.
o (optional) Enter a name in the Media set name text box. If no name is specified, a media
set with a blank name is created. If you specify a media set name, the media (tape or disk)
is checked to see whether the actual name matches the name that you enter here.

If you leave the media name blank and check the box to check it against the media, success
will equal the media name on the media also being blank.

 Back up to a new media set, and erase all existing backup sets

For this option, enter a name in the New media set name text box, and, optionally, describe
the media set in the New media set description text box.

For more information about creating a new media set, see Media Sets, Media Families, and
Backup Sets (SQL Server).

11. (optional) In the Reliability section, check:


 Verify backup when finished.
 Perform checksum before writing to media, and (optional) Continue on checksum error.

For more information about checksums, see Possible Media Errors During Backup and
Restore (SQL Server).

12. If you are backing up to a tape drive (as specified in the Destination section of the General page),
the Unload the tape after backup option is active. Clicking this option enables the Rewind the tape
before unloading option.

Note

The options in the Transaction log section are inactive unless you are backing up a transaction log
(as specified in the Backup type section of the General page).

13. SQL Server 2008 Enterprise and later versions support backup compression. By default, whether a
backup is compressed depends on the value of the backup-compression default server
configuration option. However, regardless of the current server-level default, you can compress a
backup by checking Compress backup, and you can prevent compression by checking Do not
compress backup.

To view the current backup compression default, see View or Configure the backup compression
default Server Configuration Option

3. SQL Server transaction log backups


1. After connecting to the appropriate instance of the SQL Server Database Engine, in Object
Explorer, click the server name to expand the server tree.
2. Expand Databases, and, depending on the database, either select a user database or
expand System Databases and select a system database.
3. Right-click the database, point to Tasks, and then click Back Up. The Back Up Database dialog box
appears.
4. In the Database list box, verify the database name. You can optionally select a different database
from the list.
5. Verify that the recovery model is either FULL or BULK_LOGGED.
6. In the Backup type list box, select Transaction Log.
7. (optional) Select Copy Only Backup to create a copy-only backup. A copy-only backup is a SQL
Server backup that is independent of the sequence of conventional SQL Server backups, see Copy-
Only Backups (SQL Server).

Note

When the Differential option is selected, you cannot create a copy-only backup.

8. Either accept the default backup set name suggested in the Name text box, or enter a different
name for the backup set.
9. (optional) In the Description text box, enter a description of the backup set.
10. Specify when the backup set will expire:
 To have the backup set expire after a specific number of days, click After (the default
option), and enter the number of days after set creation that the set will expire. This value
can be from 0 to 99999 days; a value of 0 days means that the backup set will never expire.

The default value is set in the Default backup media retention (in days) option of
the Server Properties dialog box (Database Settings page). To access this dialog box, right-
click the server name in Object Explorer and select properties; then select the Database
Settings page.

 To have the backup set expire on a specific date, click On, and enter the date on which the
set will expire.
11. Choose the type of backup destination by clicking Disk, URL or Tape. To select the paths of up to
64 disk or tape drives containing a single media set, click Add. The selected paths are displayed in
the Backup to list box.

To remove a backup destination, select it and click Remove. To view the contents of a backup
destination, select it and click Contents.

12. To view or select the advanced options, click Options in the Select a page pane.
13. Select an Overwrite Media option, by clicking one of the following:
 Back up to the existing media set

For this option, click either Append to the existing backup set or Overwrite all existing
backup sets, see Media Sets, Media Families, and Backup Sets (SQL Server).

o (optional) Select Check media set name and backup set expiration to cause the backup
operation to verify the date and time at which the media set and backup set expire.
o (optional) Enter a name in the Media set name text box. If no name is specified, a media
set with a blank name is created. If you specify a media set name, the media (tape or
disk) is checked to see whether the actual name matches the name you enter here.

If you leave the media name blank and check the box to check it against the media, success
will equal the media name on the media also being blank.

 Back up to a new media set, and erase all existing backup sets

For this option, enter a name in the New media set name text box, and, optionally,
describe the media set in the New media set description text box, see Media Sets, Media
Families, and Backup Sets (SQL Server).

14. In the Reliability section, optionally, check:


 Verify backup when finished.
 Perform checksum before writing to media and (optional) Continue on checksum error.
For information on checksums, see Possible Media Errors During Backup and Restore (SQL
Server).

15. In the Transaction log section:


 For routine log backups, keep the default selection, Truncate the transaction log by
removing inactive entries.
 To back up the tail of the log (the active log), check Back up the tail of the log, and leave
database in the restoring state.

A tail-log backup is taken after a failure to back up the tail of the log in order to prevent
work loss. Back up the active log (a tail-log backup) both after a failure, before beginning to
restore the database, or when failing over to a secondary database. Selecting this option is
equivalent to specifying the NORECOVERY option in the BACKUP LOG statement of
Transact-SQL.

For more information about tail-log backups, see Tail-Log Backups (SQL Server).

16. If you are backing up to a tape drive (as specified in the Destination section of the General page),
the Unload the tape after backup option is active. Clicking this option activates the Rewind the
tape before unloading option.
17. SQL Server 2008 Enterprise and later supports backup compression. By default, whether a backup
is compressed depends on the value of the backup-compression default server configuration
option. However, regardless of the current server-level default, you can compress a backup by
checking Compress backup, and you can prevent compression by checking Do not compress
backup.

To view the current backup compression default, see View or Configure the backup compression
default Server Configuration Option.

Back Up the Transaction Log When the Database Is Damaged


(SQL Server)

1. In the Database list box, verify the database name. You can optionally select a different database
from the list.
2. Verify that the recovery model is either FULL or BULK_LOGGED.
3. In the Backup type list box, select Transaction Log.
4. Leave Copy Only Backup deselected.
5. In the Backup set area, either accept the default backup set name suggested in the Name text box,
or enter a different name for the backup set.
6. In the Description text box, enter a description for the tail-log backup.
7. Specify when the backup set will expire:
 To have the backup set expire after a specific number of days, click After (the default option),
and enter the number of days after set creation that the set will expire. This value can be
from 0 to 99999 days; a value of 0 days means that the backup set will never expire.
The default value is set in the Default backup media retention (in days) option of the Server
Properties dialog box (Database Settings page). To access this dialog box, right-click the
server name in Object Explorer and select properties; then select the Database
Settings page.

 To have the backup set expire on a specific date, click On, and enter the date on which the
set will expire.
8. Choose the type of backup destination by clicking Disk or Tape. To select the paths of up to 64 disk
or tape drives containing a single media set, click Add. The selected paths are displayed in
the Backup to list box.

To remove a backup destination, select it and click Remove. To view the contents of a backup
destination, select it and click Contents.

9. On the Options page, select an Overwrite Media option, by clicking one of the following:
 Back up to the existing media set

For this option, click either Append to the existing backup set or Overwrite all existing
backup sets.

Optionally, select Check media set name and backup set expiration to cause the backup
operation to verify the date and time at which the media set and backup set expire.

Optionally, enter a name in the Media set name text box. If no name is specified, a media set
with a blank name is created. If you specify a media set name, the media (tape or disk) is
checked to see whether the actual name matches the name you enter here.

If you leave the media name blank and check the box to check it against the media, success
will equal the media name on the media also being blank.

 Back up to a new media set, and erase all existing backup sets

For this option, enter a name in the New media set name text box, and, optionally, describe
the media set in the New media set description text box.

10. For more information about media set options, see Media Sets, Media Families, and Backup Sets
(SQL Server).
11. In the Reliability section, optionally, check:
 Verify backup when finished.
 Perform checksum before writing to media.
 Continue on checksum error

For information on checksums, see Possible Media Errors During Backup and Restore (SQL Server).

12. In the Transaction log section, check Back up the tail of the log, and leave database in the
restoring state.
This is equivalent to specifying the following BACKUP statement:

BACKUP LOG <database_name> TO <backup_device> WITH NORECOVERY

Important

At restore time, the Restore Database dialog box displays the type of a tail-log backup
as Transaction Log (Copy Only).

13. If you are backing up to a tape drive (as specified in the Destination section of the General page),
the Unload the tape after backup option is active. Clicking this option activates the Rewind the
tape before unloading option.
14. SQL Server 2008 Enterprise and later supports backup compression. By default, whether a backup
is compressed depends on the value of the backup-compression default server configuration
option. However, regardless of the current server-level default, you can compress a backup by
checking Compress backup, and you can prevent compression by checking Do not compress
backup.

SQL Server Recovery Model


1. After connecting to the appropriate instance of the SQL Server Database Engine, in Object Explorer,
select the server name to expand the server tree.
2. Expand Databases, and, depending on the database, either select a user database or
expand System Databases and select a system database.
3. Right-click the database, and then select Properties, which opens the Database Properties dialog
box.
4. In the Select a page pane, select Options.
5. The current recovery model is displayed in the Recovery model list box.
6. Optionally, to change the recovery model select a different model list. The choices are Full, Bulk-
logged, or Simple.
7. Select OK.

Task
 View the recovery model and change the recovery model by using Transact-SQL
 Restore an earlier disk backup with a new database name where the original database still exists
 Restore a full database backup
 Restore an earlier disk backup over an existing database
 Restore a striped backup over an existing database and a shared access signature exists.

You might also like