Backing Up, Compressing and Restoring

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 41

Backing Up, Compressing and

Restoring
Need for Backups

 Accidental erasure of data


 Corruption of data due to power failure or hard disk
crash
 Virus attack on files
 Upgrade of system to provide for larger storage
capacity
Quality of a Good Backup

 Reliability
 Speed
 Availability
 Ease of use and documentation
Backup Strategies
 Full Backup
 Complete backup of all required files
 Performed in regular intervals
 Incremental Backup
 Backing up files that has been modified after last full
backup
 To ensure that state of files stored in backup are
consistent with original files
Concept of backup Levels

 To keep track of all the backups


 Indicates the type of backup being performed
 Level 0
 Performed immediately after OS is installed
 Level 1, 2, 3 etc
 Mainly incremental backups
Sample Plan 1
Sample Plan 2
Files to be Backed Up

 Prioritize and select files to be backed up


 Categorize files into user files and system files
 Backup /etc, /home directories
Files not to be Backed Up

 Software installed and configured


 /tmp
 /proc
 /var
Factors to Select a Backup Medium

 Portability
 Support for unattended or automated backups
 User Interface for the backup utility
 Support for remote backups
 Media types supported
 Cost of the backup utility
The tar command

 To store, backup, transport and archive files


 Creates an archive called tar file, or tar ball
 .tar extension
 Tar file is a single file that contains multiple files
 Tar file stores:
 Multiple files
 File access permissions
 User and group owners
 Size in bytes
 Time of last modification
The tar command contd...

 Name comes from Tape Archiver


 Creates new tar file
 Add new members to the tar file
 Extract member files
 View members of a tar file
The tar command contd...

 Used to store files to conveniently transfer over the


network
 Many utilities that we can download from the
Internet are in tar format
 Commonly used to perform full and incremental
backups
 Preserves file information and directory structure
 By default do not compress files
The tar command contd...

 Syntax
 Tar [options] [filenames] [directory names]
 Options
 First option must be either A, c d, r, t, u or x
 Last option is names of files and directories to be
