Backup shell script instance code _linux shell

Source: Internet
Author: User
Tags rewind sybase
1, backup_run.sh
Copy Code code as follows:

#!/bin/sh
# Backup_run
# script to run the backups
# loads in a setting file for the ' user to ' change
Source=/home/bob/backup.defaults
Check_source ()
{
# Check_source
# Can we load the file
# Backup.defaults is the source file containing config/functions
# Make sure your path includes this directory to are runing from
If [-R $SOURCE];then
. $SOURCE # Load $source
Else
echo "' basename $ ': Cannot locate default file"
Exit 1
Fi
}
Header ()
{
# header
User= ' WhoAmI '
Mydate= ' Date +%a ' "%e" of "%b-%y"
Clear
Cat << HH
User: $USER $MYDATE
Network SYSTEM BACKUP
=====================
HH
}
Change_settings ()
{
# change_settings
# Let the user to the default settings.
Header
echo "Valid Entries Are ..."
echo "Tape device:rmt0,rmt1,rmt3"
echo "Mail Admin:yes,no"
echo "Backup type:full,normal,sybase"
While:
Todo
Echo-n-C "\ n \ Tape Device to is Used for this Backup [$_device]:"
Read T_device
: ${t_device:=$_device}
Case $T _device in
RMT0|RMT1|RMT3) Break

*) echo "The device are EITHER...RMT0,RMT1,RMT3"

Esac
Done
# If the user hits return in any of the fields, the default value would be used
While:
Todo
Echo-n "Mail Admin when Done [$_inform]:"
Read T_inform
: ${t_inform:=$_inform}
Case $T _inform in
yes| Yes) Break

no| No) Break

*) echo "The choices are Yes,no"

Esac
Done
While:
Todo
Echo-n "Backup Type [$_type]:"
Read T_type
: ${t_type:=$_type}
Case $T _type in
Full|full) Break

Normal|normal) Break

Sybase|sybase) Break

*) echo "The choices are either ... full,normal,sybase"
Esac
Done
# re-assign The temp varialbes back to original variables
# were loaded in
_device= $T _device;_inform= $T _inform;_type= $T _type
}
Show_settings ()
{
# Display current settings
Cat << HH
Default Settings Are ...
Tape Device to be Used: $_device
Mail Admin when done: $_inform
Type of Backup: $_type
Log File of Backup: $_logfile
HH
}
Get_code ()
{
# users get 3 attempts at entering the correct code
# _code is loaded in from the source file
Clear
Header
_counter=0
echo "You must ENTER the correct CODE to is able to change DEFAULT SETTINGS"
While:
Todo
_counter= ' expr $_counter + 1 '
Echo-n "Enter" The code to change the settings: "
Read T_code
# echo $_counter
If ["$T _code" = "$_code"];then
return 0
Else
If ["$_counter"-GT 3];then
echo "Sorry incorrect code entered, you cannot change the settings ..."
Return 1
Fi
Fi
Done
}
Check_drive ()
{
# Make sure we can rewind the tape
Mt-f/dev/$_device Rewind >/dev/null 2>&1
If [$?-ne 0];then
Return 1
Else
return 0
Fi
}
#====================== Main =======================
# can we source the file
Check_source
Header
# Display the loaded in variables
Show_settings
# Ask user if he/she wants to change any settings
If Continue_prompt "Do you wish to change Some of the System Defaults" "Y";
Then
echo $?
# Yes then enter code name
If Get_code;then
# Change some settings
Change_settings
Fi
Fi
#------------------got settings ... now do backup
If Check_drive;then
echo "Tape ok ..."
Else
echo "Cannot rewind the tape. Is it in the tape drive??? "
echo "Check it Out"
Exit 1
Fi
# File system paths to backup
Case $_type in
Full|full)
Backup_path= "Sybase Syb/suppor etc var bin apps usr/local"

Normal|normal)
Backup_path= "etc Var bin apps usr/local"

Sybase|sybase)
Backup_path= "Sybase Syb/suppor"

Esac
# Now for backup
CD/
echo "Now starting backup ..."
Find $BACKUP _path-print | Cpio-ovb-o/dev/$_device >> $_logfile 2>&1
# If the above Cpio does not work on your system try Cpio below, instead
# Find $BACKUP _path-print | Cpio-ovb >/dev/$_device >> $_logfile 2>&1
# to get more information on the tape Change-ovb to-ovcc66536
If ["$_inform" = "yes"];then
echo "Backup finished check the log file" | Mail Admin
Fi

2, Backup.defaults
Copy Code code as follows:

#!/bin/sh
# Backup.defaults
# Configuration default file for network backups
# edit this file at your own
# name Backup.defaults
# --------------------------------------------
# not necessary for the ' environments to being in quotes. But
_code= "Comet"
_logfile= "/appdva/backup/log. ' Date +%y%m%d '"
_device= "Rmt0"
_inform= "Yes"
_type= "Full"
#---------------------------------------------
Continue_prompt ()
{
# continue_prompt
# to Call:continue_prompt ' string to display ' Default_answer
_str=$1
_default=$2
# Check we have the right params
If [$#-lt 1];then
echo "Continue_prompt:i need a string to display"
Return 1
Fi
While:
Todo
Echo-n "$_str [Y. N] [$_default]: "
Read _ans
If ["$_ans" = ""];then
: ${_ans:=$_default}
Case $_ans in
Y) return 0

N) return 1

Esac
Fi
# User has selected something
Case $_ans in
y| y| yes| YES)
return 0

n| n| No|no)
Return 1

*) echo "Answer either Y or N, default is $_default"

Esac
Echo $_ans
Done
}

3. Operation:
Copy Code code as follows:

$./backup_run.sh Backup.defaults
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.