Week 9 - Managing Backup and Recovery Flashcards
System backup
Copies files and directories to an archive
Use to restore data in case of system failure of data loss and corruption
Most common backup medium is tape
Archive
File containing many other files, each of which is still identified by its file name, owner, permissions, and timestamp
System backups in Linux
Directories to include in regular backups
/etc contains core configuration files, security files, network configuration files, user and group
information, etc
/home each user has a /home directory
/opt software and packages added after the default installation
/root root user’s home directory
/var system specific information that changes while the system is running normally
/srv server scripts
Tar Utility
Tar (tape archive) utility
Archives files
- creates archives by combining multiple files and directories into a single file
- originally designed to store files on magnetic tape
- now used to store files on a tape, hard disk, CD/DVD, or even on a network
Extracts files
- unpack members of an archive making them available to the file system
Common tar options
-c or –create
creates an archive file
-t or –list
Lists an archive’s contents
-x or –extract
Extracts an archive’s contents
-f or –file
Specifies the archive’s file name and location
-v or –verbose
Displays details about copying files to and extracting files from archives
-z or –gzip, –unzip
Filters an archive through gzip
Members
– Different from files
– Can be viewed only with the tar command’s t option
– Can extract all/some members from an archive
* e.g. When a user deletes a file accidentally
- r or –append
Adds files to existing archive
-u or –update
Compares the date and time of a member with the date and time of the file with the same name. If the file was modified after the archive was created, its newer version is added to the archive.
-A or –concatenate
Similar to append option but adds one archive to another archive
–delete
removes specific members from a tar archive. This option doesn’t have a short name
-d or –compare
compares specified members with files in the file system having the same name and reports difference in file size, mode, owner, modification date and contents
–mode
changes a member’s permissions in an archive with number or symbolic notation
–mtime
changes a member’s modification date in the tar archive
–owner
changes the member’s owner in the tar archive
–group
similar to –owner, except it’s user to change member’s group instead of owner
Full backup
Archive of all files on file system
Never perform a full backup while users are accessing the system - tar file could be corrupted if files are modified during backup process
tar command for full backup
tar -cvf backup0.tar -V “Comment” –listed-incremental =/home/backup.snap *
creates full backup of current directory
-cvf creates archive called backup0.tar
-v labels archive with the text between quotation marks
–listed-incremental creates a snapshot file named backup.snap which is used during incremental backups to determine which files have changed since the last backup
* what files to backup
Incremental backups
Archive containing only files modified since the last backup
– Companies have different backup strategies,
depending on their needs
– Incremental backup each night, full backup weekend
– Full Backup each night
- Syntax for creating an incremental backup
– Same as the command for full backups
– If the snapshot file already exists, the tar utility
examines it to determine whether any files have
changed
-V or –label
Adds volume header to tar file. Volume header is a digital label used to describe file. View volume header with -t option
-w or –verify
verifies files have been included in archive correctly
-g or –listed-incremental
Forces tar to archive only files that have been modified since last backup (full or incremental) by analysing a snapshot file.
The snapshot file is given as an argument to the –listed-incremental option so that tar utility knows which files have been changed, added or deleted since last backup.
–no-check-device
–no-check-device
When a device number changes (can happen when upgrading kernel version) an incremental backup might backup files that haven’t been changed. This option prevents this from happening by forcing tar utility to not rely on device number when preparing for incremental backup.
–check-device
default option; necessary only when you want to undo –no-check-device option
Cpio Utility
Copy in/out utility
- Uses results of ls or find command to generate files to be archived
Operates in 3 modes
- Copy-out, cpio created an archive from the output of ls or find commands
-Copy-in, extracts files from an archive
-Copy-pass, copies files from one directory to another
Input redirection
Default standard input - keyboard
< symbol redirects input instead of getting input from keyboard, can get input from file
Output redirection
default standard output, screen e.g. type ls and result is output to screen
Output redirection operators redirect command’s output
> redirects output to a file
> file redirection
| pipe redirection
redirects output of one command and sends it ass input to another commands
ls > myfile
redirect ls command’s output to the myfile instead of displaying the output on screen
ls | more
redirect ls output to more command
Copy-Out Mode
cpio - copy in/out utility
Uses results of ls or find command to generate files to be archived
-o or –create
creates archives by accepting output of ls or find as input for an archive
e.g. ls | cpio -o > files.cpio
results of ls command used to determine which files to archive in files.cpio
Copy-In Mode
Extract an archive
use standard input redirection symbol < to extract the archive members
-i extracts fies from a cpio archive
-v lists files as they are being extracted
Copy-Pass Mode
Copy files and directories from one directory and paste them in another directory
- without actually creating an archive
Not practical option for option for backups
- Does almost same as cp command
Cpio utility
- Preserves modification times and ownership
-p copy files from one directory tree to another
Compression
Reduces size of data to store information in less space
Every GB of data costs money
Compress data to:
- Save storage space
- Make it fit on removable media
- Transfer it across network faster
Most common compression utility gzip
bzip2 also available
The gzip Utility
File compressed with gzip has:
– Extension .gz
–Same file permissions, ownership, and modification time as the original file
– Much smaller file size
- Compression ratio
– Defines by how much a file is reduced after compressing it
– Text files are typically reduced by 60% to 70% with compression
– -v option: view compression ratio
gzip is built into tar
- Use -z option to enable gzip
- Compress an archive as you create it
Scheduling Backups
Configure Automatic system backups
– Backing up is a chore
– Management can often prioritize other work
– 75% of data loss is human error related
– Vital areas of software production, software deployment, data warehousing etc.
CRON (Command Run ON)
Automatic scheduling and execution of system backups
– Schedule during off hour where fewer people are logged in to the system
– Less disruption in service
- Use CRON
CRON daemon (crond)
System daemon
Uses a configuration file called a cron table to schedule commands that run at specified times
Cron table has 6 fields
-Fields used to specify time to run task and task to be run
- command to be executed
minute (0-59)
hour (0-23)
day of month (1-31)
month (1-12)
day of week (0-6) Sunday = 0
- command to be executed
Cron daemon uses two types of cron tables
– User cron table in /var/spool/cron/tabs
– System cron table in /etc/crontab
* Users use the user cron table to schedule tasks
* System uses the system cron table to schedule system tasks
User Cron tables
Every user (including root) on an Linux system has a cron table
* crontab command
– Create, delete, and list cron tables
crontab command options
-e opens vim editor to edit current user’s cron table. If cron table doesn’t exist, a blank table is created for you to edit.
-u specifes name of user whose cron table is to be edited
-l displays current user’s cron table
-r removes current user’s cron table
Displaying contents of text file
List a file’s contents without actually opening file in text editor
cat and tic
head and tail
more and less
The cat and tic commands
cat (concatenation) command
– Displays an entire file’s contents at once
– Typically used to display the contents of a small text file
–Can be used to display the contents of multiple files at once
* -n option
– Display line numbers in a text file:
– cat -n scr1
tic command
– Display a text file’s contents in reverse order
– Main purpose to display log files
The head and tail commands
head command
– Displays the first 10 lines of a text file
– head scr8
– Can display more than 10 lines: head 15 scr8
tail command
– Displays the last 10 lines of a text file
– tail scr8
– Can display more than 10 lines tail 15 scr8
+ operator
* Start displaying text at a specified line number all the way to the end of the file
The more and less commands
more command
– Displays a file’s contents one screen at a time
- less command
– Displays a file’s contents one screen at a time
– Allows you to navigate the file by using arrow keys or the mouse wheel
Spacebar Displays next bar
#+spacebar Display the next # lines
Enter Displays next line
q Exits the more command
= Displays current line number
h Displays help
Summary
Several directories should be backed up regularly particularly user’s home directories
Linux includes backup utilities tar and cpio
Archives stored on many Stored on many different types of media, such as tapes, CD RWs/DVD RWs, removable media, and hard disks