archived
Creating a new archive

 tar –cvf trail.tar /root/test/*


 Creates tar file with name trial.tar
 Contains all files from /root/test/ directory
 Leading / will be removed from files names for added
security
 Options:
 -c to create
 -v for verbose
 -f to specify name of tar file or location where archive is to
be created
Restoring Files

 tar –xvf trail.tar


 -x to extract
 Path names denote relative path names
 Creates a directory named root in current directory
Listing the Files in an Archive

 tar –tf trail.tar


 Files not extracted or modified
 Just lists the files in the archive
Comparing Files in an Archive with Disk
Files

 tar –dvf trail.tar


 -d for difference
 Single line output for each file in archive stating what
the difference is
 Reports differences in:
 File size, mode, owner, modification and date
Compare the files stored in arheive and actual disk files
Adding Files to an Archive

 tar –rvf trail.tar /root/test/imp


 -r for append
 To append new files to the archive
 Will append a new copy if file is already present in
archive
Updating Files in an Archive

 tar –uvf trail.tar /root/test/m.c /root/test/a.out


 -u for update
 Both files /root/test/m.c /root/test/a.out are compared
with respective files in archive and if different will be
appended to the end of the archive
 While restoring, the files are sequentially extracted and
hence latest version will be extracted last and
overwrites any existing copies
Deleting Files from an Archive

 tar --delete –f trail.tar /root/test/tmp


Concatenating Tar Archives

 tar –Af trial.tar script.tar


 Adds all content of script.tar to trial.tar
Compressing Files

 tar –zcvf trial.tar.gz /root/test/*


 z for compressing and decompressing
 Uses the gzip and gunzip utilities
 To view contents of compressed tar file:
 tar –ztvf trial.tar.gz
Storing Files on External Devices

 tar –cvpf /dev/nst0 /home /root


 Creates full backup of /home and /root and stores it on
the tape
Device must be mounted before using it
Operations Available in tar command

 -A appends tar files


 -c creates new archive
 -d compares archive members with files in system
 -t lists archive members
 -r appends files to end of archive
 -u adds files to the end of archive
 -x extract members from archive
 --delete delete members from archive
Making Incremental Backups

 Use –u option with tar command


 Also –g option of tar command
 tar –cf level1.tar –g level0.tar /home
The cpio Utility

 To copy files to or from a tar archive


 To store an archive on any type of backup media
 Used to store and retrieve large amounts of data
Advantages of cpio over tar

 Used to compress data efficiently


 Can take backups that span several tapes
 Skips bad sectors and continues to take backups
 tar crashes and corrupts the tape in case it finds bad
sectors
 Can backup remote systems
 cpio archive contains files and information about
these files
Modes of cpio command

Mode Meaning Option


Copies files into an archive. Takes a list of names
Copy-out from standard input and writes archive to -o
standard output.
Copy-in Extracts or creates a list of files from an archive. -i
Reads the archive from standard input
Copies files from one directory to another. ie, it
combines the copy-out and copy-in steps without
Copy-pass using an archive. Reads the list of files from -p
standard input. Directory to which the files must
be copied should be given as argument to the
command.
The dump and restore Utilities

 To back up files from a file system


 Not for archiving
 Can back up files to be stored on any medium
 If size of files to be backed up is large, dump utility
automatically spans multiple volumes
 Supports backup levels
 Remote backup possible with –f option
 File system type must be ext2 only
The dump and restore Utilities

 Inverse function of dump utility


 To restore files into the file system from a backup
created by dump
 Can restore a full backup and then restore
incremental backups
 To restore data over a network use the –f option
Syntax for dump and restore

 dump <-backup_level> [options] filesystem


 restore <operation> [option] [file/s]

 <-backup_level> specifies level of backup needed


 Type of backup can be specified using <options>
argument

 Example:
 dump -0 –f full_dump /home
Compressing Files

 To limit hard disk space


 To reduce space utilized by files
 Utilities may use algorithms
The compress utility

 To compact a disk file to a file of smaller size


 Compacts and replaces the file with a .z extension
 Reduces text file to about 50 to 60% of the original size
 File can be restored to original size using uncompress
utility
The compress utility

 Compress utility attaches a magic number to the files


that are compressed
 Uncompress searches for this magic number and the .z
extension
 Ignores files having .z extension, but no magic number
 Magic number is not visible
The compress utility

 Does not change original attributes of the file


 Does not compress symbolic links
 If a regular file ahs multiple hard links, -f option
needed to compress it

 Zcat utility
 To view contents of file without decompressing it
 zcat searches for magic number , not for .z extension
Syntax for compress, uncompress and
zcat

 compress [options] [file names]


 uncompress [options] [filename]
 zcat –V [file names]
Options available with compress
and uncompress

Option Meaning

--r Displays output to standard output. The uncompress –c is


equivalent to zcat utility.
-c Compress/decompress directories recursively.
-V Print versions of the utility
The gzip uitlity

 To compress files
 Preferred over compress utility
 Reduces size of a text file to 60 to 70% of original size
 Creates a file with extension .gz
 The gunzip utility used to decompress files
 To decompress can use, gunzip, gzip –z or zcat
Syntax for gzip, gunzip and zcat

 gzip [options] [file names]


 gunzip [options] [filenames]
 zcat [options] [file names]
Options with gzip and gunzip
Option Meaning
-c Displays output to standard output
-d Decompresses files; gzip –d is same as gunzip
-h Displays help
Does not save original file name and time stamp while
-n compressing
-N Ensures that original time stamp and name are not modified
-r Compresses/decompresses directories recursively
-l Lists the size of original file, size after compression and ratio
of compression
-q Runs in quiet mode; all warnings suppressed
-f Forces compression even if there are multiple hard links
Specifies level at which compression should happen (1 to 9).
=<#> Default is 6

You might also like