由于vps不稳定,以防数据再丢失,所以写了如下的自动备份脚本:
[root@MyCloudServer sbin]# vi backup.sh
function send_mail()
{
to=$1
subject=$2
message=$3
attachment=$4
send_server="smtp.163.com"
from="xxxxxxx@163.com"
psw=<your password>
sender_name="xiaocunjie"
/usr/local/bin/sendEmail -s $send_server -xu "$from" -xp $psw -o message-charset=utf-8 -f $from -u "$subject" -m "$message" -t $to -a $attachment
}
backup_file=$(date +"%Y%m%d").tar.bz2
cd /data
rm -f $backup_file
tar cjvf $backup_file . --exclude=./*.tar.bz2 --exclude=./lost+found
send_mail <your qq num>@qq.com "backup_$(date +%Y%m%d)" "this is a backup file, pls check.\nYours $(date +%F)" $backup_file
如果怕你的资料丢失,可以用这个方法备份
脚本功能:每天定时把/data目录压缩后,以邮件附件的方式发到我的qq邮箱
[root@MyCloudServer sbin]# crontab -e
0 5 * * * /usr/local/sbin/backup.sh &
crontab再加一下
这样就非常方便了