我写了这个备份脚本。我运行rsync
了tar
mysql 的转储。我想添加一些功能,例如电子邮件警报或某种统计数据。
这是脚本:
#!/bin/sh
DATE=`date +%D-%T`
ORIGIN=/home/share/
DEST=/media/BACKUP/mercurio/
LOGFILE=log.txt
echo "=====Starting backup on $DATE =====" >> $LOGFILE
echo "==Start rsync" >> $LOGFILE
rsync -arHu --delete --stats $ORIGIN $DEST/share >> $LOGFILE
wait
if [ $? -eq 0 ]
then
echo "==rsync ok" >> $LOGFILE
else
echo "==rsync ko" >> $LOGFILE
fi
echo "==Sart TAR" >> $LOGFILE
tar -czf $DEST`date +%y%m%d-%T`.tar.gz $ORIGIN
wait
if [ $? -eq 0 ]
then
echo "==tar ok" >> $LOGFILE
else
echo "==tar ko" >> $LOGFILE
fi
echo "==Start DUMP" >> $LOGFILE
mysqldump -u root -ptoor --all-databases > ${DEST}databases/`date +%Y%m%d-%k:%M`.sql
wait
if [$? -eq 0 ]
then
echo "==dump ok" >> $LOGFILE
else
echo "==dump ko" >> $LOGFILE
fi
echo "=====End Bakcup=====" >> $LOGFILE