Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5376366
  • 博文数量: 1144
  • 博客积分: 11974
  • 博客等级: 上将
  • 技术积分: 12312
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-13 20:06
文章存档

2017年(2)

2016年(14)

2015年(10)

2014年(28)

2013年(23)

2012年(29)

2011年(53)

2010年(86)

2009年(83)

2008年(43)

2007年(153)

2006年(575)

2005年(45)

分类: LINUX

2006-07-19 14:21:17

公司开发人员不断对现有线上系统做升级,升级前需要备份原有得应用程序,所以他们做更新都得我陪着(因为备份需要我来做),刚写了手工备份得脚本,这样开发人员自己就可以做备份了,呵呵,我解脱了。

不过大家在用得时候需要做一些修改。








#!/bin/sh

##########**********Define Envionment Variables**********##########

SCRIPTDIR="/home/iwgroup/backup/script"
BACKUPDIR="/home/iwgroup/backup/databak"
VASOSS="/opt/iwgroup/"
VASOSSLIB="/opt/iwgroup/testdir"
VASOSSCONF="/opt/iwgroup/dirtest"

##########**********define date Format**********###########
TODAYDATE="`date "+%Y%m%d%H"`"
TODAYDATEFULL="`date "+%Y-%m-%d_%H:%M:%S"`"



##########**********Print The Select Menu**********##########
echo

cat $SCRIPTDIR/word.txt | awk 'NR==1'

echo
echo -e "\t1: backup /opt/iwgroup/"
echo -e "\t2: backup /opt/iwgroup/testdir/"
echo -e "\t3: backup /opt/iwgroup/dirtest"
echo
echo -e "Please select one from 1 to 3,or enter the path: \c"
read  dirpath
case "$dirpath" in
   1)
        echo -e "now start backup directory $VASOSS,be sure of this diretory is you need backup:([Y/y] or [N/n])\c"
        read YORN
        if [ "$YORN" = "Y" -o "$YORN" = "y" ]
        then
            echo "execute backup program ..."
            cd $VASOSS
            tar cvf Vasossone_vasoss_backup_$TODAYDATE.tar ./* >> $SCRIPTDIR/logs.log 2>&1
            gzip Vasossone_vasoss_backup_$TODAYDATE.tar
            mv Vasossone_vasoss_backup_$TODAYDATE.tar.gz $BACKUPDIR
            echo "already backup $VASOSS directory to $BACKUPDIR directory,backup file name is Vasossone_vasoss_backup_$TODAYDATE.tar.gz"
            echo "at the $TODAYDATEFULL,you backup $VASOSS directory to $BACKUPDIR directory,backup file name is Vasossone_vasoss_backup_$TODAYDATE.tar.gz" >> $SCRIPTDIR/logs.log
        else
            echo "please you select again"
            echo "at the $TODAYDATEFULL,you ever select 1,but you canceled this operate" >> $SCRIPTDIR/logs.log
        fi   
        ;;
   2)  
        echo -e "now start backup directory $VASOSSLIB,be sure of this diretory is you need backup:([Y/y] or [N/n])\c"
        read YORN
        if [ "$YORN" = "Y" -o "$YORN" = "y" ]
        then
            echo "execute backup program ..."
            cd $VASOSSLIB
            tar cvf Vasossone_vasoss_lib_backup_$TODAYDATE.tar ./* >> $SCRIPTDIR/logs.log 2>&1
            gzip Vasossone_vasoss_lib_backup_$TODAYDATE.tar
            mv Vasossone_vasoss_lib_backup_$TODAYDATE.tar.gz $BACKUPDIR
            echo "already backup $VASOSSLIB directory to $BACKUPDIR directory,backup file name is Vasossone_vasoss_lib_backup_$TODAYDATE.tar.gz"
            echo "at the $TODAYDATEFULL,you backup $VASOSSLIB directory to $BACKUPDIR directory,backup file name is Vasossone_vasoss_lib_backup_$TODAYDATE.tar.gz" >> $SCRIPTDIR/logs.log
        else
            echo "please you select again"
            echo "at the $TODAYDATEFULL,you ever select 2,but you canceled this operate" >> $SCRIPTDIR/logs.log
        fi
        ;;
   3)
        echo -e "now start backup directory $VASOSSCONF,be sure of this diretory is you need backup:([Y/y] or [N/n])\c"
        read YORN
        if [ "$YORN" = "Y" -o "$YORN" = "y" ]
        then
            echo "execute backup program ..."
            cd $VASOSSCONF
            tar cvf Vasossone_vasoss_conf_backup_$TODAYDATE.tar ./* >> $SCRIPTDIR/logs.log 2>&1
            gzip Vasossone_vasoss_conf_backup_$TODAYDATE.tar
            mv Vasossone_vasoss_conf_backup_$TODAYDATE.tar.gz $BACKUPDIR
            echo "already backup $VASOSSCONF directory to $BACKUPDIR directory,backup file name is Vasossone_vasoss_conf_backup_$TODAYDATE.tar.gz"
            echo "at the $TODAYDATEFULL,you backup $VASOSSCONF directory to $BACKUPDIR directory,backup file name is Vasossone_vasoss_conf_backup_$TODAYDATE.tar.gz" >> $SCRIPTDIR/logs.log
        else
            echo "please you select again"
            echo "at the $TODAYDATEFULL,you ever select 3,but you canceled this operate" >> $SCRIPTDIR/logs.log
        fi
        ;;
   *)
        echo -e "You not select number,but you enter a path,please you be sure of this diretory exist:([Y/y] or [N/n])\c"
        read YORN
        echo $dirpath
        if [ "$YORN" = "Y" -o "$YORN" = "y" ]
        then
                if [ -d $dirpath ]
                then
                        echo "execute backup program ..."
                        cd $dirpath
                        tar cvf Vasossone_other_backup_$TODAYDATE.tar ./* >> $SCRIPTDIR/logs.log 2>&1
                        gzip Vasossone_other_backup_$TODAYDATE.tar >> $SCRIPTDIR/logs.log 2>&1
                        mv Vasossone_other_backup_$TODAYDATE.tar.gz $BACKUPDIR
                        echo "already backup $dirpath directory to $BACKUPDIR directory,backup file name is Vasossone_other_backup_$TODAYDATE.tar.gz"
                        echo "at the $TODAYDATEFULL,you backup $dirpath directory to $BACKUPDIR directory,backup file name is Vasossone_other_backup_$TODAYDATE.tar.gz" >> $SCRIPTDIR/logs.log
                else
                        echo "you enter path not exist,please check you enter and again"
                        echo "at the $TODAYDATEFULL,you enter the path of you need backup,but this directory is not exist" >> $SCRIPTDIR/logs.log
                fi
        else
            echo "please you select again"
            echo "at the $TODAYDATEFULL,you enter the path of you need backup,but this operate be canceled by you" >> $SCRIPTDIR/logs.log
        fi
        ;;
esac


word.txt 文件得内容是:
您好,您所执行的这个程序是手工备份应用程序的SHELL脚本,请选择您要备份的目录,如果下列选项中没有您希望备份的目录,请手工输入:
您输入的路径不正确,请查证后再次输入
 
本貼由Cu zdm所有
阅读(1215) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~