非常简单的shell备份脚本

所要备份的库,以参数的形式传递进去,删除30天以前的备份文件

备份目录若不存在就创建之,/back/mysql/


#!/bin/bash

DATABASE=$1

USERNAME="root"

PASSWD="redhat"

BACKUPDIR="/backup/mysql"

CURDATE=`date +%F`

lOG="/var/log/mysqlbackup.log"

[ $? -eq 1 ] || {

      echo "Usage: $0 DATE"

      exit 99

}


[ -d $BACKUPDIR ] || mkdir -p $BACKUPDIR


 mysqldump -u $USERNAME -p$PASSWD $DATEBASE >$BACKUPDIR/backup-$CURDATE.sql


[ $? -gt 0 ] && {

      echo -e "$CURDATE--mysql:backup $DATABASE error\n" >> $LOG

     exit 99

}



find $BACKUPDIR/ -ctime +30 -exec rm -rf {} \;


[ $? -gt 0 ]$${

     echo -e "CURDATE--mysql:delete 30 days ago backup files[error]\n" >>$LOG

}


你可能感兴趣的:(linux,shell,备份脚本)