#!/bin/sh
#設定變量
bak_path=/root/bak_linux
date=$(date +%Y%m%d)
log_file=$bak_path/$date#log.log
#把執行結果寫到日志中
exec 1>>$log_file 2>&1
#把要備份的目錄打包放到$bak_path目錄下
tar -zcvf $bak_path/$date#boot.tar.gz /boot
tar -zcvf $bak_path/$date#etc.tar.gz /etc
tar -zcvf $bak_path/$date#var.tar.gz /var
echo "############\n"
echo $?
#上傳備份文件
ftp -i -n -v << FTPIT
open 192.168.0.27
user 111 111
binary
lcd $bak_path
mput *.tar.gz
put *#log.log
by
FTPIT
echo "############\n"
echo $?
#刪除上傳完畢的.tar和.log文件
rm -rf $bak_path/*#*.tar
rm -rf $bak_path/*#log.log