SHELL脚本自动备份
#!/bin/sh #define 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\n--------------------------------------------\nExample $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 "--------------------------------------------\nThese 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 "-----------------------------------------\nThese 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 "-------------------------------------------\nThese Add_Backup System Files Backup Successfully !" fi fi } Full_Backup;Add_Backup
参考的网址:http://blog.51cto.com/wgkgood/1330200
相关推荐
huha 2020-10-16
laisean 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
JohnYork 2020-10-16
Julyth 2020-10-16
applecarelte 2020-10-16
laisean 2020-09-27
flycappuccino 2020-09-27
liguojia 2020-09-27
wangzhaotongalex 2020-09-22
流年浅滩 2020-10-23
liujianhua 2020-10-22
woaimeinuo 2020-10-21
tufeiax 2020-09-03
laisean 2020-09-01
vvu 2020-09-16
libao 2020-09-16
Yyqingmofeige 2020-08-18
zhushixia 2020-08-17