寫如下腳本,保存為/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分執行備份操作。