⑴在Linux中,备份系统的方法有很多,除了使用备份工具外,还能通过shell备份Linux系统,下面小编就给大家分享下备份Linux系统的shell脚本。
⑵#!/bin/sh
⑶#Automatic Backup Linux System Files
⑷#Author wugk --
⑸#Define Variable
⑹SOURCE_DIR=(
⑺TARGET_DIR=/data/backup/
⑻YEAR=`date +%Y`
⑼MONTH=`date +%m`
⑽DAY=`date +%d`
⑾WEEK=`date +钹>
⑿FILES=system_backup.tgz
⒀[ -z “$*” ];then
⒁echo -e “Please Enter Your Backup Files or Directories
⒂--------------------------------------------
⒃Example $ /boot /etc 。。。。。。”
⒄#Determine Whether the Target Directory Exists
⒅[ ! -d $TARGET_DIR/$YEAR/$MONTH/$DAY ];then
⒆mkdir -p $TARGET_DIR/$YEAR/$MONTH/$DAY
⒇echo “This $TARGET_DIR is Created Suessfully !”
⒈#EXEC Full_Backup Function mand
⒉Full_Backup(
⒊[ “$WEEK” -eq “” ];then
⒋rm -rf $TARGET_DIR/snapshot
⒌cd $TARGET_DIR/$YEAR/$MONTH/$DAY ;tar -g $TARGET_DIR/snapshot -czvf $FILES `echo ${SOURCE_DIR[]}`
⒍[ “$CODE” == “” ]&&echo -e “--------------------------------------------
⒎These Full_Backup System Files Backup Suessfully !”
⒏#Perform incremental BACKUP Function mand
⒐Add_Backup(
⒑cd $TARGET_DIR/$YEAR/$MONTH/$DAY ;
⒒[ -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 ;exit
⒖#Add_Backup Files System
⒗[ $WEEK -ne “” ];then
⒘cd $TARGET_DIR/$YEAR/$MONTH/$DAY ;tar -g $TARGET_DIR/snapshot -czvf $$_$FILES `echo ${SOURCE_DIR[]}`
⒙[ “$CODE” == “” ]&&echo -e “-----------------------------------------
⒚These Add_Backup System Files Backup Suessfully !”
⒛[ $WEEK -ne “” ];then
①cd $TARGET_DIR/$YEAR/$MONTH/$DAY ;tar -g $TARGET_DIR/snapshot -czvf $FILES `echo ${SOURCE_DIR[]}`
②[ “$CODE” == “” ]&&echo -e “-------------------------------------------
③These Add_Backup System Files Backup Suessfully !”
④Full_Backup;Add_Backup
⑤上面就是Linux使用shell脚本备份系统的方法介绍了,通过上面的脚本就能自动备份系统,但脚本可能还存在不足的地方,可自行改良优化。