0% found this document useful (0 votes)
37 views54 pages

Chapter 4 Backup & Recovery

Uploaded by

neeltest1203
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views54 pages

Chapter 4 Backup & Recovery

Uploaded by

neeltest1203
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 54

Ch.

4 Backup & Recovery

CO2-Describe different network file system and different backup and


recovery
Introduction to backup

• Backup is copy of file system, files,part of files stored onto another


meduim that can be used later to recreate the original.
• The medium used for backup can be tape,floppy disk,secondary or
removable HDD
• Data is imp for any organization
• Data can be any form
• The availability of data at all time is very imp.
• Solution=backup
• It is always a good practice to keep on backing up data on our
computers
• Backup can either be done manually or by using different backup
tools
• Many backup tools have different features that allow users to
configure the type of backup, time of backup, what to backup, logging
backup activities and many more
Why backup?
• Loss of data
• Due to human error
• Hardware failure
• Bad software
• Natural disaster

• rm –r
• Multi user and multi tasking OS
What is archieving
• Data archiving is the process of moving data that is no longer actively
used
• An archive is a inactive information, in any format, is securely stored
for long periods of time.
• Repository- is a central place in which an aggregation of data is kept
and maintained in an organized way.
• It can include a simple list of files or files organized under a directory
or catalog structure (depending on how a particular program supports
archiving).
Difference in Backup and Archiving
• Backup refers to the process of creating copies of data to ensure its
availability and recoverability in case of data loss, system failures,
hardware malfunctions, accidental deletions, or other disasters.
• Key characteristics of backups:
• Recoverability:
• Frequent Updates:
• Retention
• Data Integrity
• Archiving involves the process of preserving data for long-term
storage and historical reference. Archived data is typically data that is
no longer actively used but needs to be retained for legal, regulatory,
historical, or business reasons. Archives focus on storing data
efficiently and securely while making it accessible when needed.
• Long-Term Storage:
• Limited Updates
• Data Reduction:
• backups are focused on ensuring data availability and recoverability in
case of data loss or system failures, while archives are focused on
preserving data for the long term, often to meet legal or regulatory
obligations. Both concepts are crucial for effective data management
and protection, and organizations often implement both backup and
archiving strategies as part of their data lifecycle management plans.
• Archived data is not a copy, but rather inactive and rarely altered data
that needs to be retained for long periods of time.
• Rather than stored in blocks, archived data is usually stored as a file or
object that can be stored with metadata
Backup Archive

The original data remains in place, Archived data is moved from its
Data Storage Method while a backup copy is stored in original location to an archive
another location storage location

Backed up data is constantly Once you create an archive, you do


Data State
changing not modify it

You periodically delete or overwrite


Data archives are designed for long-
Data Retention Policy data backups that are too old to be
term storage
useful

Hot cloud storage or easily


Storage Type Cold cloud storage or tape archives
accessible local storage locations
Archive storage options

• Archive storage typically needs to be able to store large amounts of


data, for long periods of time at a low cost.
• Tape: Tape is an effective data storage archival format because of its
low cost.
• Data Access rate is less
• Disk: Hard disk drives can be used as archive storage
• Cloud: The cloud is a favourable archival option because it can easily
scale and removes the cost of hardware, power and cooling.
Activity 1 Define Backup
Activity 2 Define Archive
Qualities of Good Backup
• Reliability
• Speed
• Storage Space
• Availability
• Look for scalable storage
• Disaster recovery
• Backup security
• Schedule backup/Frequency
• Volumes.
• Coverage
• Testing
Selecting backup meduim
Steps to Perform Backup
• Identify What to Backup: Determine which files and directories you want to back up. Common items
include personal documents, configuration files, databases, and important application data.
• Choose Backup Destination: Decide where you want to store your backups. This could be an external hard
drive, a network location, a cloud storage service, or a separate partition on your system.
• Select Backup Method: There are several methods to perform backups in Linux:
• a. Manual Copying: Simply copy your important files and directories to the backup destination using the cp
command.
• b. rsync: This powerful utility synchronizes files and directories between different locations, updating only
the changed portions.
• c. tar: Use the tar command to create compressed archive files of your data, which can be easily restored
later.
• d. Backup Utilities: Linux distributions often come with backup tools like Deja Dup, Timeshift, or Bacula,
which provide user-friendly interfaces for scheduling and managing backups.
• Perform the Backup: Depending on the method you chose, execute the appropriate command or use the
backup utility to initiate the backup process. For example, if using rsync, the command might look like:
• rsync -av /source/directory /backup/destination
• Automate Backups (Optional): For regular backups, automate the
process using tools like cron or systemd timers. Schedule backups to
occur at specific intervals or times.
• Verify Backup Integrity: After the backup is complete, verify that the
backup files are intact and accessible. You don't want to discover
corruption when you need to restore.
• Test Restoration: Periodically perform a test restoration from your
backup to ensure that the process works as expected. This will help you
become familiar with the restoration process and ensure that your
backups are usable.
• Keep Multiple Copies: Maintain multiple backup copies to cover different time
points. This provides redundancy and helps you recover data from different points
in time.
• Encrypt Backups (Optional): If your backup contains sensitive information, consider
encrypting it to protect your data from unauthorized access. Tools like GPG (GNU
Privacy Guard) can be used for encryption.
• Document Backup Procedures: Create documentation outlining your backup
procedures, including the steps to perform backups and restore data. This
documentation will be valuable in case you need to recover your data in the future.
• Regularly Review and Update: Periodically review and update your backup strategy
to account for changes in your data and storage needs. Adjust your backup
schedule and methods as necessary.
Linux Cp Backup
• The cp command in Linux is used to copy files and directories from
one location to another. Its basic syntax is as follows
• cp [options] source destination
• Here, source is the file or directory you want to copy, and destination
is the location where you want to copy the source.
• If the file you want to copy already exists in the destination directory
you can backup your existing file with the use of this command
• -i or --interactive: Prompts you for confirmation before overwriting
existing files.
• -v or --verbose: Displays detailed information about the copying
process.
• p or --preserve: Preserves file attributes such as timestamps and
permissions during copying.
• Copy a file to a different location:
• cp file.txt /path/to/destination/

