TM07 Database Backup and Recovery
TM07 Database Backup and Recovery
The design of a DBMS depends on its architecture. Selecting the correct Database
Architecture helps in quick and secure access to data. The architecture of a DBMS can be
seen as either single tier or multi-tier. The tiers are classified as follows:
1.1.1. Single tier architecture
The simplest of Database Architecture are 1 tier where the Client, Server, and Database all
reside on the same machine. In other word, it keeps all of the elements of an application,
including the interface, Middleware and back-end data, in one place. Developers see these
types of systems as the simplest and most direct way.
The database is directly available to the user. It means the user can directly sit on the
DBMS and uses it.
Any changes done here will directly be done on the database itself. It doesn't provide
a handy tool for end users.
The 1-Tier architecture is used for development of the local application, where
programmers can directly communicate with the database for the quick response.
The direct communication takes place between client and server. There is no intermediate
between client and server.
The user interfaces and application programs are run on the client-side.
The server side is responsible to provide the functionalities like: query processing and
transaction management.
To communicate with the DBMS, client-side application establishes a connection with the
server side 2 Tier architecture provides added security to the DBMS as it is not exposed to
the end user directly.
This architecture has different usages with different applications. It can be used in web
applications and distributed applications. 3-tier architecture has following layers;
Database server (Data) Tier − at this tier, the database resides along with its query
processing languages.
Application (Middle) Tier – also called business logic layer and it processes
functional logic, constraint, and rules before passing data to the user or down to the
DBMS.
For a user, this application tier presents an abstracted view of the database. End-users
are unaware of any existence of the database beyond the application.
User (Presentation) Tier − End-users operate on this tier and they know nothing about
any existence of the database beyond this layer. Example your PC, Tablet, Mobile,
etc.)
The goal of Three-tier architecture is:
To separate the user applications and physical database
Proposed to support DBMS characteristics
Program-data independence
Support of multiple views of the data
Power Failure
Power failures can lead to hardware failure. The affected hardware components could be
cables, power supplies or storage devices.
Disk Failure
While power failures can lead to disk failure, they can also fail due to physical damage or a
logical failure. Such failures are due to head crashes or unreadable media, resulting in the
loss of parts of secondary storage.
Software Corruption
Companies using traditional in-house IT infrastructures are more at risk of software
corruption than those relying on cloud-based services. While cloud vendors provide
flexibility and scalability of resources, traditional IT environments have fixed sets of
hardware resources which they manually upgrade.
Repeated crashing can especially cause serious damage if the user is working on a database.
These are logical errors in the program that is accessing the database, which cause one or
more transactions to fail.
Virus Infection
An enterprise cannot operate safely without the use of a good security solution. Cyber-attacks
are the biggest threat a company faces today and it is imperative that the security solution
performs real-time scanning.
Natural Disasters
Natural disasters such as fire, floods, earthquake, tsunami, etc have the ability to destroy the
entire infrastructure.
Hardware Failure
Hardware failure may include memory errors, disk crashes, bad disk sectors, disk full error
and so on.
System Crash
System crashes are due to hardware or software errors, resulting in the loss of main memory.
This could be the situation that the system has entered an undesirable state.
Network Failure
Network failure can occur while using a Client-server configuration or distributed database
system where multiple database servers are connected y common network. •
Sabotages
These are failures due to international corruption or destruction of data, hardware or users.
1.3 OHS
Occupational Health and Safety (OHS) requirements for database backup and recovery are
crucial to ensure the well-being and safety of individuals involved in managing and
maintaining databases.
Ensure that personnel responsible for database backup and recovery are adequately trained
and competent in their roles.
Ergonomics
Workload Management
Monitor and manage the workload of personnel involved in database backup and recovery to
prevent stress and burnout.
Emergency Procedures
Establish clear emergency procedures for unexpected situations during database backup and
recovery processes. Ensure that personnel are aware of evacuation plans and procedures in
case of emergencies.
Security Measures
Implement security measures to protect personnel from potential cybersecurity threats during
backup and recovery operations.
Equipment Safety
Regularly inspect and maintain all equipment used in database backup and recovery to ensure
it meets safety standards.
Health Monitoring
Implement health monitoring programs to identify and address any health issues among
personnel promptly.
Communication Protocols
Establish effective communication protocols to ensure that team members can communicate
efficiently during backup and recovery operations. Encourage open communication about
any concerns related to health and safety.
Restore is the process of retrieving data from a backup. This might mean copying data from
backup media to an existing device or to a new device. It also could mean copying data from
the cloud to a local device or from one cloud to another.
Recovery refers to the process of restoring data and operations (e.g., returning a server to
normal working order following hardware failure).
Restore and recovery times can vary widely depending on the backup format and data
recovery methods you choose. Additionally, restore needs also vary (e.g., restoring a single
file vs. an entire server). Finally, critical data may live on workstations, local servers, and in
the cloud. These are important considerations when selecting a backup and recovery solution.
The most common type of database backups are:
- Logical backup - backup of data is stored in a human-readable format like SQL
- Physical backup - backup contains binary data
There are different types of backup, and each backup process works differently.
Table 2.1. Comparison of backup type
A comparison of different types of backup
Backup 3 All data All data Selected Changes from backup 2 Changes from backup 1
Backup 4 All data All data Selected Changes from backup 3 Changes from backup 1
1. Full backups
The most basic and complete type of backup operation is a full backup. As the name implies,
this type of backup makes a copy of all data to a storage device, such as a disk or tape. The
primary advantage to performing a full backup during every operation is that a complete
copy of all data is available with a single set of media. This results in a minimal time to
restore data, a metric known as a recovery time objective. However, the disadvantages are
that it takes longer to perform a full backup than other types (sometimes by a factor of 10 or
more), and it requires more storage space.
Thus, full backups are typically run only periodically. Typically, backup operations employ a
full backup in combination with either incremental or differential backups.
The benefit of an incremental backup is that it copies a smaller amount of data than a full.
Thus, these operations will have a faster backup speed, and require fewer medium to store
the backup.
Do the right or appropriate backup for your organization. For organizations with small data sets,
running a daily full backup provides a high level of protection without much additional storage space
costs. Larger organizations or those with more data or server volume find that running a weekly full
backup, coupled with either daily incremental backups or differential backups, provides a better
option. Using differentials provides a higher level of data protection with less restore time for most
scenarios and a small increase in storage capacity. For this reason, using a strategy of weekly full
backups with daily differential backups is a good option for many organizations.
From these types of backup, it is possible to develop an approach for comprehensive data
protection. An organization often uses one of the following backup settings:
Full daily
It is mostly accomplished before the beginning of the day or at the end of the day.
Cold backups consume fewer resources but have a limitation. The database cannot be
accessed when the backup operation is in progress.
The advantage of this method is that users are still able to access the system during the
backup. However, if the server crashes, the backup will also be gone. The risk that comes
with a hot backup is that the data may be modified during the process, resulting in
inconsistent data.
The most important advantage here is the capability to continue business operations while
the backup is in progress. The database is available at all times, and hence the business can
continue as usual.
2.6.Disk mirroring
Disk mirroring, also known as RAID 1, is the replication of data to two or more disks. Disk
mirroring is a strong option for data that needs high availability because of its quick recovery
time. It's also helpful for disaster recovery because of its immediate failover capability. Disk
mirroring requires at least two physical drives. If one hard drive fails, an organization can use
the mirror copy. While disk mirroring offers comprehensive data protection, it requires a lot
of storage capacity.
Offsite backup is the replication of the data to a server which is separated geographically
from a production systems site. Offsite data backup may also be done via direct access, over
Wide Area Network (WAN). An offsite backup is a backup process or facility that stores
backup data or applications external to the organization or core IT environment.
It is similar to a standard backup process, but uses a facility or storage media that is not
physically located within the organization’s core infrastructure.
Offsite backups are primarily is used in data backup and disaster-recovery measures. The
core objective behind storing and maintaining data at a backup facility is to:
Onsite storage usually entails storing important data on a periodic basis on local storage
devices, such as hard drives, DVDs, magnetic tapes, or CDs. Offsite storage requires storing
important data on a remote server, usually via the Internet, although it can also be done via
direct access.
Advantages of onsite storage:
Immediate access to data
Less expensive
Internet access not needed
Control of your own data security
Performance improvement
Disadvantage of onsite storage;
- In the event of a catastrophic event, onsite data storage can be destroyed.
- Storage can be extremely expensive depending on the size of the storage array.
- Storage device will need to be managed, maintained, and upgraded in-house.
Unit Three: Database Recovery Points & Procedures
3.1.Database recovery point
Database recovery is the process of restoring the database to a correct (consistent) state in the
event of a failure. In other words, it is the process of restoring the database to the most recent
consistent state that existed shortly before the time of system failure.
There are many situations in which a transaction may not reach a commit or abort point.
Some of them include;
In any of these situations, data in the database may become inconsistent or lost.
- It should check the states of all the transactions, which were being executed.
- A transaction may be in the middle of some operation; the DBMS must ensure the
atomicity of the transaction in this case.
- It should check whether the transaction can be completed now or it needs to be rolled
back.
Transaction log plays an important role for database recovery and bringing the database in a
consistent state in the event of failure. Transactions represent the basic unit of recovery in a
database system. The recovery manager guarantees the atomicity and durability properties of
transactions in the event of failures. During recovery from failure, the recovery manager
ensures that either all the effects of a given transaction are permanently recorded in the
database or none of them are recorded. A transaction begins with successful execution of a
<T, BEGIN>” (begin transaction) statement.
So, recovery techniques which are based on deferred update and immediate update or
backing up data can be used to stop loss in the database.
Immediate Update: As soon as a data item is modified in cache, the disk copy is
updated.
Deferred Update: All modified data items in the cache are written either after a
transaction ends its execution or after a fixed number of transactions have completed
their execution.
Shadow update: The modified version of a data item does not overwrite its disk copy
but is written at a separate disk location.
In-place update: The disk version of the data item is overwritten by the cache version.
This transaction log Includes information helpful to the recovery process such as: A
transaction identifier, the date and time, the user running the transaction, before
images and after images.
Before Image: A copy of the table record (or data item) before it was changed by the
transaction.
After Image: A copy of the table record (or data item) after it was changed by the
transaction.
The Automated Recovery process uses both rollback and roll forward to restore the
database.
Rollback: Undo any partially completed transactions (ones in progress when the crash
occurred) by applying the before images to the database. UNDO the transactions in
progress at the time of failure.
Roll forward: Redo the transactions by applying the after images to the database. This is
done for transactions that were committed before the crash. REDO the transactions that
successfully complete but did not write to the physical disk.
Checkpoint is a mechanism where all the previous logs are removed from the system and
stored permanently in a storage disk. Checkpoint declares a point before which the DBMS
was in consistent state, and all the transactions were committed. Checkpoints can also be
taken (less time consuming) in between database saves.
The DBMS flushes all pending transactions and writes all data to disk and transaction log.
Database can be recovered from the last checkpoint in much less time.
The ability to perform this kind of recovery depends on a recovery model set for the
database. The database must be in either the Full or Bulk-Logged recovery model. In case the
Simple recovery mode was used, this recovery method is not possible.
In case of using the Bulk-Logged recovery model some errors may occur and recovery to a
point in time might fail. An error will be thrown in case when any bulk-logged operations
were performed. As such operations are minimally logged; there is not sufficient data in a
particular transaction log.
When you issue a RESTORE DATABASE or RESTORE LOG command the WITH
RECOVERY option is used by default.
This option is not on by default, so if you need to recover a database by restoring multiple
backup files and forget to use this option you have to start the backup process all over again.
The most common example of this would be to restore a "Full" backup and one or more
"Transaction Log" backups.
The first command does the restore and leaves the database in a restoring state and second
command restores the transaction log backup and then makes the database useable.
RESTORE DATABASE <<DatabaseName>>FROM DISK = 'C:\BackupName.BAK'
WITH NORECOVERY
GO
RESTORE LOG <<DatabaseName>> FROM DISK = 'C:\BackupName.TRN'
WITH RECOVERY
GO
This restores the first two backups using NORECOVERY and then RECOVERY for the last
restore.
RESTORE DATABASE <<DatabaseName>> FROM DISK = 'C:\ BackupName.BAK'
WITH NORECOVERY
GO
RESTORE LOG <<DatabaseName>> FROM DISK = 'C:\ BackupName.TRN'
WITH NORECOVERY
GO
RESTORE LOG <<DatabaseName>> FROM DISK = 'C:\ BackupName1.TRN'
WITH RECOVERY
GO
Restore full backup, latest differential and two transaction log backups
This restores the first three backups using NORECOVERY and then RECOVERY for the
last restore.
RESTORE DATABASE <<DatabaseName>> FROM DISK = 'C:\ BackupName.BAK'
WITH NORECOVERY
GO
RESTORE DATABASE <<DatabaseName>> FROM DISK = 'C:\ BackupName.DIF'
WITH NORECOVERY
GO
RESTORE LOG <<Database Name>> FROM DISK = 'C:\ BackupName.TRN'
WITH NORECOVERY
GO
RESTORE LOG <<DatabaseName>> FROM DISK = 'C:\ BackupName1.TRN'
WITH RECOVERY
GO