服务器备份与还原脚本
来源:互联网 发布:亲和素淘宝店 编辑:程序博客网 时间:2024/06/06 09:58
#!/bin/bash
#
#this is a main() interface
#
#
#
stname=$(hostname | awk -F "." '{print $1}')
#the port of nginx
_pnginx=80
#the port of Chinese web site
_pwwworg=8080
#the port of English web site
_pwwwcom=8081
#the swich of nfs
_nflag=yes
#check log
_logfile=/tmp/${_hostname}chk$(date +%Y%m%d%H%M).log
echo "LogFileName:${_hostname}chk$(date +%Y%m%d%H%M).log">>$_logfile
echo "IP:">>$_logfile
ifconfig | grep Mask >>$_logfile
echo "">>$_logfile
echo "=====================================================">>$_logfile
echo "srv : check the status of server running!"
echo "bakngx : backup the control file of nginx!"
echo "baktomchn : create a image of chinese web site!"
echo "baktomeng : create a image of english web site!"
echo "bakusrchn : backup the datafile of chinese users!"
echo "bakusreng : backup the datafile of english users!"
echo "storesecene : protect scene!"
echo "crtsnap : create a web system snapshot!"
echo "restorescene : recovery web system scene!"
echo "restoresnap : recovery web system snapshot point!"
echo ""
echo ".............................................................">>$_logfile
echo "usage:">>$_logfile
echo "srv : check the status of server running!">>$_logfile
echo "bakngx : backup the control file of nginx!">>$_logfile
echo "baktomchn : create a image of chinese web site!">>$_logfile
echo "baktomeng : create a image of english web site!">>$_logfile
echo "bakusrchn : backup the datafile of chinese users!">>$_logfile
echo "bakusreng : backup the datafile of english users!">>$_logfile
echo "storescene : protect scene!">>$_logfile
echo "crtsnap : create a web system snapshot!">>$_logfile
echo "restorescene : recovery web system scene!">>$_logfile
echo "restoresnap : recovery web system snapshot point!">>$_logfile
echo ".............................................................">>$_logfile
_dfbkhome=/home/backup/
_bkprocn=$_dfbkhome/www/cn/
_bkproen=$_dfbkhome/www/en/
_bkngx=$_bkprocn/ngx/
_bktomcn=$_bkprocn/tomcat/manu/
_bktomcn=$_bkprocn/tomcat/manu/
_bkusrcn=$_bkprocn/usr/
_bkusrcn=$_bkprocn/usr/
_bkscenecn=$_bkprocn/scene/
_bksceneen=$_bkproen/scene/
_bksnapcn=$_bkprocn/tomcat/snap/
_bksnapen=$_bkproen/tomcat/snap/
#function
#Note: the usage function as flows:
# _function_name $1 $2 $3
# $1 stands for the parameter which is needed
# $2 stands for the parameter which is source path
# $3 stands for the parameter which is destination path
# $4 stands for the parameter which is logfile
#
function srv(){
}
function bakngx(){
_ngxfilename=nginx$(date +%Y%m%d%H%M).conf
echo "Nginx control file name is $_ngxfilename">>$4
echo "start to backup nginx control file ...">>$4
cp -rf $2/nginx.conf $3/$_ngxfilename >>$4
if [[ $? -eq 0 ]] ; then
echo "nginx backup successfully,the backup file : $3/$_ngxfilename">>$4
echo "nginx backup finished!">>$4
return 0
else
echo "nginx backup failed!">>$4
echo "nginx backup finished!">>$4
return 1
fi
}
function baktomchn(){
_tmcn=tomcatchinese$(date +%Y%m%d%H%M).dmp
echo "Tomcat backup filename is $_tmcn">>$4
echo "start to backup tomcat">>$4
tar -czvf $3/$_tmcn $2>>$4
if [[ $? -eq 0 ]] ; then
echo "tomcat backup successfully,the backup file : $3/$_tmcn">>$4
echo "tomcat backup finished!">>$4
return 0
else
echo "tomcat backup failed!">>$4
return 1
fi
}
function baktomeng(){
_tmen=tomcatenglish$(date +%Y%m%d%H%M).dmp
echo "Tomcat backup filename is $_tmen">>$4
echo "start to backup tomcat">>$4
tar -czvf $3/$_tmen $2>>$4
if [[ $? -eq 0 ]] ; then
echo "tomcat backup successfully,the backup file : $3/$_tmen">>$4
echo "tomcat backup finished!">>$4
return 0
else
echo "tomcat backup failed!">>$4
return 1
fi
}
function bakusrchn(){
_ucndata=usrcndatas$(date +%Y%m%d%H%M).udt
echo "User data backup filename : $_ucndata">>$4
echo "start to backup user datas">>$4
tar -czvf $3/$_ucndata $2 >>$4
if [[ $? -eq 0 ]] ; then
echo "user data has been backup successfully, the backup file is $_ucndata">>$4
echo "user datas backup finished!">>$4
return 0
else
echo "user datas backup failed!">>$4
return 1
fi
}
function bakusreng(){
_uendata=usrendatas$(date +%Y%m%d%H%M).udt
echo "User data backup filename : $_uendata">>$4
echo "start to backup user datas">>$4
tar -czvf $3/$_uendata $2 >>$4
if [[ $? -eq 0 ]] ; then
echo "user data has been backup successfully, the backup file is $_uendata">>$4
echo "user datas backup finished!">>$4
return 0
else
echo "user datas backup failed!">>$4
return 1
fi
}
function storescene(){
_scene=scene$(date +%Y%m%d%H%M).scn
echo "the scene filename is $_scene">>$4
echo "start to restore current scene">>$4
tar -czvf $3/$_scene $2 >>$4
if [[ $? -eq 0 ]] ; then
echo "the scene has been restored successfully,the scene file is $_scene">>$4
echo "scene has been restored finished!">>$4
return 0
else
echo "scene has been restored failed!">>$4
return 0
fi
}
function crtsnap(){
_snapshot=snapshot.scn$(date +%Y%m%d).$(date +%H%M).snp
_ssd=snapshot.scn$(date +%Y%m%d)
echo "the snapshot name is $_snapshot">>$4
echo "start to create snapshot">>$4
if [[ -d /tmp/snapshot ]] ; then
rm -rf /tmp/snapshot/* >>$4
mkdir -p /tmp/snapshot/$_ssd>>$4
else
mkdir -p /tmp/snapshot/$_ssd >>$4
fi
cp -rf $2 /tmp/snapshot/$_ssd>>$4
tar -czvf $3/$_snapshot /tmp/snapshot/$_ssd/* >>$4
if [[ $? -eq 0 ]] ; then
echo "snapshot created successfully,the file is $3/$_snapshot">>$4
echo "snapshot create finished!">>$4
return 0
else
echo "snapshot created failed!">>$4
return 1
fi
}
function restorescene(){
case $1 in
tomcat_cn)
echo "start to restorescene..."
echo "start to restorescene...">>$4
rm -rf /usr/local/project/tomcat_cn>>$4
tar -xzvf $2 -C /usr/local/project/>>$4
tar -xzvf $2 -C $3 >>$4
if [[ $? -eq 0 ]] ; then
echo "restorescene successfully!">>$4
return 0
else
echo "restorescene failed!">>$4
return 1
fi
;;
tomcat_en)
echo "start to restorescene..."
echo "start to restorescene...">>$4
rm -rf /usr/local/project/tomcat_cn>>$4
tar -xzvf $2 -C /usr/local/project/>>$4
tar -xzvf $2 -C $3 >>$4
if [[ $? -eq 0 ]] ; then
echo "restorescene successfully!">>$4
echo "restorescene successfully!"
return 0
else
echo "restorescene failed!">>$4
echo "restorescene failed!"
return 1
fi
;;
*)
echo "usage : restorescene parameter[tomcat_cn|tomcat_en] source_bak_file destination"
;;
esac
}
function restoresnap(){
}
#
#main(string[] args)
_optype=$1
case $_optype in
srv)
echo "check the status of server running!">>$_logfile
;;
bakngx)
echo "backup the control file of nginx!">>$_logfile
;;
baktomchn)
echo "create a image of chinese web site!">>$_logfile
;;
baktomeng)
echo "create a image of chinese web site!">>$_logfile
;;
bakusrchn)
echo " backup the datafile of chinese users!">>$_logfile
;;
bakusreng)
echo " backup the datafile of english users!">>$_logfile
;;
storescene)
echo "protect scene!">>$_logfile
;;
crtsnap)
echo " create a web system snapshot!">>$_logfile
;;
restorescene)
echo "recovery web system scene!">>$_logfile
;;
restoresnap)
echo "recovery web system snapshot point!">$_logfile
;;
*)
echo "check system status!"
;;
esac
- 服务器备份与还原脚本
- SQL Server数据库脚本备份与还原
- oracle备份、还原脚本
- T-SQL语句实现数据库备份与还原 (脚本)
- linux mysql压缩备份与还原的shell脚本
- 两台服务器自动备份与还原处理解决方案
- 服务器上的Svn 版本库备份与还原
- Window服务器 - Java进行Mysql数据库备份与还原
- SQLserver备份与还原
- 备份与还原
- 备份与还原数据库
- 数据库备份与还原
- 数据库备份与还原
- oracle 备份与还原
- IIS备份与还原
- 数据库备份与还原
- 数据库备份与还原
- mysql备份与还原
- QT 5使用QNetworkAccessManager类遇到的问题
- 协同过滤(英语:Collaborative Filtering)
- jquery + json 操作
- G级超大文件 断点续传 上传控件 silverupload 支持md5验证 支持跨域上传
- 黑马程序员 java高新技术笔记之反射
- 服务器备份与还原脚本
- 一步一步将你的C#程序部署到Android
- 黑马程序员 java高新技术笔记之装箱与拆箱,枚举
- php中的Sessions详解
- hdu 2665 Kth number
- 转载:PostgreSQL内核分析 (1)
- 为什么日志只应该有三个级别
- hdu1240 Asteroids! (BFS)
- C# 汉字转拼音与汉字简繁转换