tm

#!/bin/bash
RM=/bin/rm
CP=/bin/cp
MV=/bin/mv
TAR=/bin/tar
FIND=/usr/bin/find
DATE=`date +%d`
BACK=/backup
DIR_JIRA=/opt/atlassian/jira
DIR_JIRA_MNT=/mnt/service/jira
BACK_JIRA=/backup/jira
BACK_JIRA_MONTH=/backup/jira/month
BACK_JIRA_DAY=/backup/jira/day
inc_jira=/backup/jira/jira.inc
inc_jira_mnt=/backup/jira/jira-mnt.inc
inc_jira_day=/backup/jira/jira_day.inc
inc_jira_mnt_day=/backup/jira/jira-mnt_day.inc
if [ ! -d "$BACK" ]; then
/bin/mkdir /backup
fi
apt-get install cifs-utils -y
if /bin/mount | grep '10.1.6.13' > /dev/null; then
echo Alredy Mounted
else
while ! /bin/mount | grep '10.1.6.13' > /dev/null; do
echo Not mounted. Mounting...
sleep 5
mount.cifs //10.1.6.13/backup /backup/ -o username=test_user,password=pYeIpIBjG,iocharset=utf8,sec=ntlm,nosetuids,noperm,vers=1.0 0 0
done
fi
if [[ -d $BACK_JIRA && ! -d $BACK_JIRA_MONTH && ! -d $BACK_JIRA_DAY ]]; then
echo Folders are exists
else
/bin/mkdir -p $BACK_JIRA_MONTH
/bin/mkdir -p $BACK_JIRA_DAY
fi
#if [ $DATE = "01" ]; then
if [[ $DATE = "01" && ! -n $($FIND $BACK_JIRA_MONTH -name "full-opt.tar.gz" -mtime -1) && ! -n $($FIND $BACK_JIRA_MONTH -name "full-mnt.tar.gz" -mtime -1) ]]; then
$MV $BACK_JIRA_MONTH/full-opt.tar.gz $BACK_JIRA_MONTH/full-opt_arch_`date '+%Y-%m-%d-%H-%M'`.tar.gz
$MV $BACK_JIRA_MONTH/full-mnt.tar.gz $BACK_JIRA_MONTH/full-mnt_arch_`date '+%Y-%m-%d-%H-%M'`.tar.gz
$FIND $BACK_JIRA_MONTH/ -name "full-opt_arch*.tar.gz" -mtime +10 | xargs $RM -rf
$FIND $BACK_JIRA_MONTH/ -name "full-mnt_arch*.tar.gz" -mtime +10 | xargs $RM -rf
$RM $inc_jira
$RM $inc_jira_mnt
$TAR --create --ignore-failed-read --one-file-system --recursion --preserve-permissions --sparse --listed-incremental=$inc_jira --gzip --verbose --file=$BACK_JIRA_MONTH/full-opt.tar.gz $DIR_JIRA
$TAR --create --ignore-failed-read --one-file-system --recursion --preserve-permissions --sparse --listed-incremental=$inc_jira_mnt --gzip --verbose --file=$BACK_JIRA_MONTH/full-mnt.tar.gz $DIR_JIRA_MNT
echo > /opt/atlassian/jira/logs/catalina.out
$FIND $DIR_JIRA/logs -type f -mtime +60 | xargs $RM -rf
$FIND $DIR_JIRA_MNT/jira-data/log/ -type f -mtime +60 | xargs $RM -rf
else
$RM $inc_jira_day
$RM $inc_jira_mnt_day
$CP $inc_jira $inc_jira_day
$CP $inc_jira_mnt $inc_jira_mnt_day
$MV $BACK_JIRA_DAY/day-opt.tar.gz $BACK_JIRA_DAY/day-opt.`date '+%Y-%m-%d-%H-%M'`.tar.gz
$MV $BACK_JIRA_DAY/day-mnt.tar.gz $BACK_JIRA_DAY/day-mnt.`date '+%Y-%m-%d-%H-%M'`.tar.gz
for i in $( $FIND $BACK_JIRA_DAY/ -name "day-opt_*.tar.gz" -mtime +30 ); do rm -f $i; done
for i in $( $FIND $BACK_JIRA_DAY/ -name "day-mnt_*.tar.gz" -mtime +30 ); do rm -f $i; done
$TAR --create --ignore-failed-read --one-file-system --recursion --preserve-permissions --sparse --listed-incremental=$inc_jira_day --gzip --verbose --file $BACK_JIRA_DAY/day-opt.tar.gz $DIR_JIRA
$TAR --create --ignore-failed-read --one-file-system --recursion --preserve-permissions --sparse --listed-incremental=$inc_jira_mnt_day --gzip --verbose --file $BACK_JIRA_DAY/day-mnt.tar.gz $DIR_JIRA_MNT
fi
/bin/umount /backup
Добавить комментарий


Защитный код
Обновить