最近在寫 crontab 來做 備援的動作(主要是參考鳥哥所提及的方法)
環境為 ubuntu
程式如下 (daily_back)
#!/bin/sh
day=`date +%Y%m%d`
basedir="/home/backup/daily"
cd $basedir
mkdir -m 700 $day
cd $day
mysqldump -u root -pxxxx -c xoops > backup_file_xoops.sql 2>> "$basedir"/backup_file_xoops.error
mysqldump -u root -pxxxx --all-databases > backup_file_ALL.sql 2>> "$basedir"/backup_file_ALL.error
cp -r /var/lib/mysql/xoops ./ 2> /dev/null
tar -cvf xoops.tar xoops/ 2> /dev/null
gzip xoops.tar 2> /dev/null
rm -r xoops 2> /dev/null














cd /home/backup
tar -cvf mysql."$day".tar daily/ 2>> tar.log
gzip mysql."$day".tar 2>> tar.log














id="xxx"
pw='xxx'
cd $basedir
ftp -n xxx.xxx.xxx.xxx >> "$basedir"/backup.ftp.log 2>&1 <<EOC
user $id $pw
binary
cd /FWserver_backup/Daily
put mysql."$day".tar.gz
bye
EOC
sync;sync
ps.
1.此程式的執行權限為 755
而
crontab 裡如下
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
#Backup(add by myself)
30 3 * * 0 root sh /home/backup/shell_script/weekly_back.sh
39 19 * * * root sh /home/backup/shell_script/daily_back.sh
問題如下
手動執行此程式,是很正常的執行,但讓crontab來執行時,卻會有問題,主要是他在做
tar -cvf mysql."$day".tar daily/ 2>> tar.log
gzip mysql."$day".tar 2>> tar.log
這段時,
手動所產生的大小是正常的大小,
但crontab來執行時,所產生的大小,是不正常的。
將不正常的檔案解開看過,裡面是 0kb的資料,也就是跟本沒有檔案打包壓縮 。
想請問各位大大,這是什麼問題造成的??