• Copy a file, preserving attributes:


• cp -p source/file.txt destination/

• Copy multiple files to a directory:


• cp file1.txt file2.txt /path/to/destination/
• Copy with confirmation before overwriting:
• cp -i source/file.txt destination/
Linux tar Command
• The Linux ‘tar’ stands for tape archive, is used to create Archive and
extract the Archive files.
• provides archiving functionality in Linux.
• It can store all file attributes-access permission,user,group,size,time of
modification
• Files are stored with extension .tar
• We can use Linux tar command to create compressed or
uncompressed Archive files

Syntax:-tar [options] [file or directory to be
archived]
• Options:
-c : Creates archive
-x : Extracts the archive
-f : creates archive with given filename
-t : displays or lists files in archived file
-v : Displays verbose information
-z : compresses the tar file using gzip
-j : compresses the tar file using bzip2
• tar –cvf backup.tar file1
• tar –rvf backup.tar file2----appending
• tar –uvf backup.tar file2---updating
• tar –tvf backup.tar----view
• tar –delete –f backup.tar file2--delete
• tar cvf test.tar test1.txt test4.txt
• o/p—test.tar
tar cvf test.zip test1.txt test4.txt
o/p—test.zip
All similar types of files
$ tar cvf file.tar *.c
Output :
• File.tar
Zip and compress
• tar czf test.tar.gz test2.txt test4.txt
• o/p----Test.tar.gz

• Zip and compress with gz2 utility


• tar cjf test.tar.gz2 test2.txt test4.txt
• o/p—test.tar.gz2

• View the contents of tar file


• tar tvf test.tar
• Preserve the permissions
• tar cvpf test1.tar test1.txt
• Extracting files from Archive using option -xvf : This command
extracts files from Archives.

• $ tar xvf file.tar


• Output :

• os2.c
• os3.c
• os4.c
• Extracting a gzip tar Archive *.tar.gz using option -xvzf :

• This command extracts files from tar archived file.tar.gz files.

• $ tar xvzf file.tar.gz


Backup Your Entire Linux System Using
Rsync
• Rsync Command Syntax
• The rsync command follows the following syntax:
• # rsync [OPTIONS] SOURCE DESTINATION
• Here’s an explanation of the different components and options used with rsync commands:
• -v – Verbose output, displaying detailed information about the transfer.
• -a – archive mode, which allows copying files recursively and it also preserves symbolic links, file
permissions, user & group ownerships, and timestamps.
• -z – Compress files during transfer to reduce network usage.
• -h – human-readable, output numbers in a human-readable format.
• -P – Show progress during the transfer.
• SOURCE – Specifies the source file(s) or directory to be transferred, which can be a local or a remote
location.
• DESTINATION – Specifies the destination path where the files or directories will be copied. Similar to the
source, it can be a local path or a remote location.
Install Rsync in Linux System

• We can install the rsync package with the help of the following
package manager as per your Linux distribution.
• $ sudo apt install rsync [On Debian, Ubuntu and Mint]
1. Copy/Sync File Locally

• a file name backup.tar needs to be copied or synced


to /tmp/backups/ folder.
• # rsync -zvh backup.tar.gz /tmp/backups/

• created directory /tmp/backups backup.tar.gz


• sent 224.54K bytes received 70 bytes 449.21K bytes/sec
• total size is 224.40K
• speedup is 1.00
2.Copy/Sync Directory Locally

• Here in this example, /root/rpmpkgs contains some rpm package files and you
want that directory to be copied inside /tmp/backups/ folder.

• rsync -avzh /root/rpmpkgs /tmp/backups/


