通过ftp及crontab自动每日备份网站数据

#!/bin/sh
f=`date +%Y%m%d`
cd /root
#export mysql data
mysqldump --opt --user=root --password=xxx--host=localhost score > score$f.sql
mysqldump --opt --user=root --password=xxx--host=localhost review > review$f.sql
mysqldump --opt --user=root --password=xxx--host=localhost typecho > typecho$f.sql
#pack file
tar -zcvf web$f.sql.tar.gz score$f.sql review$f.sql typecho$f.sql 
cd /data/www/default/
tar zcvf /root/web$f.php.tar.gz *.php *.txt *.js
tar zcvf /root/web$f.upload.tar.gz /data/www/default/usr/uploads
#tar zcvf /root/redis$f.tar.gz /var/lib/redis/dump.rdb
cd /root
#put to ftp server
ftp -v -n 103.99.179.123 << EOF
user backup backpwd
type binary
cd /backup
put web$f.sql.tar.gz
put web$f.php.tar.gz
put web$f.upload.tar.gz
#put redis$f.tar.gz
bye
EOF
#del local files
rm -rf /root/*.tar.gz
rm -rf /root/*.sql