當前位置:係統粉 >  係統教程 > 電腦軟件教程 >  Linux通過shell腳本怎麼備份係統 Linux通過shell腳本備份係統的步驟

Linux通過shell腳本怎麼備份係統 Linux通過shell腳本備份係統的步驟

時間:2017-07-04 來源:互聯網 瀏覽量:

今天給大家帶來Linux通過shell腳本怎麼備份係統,Linux通過shell腳本備份係統的步驟,讓您輕鬆解決問題。

  在Linux中,備份係統的方法有很多,除了使用備份工具外,還能通過shell備份Linux係統,下麵小編就給大家分享下備份Linux係統的shell腳本。

  腳本如下:

  #!/bin/sh

  #Automatic Backup Linux System Files

  #Author wugk 2013-11-22

  #Define Variable

  SOURCE_DIR=(

  $*

  )

  TARGET_DIR=/data/backup/

  YEAR=`date +%Y`

  MONTH=`date +%m`

  DAY=`date +%d`

  WEEK=`date +%u`

  FILES=system_backup.tgz

  CODE=$?

  if

  [ -z “$*” ];then

  echo -e “Please Enter Your Backup Files or Directories -------------------------------------------- Example $0 /boot /etc 。。。。。。”

  exit

  fi

  #Determine Whether the Target Directory Exists

  if

  [ ! -d $TARGET_DIR/$YEAR/$MONTH/$DAY ];then

  mkdir -p $TARGET_DIR/$YEAR/$MONTH/$DAY

  echo “This $TARGET_DIR is Created Successfully !”

  fi

  #EXEC Full_Backup Function Command

  Full_Backup()

  {

  if

  [ “$WEEK” -eq “7” ];then

  rm -rf $TARGET_DIR/snapshot

  cd $TARGET_DIR/$YEAR/$MONTH/$DAY ;tar -g $TARGET_DIR/snapshot -czvf $FILES `echo ${SOURCE_DIR[@]}`

  [ “$CODE” == “0” ]&&echo -e “-------------------------------------------- These Full_Backup System Files Backup Successfully !”

  fi

  }

  #Perform incremental BACKUP Function Command

  Add_Backup()

  {

  cd $TARGET_DIR/$YEAR/$MONTH/$DAY ;

  if

  [ -f $TARGET_DIR/$YEAR/$MONTH/$DAY/$FILES ];then

  read -p “These $FILES Already Exists, overwrite confirmation yes or no ? : ” SURE

  if [ $SURE == “no” -o $SURE == “n” ];then

  sleep 1 ;exit 0

  fi

  #Add_Backup Files System

  if

  [ $WEEK -ne “7” ];then

  cd $TARGET_DIR/$YEAR/$MONTH/$DAY ;tar -g $TARGET_DIR/snapshot -czvf $$_$FILES `echo ${SOURCE_DIR[@]}`

  [ “$CODE” == “0” ]&&echo -e “----------------------------------------- These Add_Backup System Files Backup Successfully !”

  fi

  else

  if

  [ $WEEK -ne “7” ];then

  cd $TARGET_DIR/$YEAR/$MONTH/$DAY ;tar -g $TARGET_DIR/snapshot -czvf $FILES `echo ${SOURCE_DIR[@]}`

  [ “$CODE” == “0” ]&&echo -e “------------------------------------------- These Add_Backup System Files Backup Successfully !”

  fi

  fi

  }

  Full_Backup;Add_Backup

  上麵就是Linux使用shell腳本備份係統的方法介紹了,通過上麵的腳本就能自動備份係統,但腳本可能還存在不足的地方,可自行改良優化。

以上就是Linux通過shell腳本怎麼備份係統,Linux通過shell腳本備份係統的步驟教程,希望本文中能幫您解決問題。

我要分享:
版權信息

Copyright @ 2011 係統粉 版權聲明 最新發布內容 網站導航