• sending incremental file list
• rpmpkgs/ rpmpkgs/httpd-2.4.37-40.module_el8.5.0+852+0aafc63b.x86_64.rpm
rpmpkgs/mod_ssl-2.4.37-40.module_el8.5.0+852+0aafc63b.x86_64.rpm
rpmpkgs/nagios-4.4.6-4.el8.x86_64
• rpm rpmpkgs/nagios-plugins-2.3.3-5.el8.x86_64.
• rpm sent 3.47M bytes received 96 bytes 2.32M bytes/sec
• total size is 3.74M speedup is 1.08
• backup the entire system, all you have to do is open your Terminal
and run the following command
• $ sudo rsync -aAXv /
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*
","/media/*","/lost+found"} /mnt

• This command will backup the entire root ( / ) directory, excluding


/dev, /proc, /sys, /tmp, /run, /mnt, /media, /lost+found directories,
and save the data in /mnt folder.
• rsync – A fast, versatile, local and remote file-copying utility
• -aAXv – The files are transferred in “archive” mode, which ensures
that symbolic links, devices, permissions, ownerships, modification
times, ACLs, and extended attributes are preserved.
• / – Source directory
• –exclude – Excludes the given directories from backup.
• /mnt – It is the backup destination folder.
Copy a Directory from Remote to Local
Server
• This command will help you sync a remote directory to a local
directory. Here in this example, a directory /root/rpmpkgs which is on
a remote server is being copied into your local computer
in /tmp/myrpms.
3-2-1 backup Rule

• 3 copies of data
• 2 copy of back up medium
• 1 copy of data offsite
Choosing a Backup Tool
• Linux has several tools for backing up and restoring files
1. dump : Old tools that work with filesystems. This tool supports two
types of operations: full backups and incremental backups.
• define these by levels ranging from 0 to 9. Level 0 commands dump to
perform a full backup of the entire file system. Levels 1 thru 9 instruct
the program to record all changes made since the last backup
2.tar : A standard backup tool, and by far the easiest to use
dump
• tape device /dev/st0 and you want to create a full backup of the
/dev/sda1 filesystem using dump

• dump -0uf /dev/st0 /dev/sda1


3. cpio : The cpio command in Linux is used for creating and extracting
archive files in the cpio format. Cpio (short for "copy in and out") is an
older archive format used for creating backups, copying files, and
transferring files between systems.
It's less commonly used today compared to other archive formats like
tar and zip, but it still has its applications.
4.dd : The dd command is one of the original Unix utilities and used by
admins.
• creating disk images, copying data between devices
• The basic syntax of the dd command is as follows:
• dd [options] if=input_file of=output_file
• Here are some commonly used options with the dd command:
• if=input_file: Specifies the input file or device.
• of=output_file: Specifies the output file or device.
• bs=block_size: Sets the block size for data transfer (default is 512
bytes).
• Creating a Disk Image:
• To create a disk image from a source device, you can use the dd command. For
example, to create an image of a disk partition:
• dd if=/dev/sda1 of=image.img bs=4M
• This creates an image of the /dev/sda1 partition and saves it to image.img using a
block size of 4 megabytes.
• Copying Data Between Devices:
• You can use dd to copy data from one device to another. For example, to copy data
from one disk to another:
• dd if=/dev/sda of=/dev/sdb bs=1M
• This copies the contents of /dev/sda to /dev/sdb with a block size of 1 megabyte.
Types of backup
• Full backup
• Incremental backup
• Differential backup
• Mirror backup
Full Backup

• Also called as complete backup


• Good for small system
• the process of restoring lost data from backup is much faster.
• A full backup in Linux refers to a type of data backup where all the files and data on a system
or a specific set of directories are copied and stored to a backup destination.
• This type of backup captures all the data, including files, directories, permissions,
ownership, and other attributes
• Advantages
• Restore is the fastest
• Disadvantages
• Backing up is the slowest
• The storage space requirements are the highest
Incremental Backup

• Incremental backup means backing up everything that has changed since last full backup.
• With incremental backup, only the initial backup is a full one.
• Subsequent backups only stores changes that were made since the previous backup.
• Incremental backups reduce the time and network bandwidth required in full backups.
• Also called as differential backup
• Advantages
• Backing up is the fastest
• The storage space requirements are the lowest
• Disadvantages
• Restore is the slowest
How to Create a Linux Backup Plan
Types of media
Gzip command
• gzip test.txt
• o/p—test.txt.gz

• Several files
• gzip test1.txt test2.txt
• o/p----test1.txt.gz
• Test2.txt.gz

• All txt files together


• gzip *.txt

• View
• zcat test.txt.gz
gunzip command
• gunzip command is used to uncompress

• replace the compressed file with the original file by default

• gunzip test.txt.gz
• gunzip test1.txt.gz test2.txt.gz
Bzip2

• File compressions are carried out according to specific algorithms.


There are many compression techniques, and one of them is achieved
through bzip2.
• bzip2 command in Linux is used to compress and decompress the files
Q. How to compress a file using bzip2?

bzip2 test.txt
o/p---test.txt.bz2

View files—bzcat test.txt.bz2

Several files---bzip2 test1.txt test2.txt


o/p---test1.txt.bz2 test.txt.bz2
Q. How to decompress using bzip2?
• bunzip2 test1.txt.bz2

You might also like