在linux中常用的shell备份脚本

 

【转】 在linux中常用的shell备份脚本

备份脚本:
备份网站内容
#!/bin/bash
#指定运行的脚本shell
#运行脚本要给用户执行权限
bakdir=/backup
month=`date +%m`
day=`date +%d`
year=`date +%Y`
hour=`date +%k`
min=`date +%M`
dirname=$year-$month-$day-$hour-$min
mkdir $bakdir/$dirname
mkdir $bakdir/$dirname/conf
mkdir $bakdir/$dirname/web
mkdir $bakdir/$dirname/db
#备份conf,检测通过
gzupload=upload.tgz
cp /opt/apache2/conf/httpd.conf $bakdir/$dirname/conf/httpd.conf
cd /opt/apache2/htdocs/php
tar -zcvf $bakdir/$dirname/web/$gzupload ./upload
#远程拷贝的目录要有可写权限
scp -r /backup/$dirname [email protected]:/backup
备份数据库:
#!/bin/bash
#指定运行的脚本shell
#运行脚本要给用户执行权限
bakdir=/backup
month=`date +%m`
day=`date +%d`
year=`date +%Y`
hour=`date +%k`
min=`date +%M`
dirname=$year-$month-$day-$hour-$min
mkdir $bakdir/$dirname
mkdir $bakdir/$dirname/conf
mkdir $bakdir/$dirname/web
mkdir $bakdir/$dirname/db
#热备份数据库
cp /opt/mysql/my.cnf $bakdir/$dirname/db/my.cnf
cd /opt/mysql
mysqldump --opt -u zhy -p --password=1986 test>$bakdir/$dirname/db/test.sql
mysqldump --opt -u zhy -p --password=1986 phpwind>$bakdir/$dirname/db/phpwind.sql
#远程拷贝的目录要有可写权限
scp -r /backup/$dirname [email protected]:/backup

 

linux下监控磁盘使用空间的脚本脚本作用:找出磁盘中使用百分比大于等于85%的分区
运行效果如下(点击查看大图):
代码:
#!/bin/bash
a=`df | awk '/\<(8[5-9]|9[0-9]|100)% +/'|wc -l`
if [ $a -gt 0 ];then
df | awk 'BEGIN {print "*** find use of usbarea big 85% ***"}/\<8[5-9]%/||/\<9[0-9]/||/\<100%/ {print $1 " is " $5} END {print "******** End *********"}'
else
echo "no the used big 85%"
fi

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