Chapter 5
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Chapter 5
Manage Backup and Recovery
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Objectives
Develop a Backup Strategy
Create Backup Files with ta
Copy Data with the dd Command
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Objectives (continued)
Mi
or Directories with the rsync Command
Automate Data Backups with the cron Service
Troubleshoot the Boot Process of a SLES 9 System
Configure and Install the GRUB Boot Loade
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Develop a Backup Strategy
Objectives
Choose a Backup Method
Choose the Right Backup Media
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Choose a Backup Method
Full backup
Best possible method of data backup
All system data is copied to a backup media once a day
To restore data
Most cu
ent backup media is copied back to the system’s hard disk
Disadvantage
Time frame available to perform backups (Backup window)
Perform backups when the system is not used
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Choose a Backup Method (continued)
Perform an incremental backup
Perform a full backup once a week
Then you perform a backup every day
That copies only files that have changed since the backup the day before
Advantage
Backup window can be much smalle
Disadvantage
Recovery time is longe
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Choose a Backup Method (continued)
Perform a differential backup
Perform a full backup once a week
Then you perform backups every day
To record files that have changed since the last full backup
Advantage
To restore data from a differential backup, you need just two backup media
Disadvantage
Amount of data to be backed up grows every day
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Choose a Backup Method (continued)
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Choose the Right Backup Media
Tape drives are used most often
They still have the best price-to-capacity ratio
Normally these are SCSI drives
Other media for data backup include
Writable CDs or DVDs, removable hard drives, and magnetic-optical (MO) drives
Storage Area Networks (SANs) are also used
SAN often uses magnetic tapes to store the data
Store backup media separately from backed up systems
Store sensitive backup media offsite
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Create Backup Files with ta
Objectives
Create tar Archives
Unpack tar Archives
Exclude Files from Backup
Perform Incremental and Differential Backup
Use tar Command-Line Options
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Create tar Archives
tar format
Container format for files and directory structures
Extension of the archive files end in .ta
Normally data in the archive files is not compressed
You can use additional compression commands
Directories are typically backed up with
tar -cvf
ackup/etc.tar /etc
tar -cvf /dev/st0 /home
View the contents of an archive by entering
tar -tvf
ackup/etc.ta
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Unpack tar Archives
Unpack files from an archive
tar -xvf /dev/st0
Extract just one file
tar -xvf /test1
ackup.tar -C /home/user1/.bashrc
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Exclude Files from Backup
List of these files must be written in an exclude file
Line by line
List is then passed to tar with the option -X
tar -cvf /dev/st0 /home -X exclude.files
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Perform Incremental and Differential Backups
Use a snapshot for incremental backups
Make a full backup with a tar command
tar -cz -g
ackup/snapshot_file -f
ackup
ackup_full.tar.gz /home
Perform an incremental backup
tar -cz -g
ackup/snapshot_file -f
ackup
ackup_mon.tar.gz /home
Use the find command to search for files to back up for differential backup
Make a full backup
tar -czf
ackup
ackup_full.tar.gz /home
Back up all files that are newer than the full backup
find /home -type f -newer
ackup
ackup_full.tar.gz -print0 | tar -cvf -null
ackup
ackup_mon.tar.gz -T-
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Use tar Command-Line Options
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Copy Data with the dd Command
Command dd
Converts and copies files byte-wise
Can copy all kinds of data
Including entire hard disk partitions
Copy a file
dd if=/etc/protocols of=protocols.org
Copy a complete partition
dd if=/dev/sda1 of=boot.partition
Create a backup copy of the MBR
dd if=/dev/sda of=/tmp/m
_copy bs=512 count=1
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Mi
or Directories with the rsync Command
Objectives
Perform Local Copying with rsync
Perform Remote Copying with rsync
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Perform Local Copying with rsync
Mi
or all home directories
rsync -a /home /shadow
Mi
or the content of a directory and not the directory itself
rsync -a /home/. /shadow
Exclude files from backup
rsync -a --exclude-from=/home/exclude /home/. /shadow/home
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Perform Local Copying with rsync (continued)
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Perform Remote Copying with rsync
With rsync and SSH
Log in to other systems
Perform data synchronization remotely over the network
Copy home directory of the user tux to a backup serve
rsync -ave ssh root@DA1:/home/tux
ackup/home
Backup of the home directory is copied back to the DA1 system
rsync -ave ssh
ackup/home/tux root@DA1:/home
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Automate Data Backups with the cron Service
Automate backups in Linux with the cron service
System jobs are controlled with the file /etc/cronta
And the files in the directory /etc/cron.d
System jobs are defined using scripts in directories
/etc/cron.(hourly, daily, weekly, and monthly)
Specify which users can create cron jobs with
/va
spool/cron/allow and /va
spool/cron/deny
Jobs of individual users
Stored in files in the directory /va
spool/cron/tabs
Processed with the command cronta
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Troubleshoot the Boot Process of a SLES 9 System
Objectives
System Boot Process Issues
How to Boot a Co
upted System Directly into a Shell
How to Boot a Co
upted System with the Installation Media
How to Start and Use the SLES9 Rescue System
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
System Boot Process Issues
Most common problems:
The system cannot boot due to a misconfigured boot loade
The system cannot boot because of file system co
uption
An init script has malfunctioned and is blocking the boot process
The system does not start co
ectly because of hardware changes
Access the file system of the co
upted system
To detect and fix the problem
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
How to Boot a Co
upted System Directly into a Shell
Boot screen of the GRUB boot loade
Lets you pass parameters that modify the Linux kernel
Before the kernel is actually loaded
Use the Boot Options field
At the bottom of the GRUB boot screen
Boot parameter init=new_init_program
Changes the first program loaded by the kernel
To boot to a shell use init=
in
ash
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
How to Boot a Co
upted System with the Installation Media
Steps
Insert the SLES 9 DVD and reboot the system
Select Installation; then press Ente
When YaST displays the language selection dialog box, select Accept
Select Boot installed system; then select OK
Select the root partition of the system you would like to boot; then select Boot
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
How to Start and Use the SLES 9 Rescue System
Steps
Insert the SLES 9 DVD and reboot the system
From the boot menu, select Rescue System; then press Ente
From the language selection dialog box, select your language; then press Ente
At the prompt Rescue login, enter root
Press the Enter key
You are now logged into the Rescue System as root
Mount the co
esponding partition
mount -t reiserfs /dev/hda6 /mnt
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Configure and Install the GRUB Boot Loade
Objectives
The Basic Functionality of a Boot Loade
The Basics of GRUB
How to Configure the GRUB Boot Loade
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
The Basic Functionality of a Boot Loade
Basic tasks of a boot loader:
Boot various operating systems
Pass boot parameters to the Linux kernel
Stages
Stage 1
Program code for stage 1 is installed in the master boot record (MBR) of the hard disk
Stage 2
Usually contains the actual boot loade
Files of boot loader are located in the directory
oot
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
The Basics of GRUB
GRUB is the standard boot loader of SLES 9
Features
Stage 2 File System Drivers
Includes file system drivers fo
ReiserFS, ext2, ext3, Minix, JFS, XFS, FAT, and FFS (BSD)
GRUB Shell
Enables interactive control of the boot manage
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
How to Configure the GRUB Boot Loade
Edit the file
oot/gru
menu.lst
Structure of the file
General options are listed
Options for the various operating systems
That can be booted with the boot manage
Example
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
*
Chapter 6
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Chapter 6
Create Shell Scripts
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Objectives
Use Basic Script Elements
Use Variable Substitution Operators
Use Control Structures
Use Advanced Scripting Techniques
Learn About Useful Commands in Shell Scripts
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Use Basic Script Elements
Objectives
Flow Charts for Scripts
The Basic Rules of Shell Scripting
How to Develop Scripts That Read User Input
How to Perform Basic Script Operations with Variables
How to Use Command Substitution
How to Use Arithmetic Operations
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Flow Charts for Scripts
Programming elements of a script
Often visualized by using program flow charts
Flow charts benefits
Force author to lay down the steps the script should perform
Provide a clear symbolic outline of the algorithm
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Flow Charts for Scripts (continued)
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
The Basic Rules of Shell Scripting
Shell script
ASCII text file
Contains commands to be executed in sequence
Permissions for script file must be set to “r” and “x”
chmod +x script.sh
Run shell script with sh script.sh
Create a
in directory for scripts under each user’s home directory
Add this directory to the user’s search path
export PATH=$PATH:~
in
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
The Basic Rules of Shell Scripting (continued)
Add an .sh extension to the script filename
Make sure script filename is not identical to existing commands
Elements of a script
Start
Commands
Stop
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
The Basic Rules of Shell Scripting (continued)
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Exercise 6-1 Produce Output from a Script
In this exercise, you will produce output from a script using the echo command
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
How to Develop Scripts That Read User Input
Command read
Used to create scripts that read user input
Takes a variable as an argument
And stores the read input in the variable
Variable can then be used to process the user input
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
How to Develop Scripts That Read User Input (continued)
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Exercise 6-2 Read User Input
In this exercise, you will use the read command in a shell script to accept user input
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
How to Perform Basic Script Operations with Variables
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Exercise 6-3 Simple Operations with Variables
In this exercise, you will practice performing simple operations with variables
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
How to Use Command Substitution
Command substitution
Output of a command is used in a shell command line or a shell script
Example 1: printing output
echo "Today is `date +%m/%d/%Y`"
Example 2: assigning output to a variable
TODAY=`date +%m/%d/%Y`
echo "Today is $TODAY"
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Exercise 6-4 Use Command Substitution
In this exercise, you will practice using command substitution
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
How to Use Arithmetic Operations
Bourne shell is limited in this regard
Can perform operations by relying on external commands (such as expr)
Bash shell
Comes with built-in support for arithmetic operations
Limited in the following ways
Only supports operations with whole numbers
All values are signed 64-bit values
Needs to use external commands, such as bc, for floating-point calculations
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
How to Use Arithmetic Operations (continued)
Use the external command exp
A=`expr $B + 10`
Use the Bash built-in command let
let A="$B + 10“
Use arithmetic expressions inside parentheses or
ackets
A=$((B XXXXXXXXXXor A=$[B + 10]
Use the built-in command declare
declare -i A
declare -i B
A=B+10
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Exercise 6-5 Use Arithmetic Operations
In this exercise, you will practice using arithmetic operations
Advanced SUSE Linux Enterprise Server Administration (Course 3038)
Use Variable Substitution Operators
Variable substitution operators
Used to assign different