若/dev/hda1為windows下的fat32分區,則mkdir /mnt/win_c, /var/www為你要備份的目錄
寫如下腳本,保存為/root/backup_var_www.sh,加上執行權限。
#!/bin/bash
if ! grep -q '/dev/hda1' /proc/mounts
then
mount /dev/hda1 /mnt/win_c || exit
fi
backup_ball="/mnt/win_c/var_www_$(date +%F).tar.bz2"
if tar jcf $backup_ball /var/www
then
echo "$backup_ball backup succeeded. :)" | mail -s "backup OK" root
else
echo "$backup_ball backup failed. :(" | mail -s "backup FAILED" root
fi
然後crontab -e
加入
30 4 * * 5 /bin/bash /root/backup_var_www.sh
即在每周五的4:30分執行備份操作