RHEL 자동 백업 증가 파일

3332 단어 백업cronRHEL
백업 스크립트 활용:
#!/bin/bash
#    
#             
#   amountebak.sh or pandawillsbak.sh
#        $bakpp         
#     $bakpp          
#   /usr/backup/amountebak.sh or /usr/backup/pandawillsbak.sh


########## Init Path ########
#                 $bakpp、$project、$projectpp
TAR=/bin/tar
#          ,       
bakpp=/var/www/html/media/backupfiles/"$project"
#         ,      
project=media
projectpp=/var/www/html/media/root/
# parament for varible
ym=`date +%Y%m`
ymd=`date +%Y%m%d`
#           ,     ,       $bakpp   
monthbakpp=$bakpp/$ym
gidpp=$monthbakpp
gidshot=gid$project$ym
#         
fullname=$ym
#         
incrementalname=$ymd
# Record the location of the log
log=$bakpp/$project.log

############ chk_full #######################
#           ,         

#this function check fullbackup file exist or not , if not then create fullbackup now

chk_full()
{
if [ -e "$monthbakpp"/"$project"_"$ym"_full.tar.gz ];then
echo ""$project"_"$ym"_full.tar.gz file exist!! ====`date +%Y-%m-%d-%T` " >>$log
else
tar_full
fi
}
######### chk_incremental ########
#           
chk_incremental()
{
while [ -e "$monthbakpp"/"$project"_"$incrementalname"_incremental.tar.gz ]
do
incrementalname=`echo "$incrementalname + 0.1" | bc `
done
}
######## tar_incremental #######
#       
tar_incremental()
{
cd $projectpp
echo "BEIGIN_TIME=====`date +%Y-%m-%d-%T` ==== CREATE "$project"_"$incrementalname"_incremental.tar.gz" >> $log
sleep 3
$TAR -g $gidpp/$gidshot -zcf $monthbakpp/"$project"_"$incrementalname"_incremental.tar.gz $project
echo "END_TIME========`date +%Y-%m-%d-%T` ==== CREATE "$project"_"$incrementalname"_incremental.tar.gz" >> $log
}

######## tar_full ###########
tar_full()
{
touch $gidpp/$gidshot
cd $projectpp
echo "BEIGIN_TIME=====`date +%Y-%m-%d-%T` ==== CREATE "$project"_"$fullname"_full.tar.gz" >> $log
$TAR -g $gidpp/$gidshot -zcf $monthbakpp/"$project"_"$fullname"_full.tar.gz $project
echo "END_TIME========`date +%Y-%m-%d-%T` ==== CREATE "$project"_"$fullname"_full.tar.gz" >> $log
}

########### backup ##############################
#       ,                    
backup()
{
if [ -d $monthbakpp ]; then
   chk_full
   chk_incremental
   tar_incremental
else
mkdir -p $bakpp/$ym
tar_full
fi
}

########### let's begin #############
#    $bakpp    ,           
if [ -d $bakpp ];then
backup
else
mkdir -p $bakpp
backup
fi
#advice you can create a file for put backup file, eg /usr/cctcc
#crontab
#mini hours day month week command
# */5 * * * * /home/mmroot/zbb/aaa.sh
# 0 1 */1 * * /home/mmroot/zbb/aaa.sh
# tar -ztf test.tar.gz            

좋은 웹페이지 즐겨찾기