How to back up shell scripts
Editor to share with you how to back up the shell script, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1 、 backup_run.sh
The code is 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 you are runing from
If [- r $SOURCE]; then
. $SOURCE # load $source
Else
Echo "`basename $0`: cannot locate default file"
Exit 1
Fi
}
Header ()
{
# header
USER= `whoami`
MYDATE= `date +% A "% e" of "% Bmuri% Y`
Clear
Cat & 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
The code is 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 be 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:
Do
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. Run:
The code is as follows:
$. / backup_run.sh backup.defaults
The above is all the contents of the article "how to back up the shell script". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!