DATETIMES=`date -d"1 day ago" +"%F"`
#echo $DATETIMES
#cat /home/q/system/qdam.bi.qihoo.net/go_run/log/access.$DATETIMES.log
if [ ! -f /home/q/system/qdam.bi.qihoo.net/go_run/log -name access.$DATETIMES.log ];then
echo "文件不存在"
else
echo "文件存在"
sudo chmod 441 /home/q/system/qdam.bi.qihoo.net/go_run/log/access.$DATETIMES.log
#remote_backup_dir="/zl/div1" /home/zhaoliang-dc/zl
remote_backup_dir="/home/zhaoliang-dc/zl"
remote_user="zhaoliang-dc"
remote_host="10.108.211.126"
remote_port="22"
#COMMOND="ssh -p $remote_port $remote_user@$remote_host 'test ! -d \"$remote_backup_dir \" && mkdir -p \"$remote_backup_dir/ \"'"
#eval $COMMOND
backup_dir="/home/q/system/qdam.bi.qihoo.net/go_run/log/access.$DATETIMES.log"
COMMOND="sudo scp -P $remote_port -r $backup_dir $remote_user@$remote_host:$remote_backup_dir"
eval $COMMOND
#sudo cp /home/q/system/qdam.bi.qihoo.net/go_run/log/access.$DATETIMES.log /zl/div1
fi
===================下面是参考========================
#!/bin/bash#定义备份目录,备份时间及用到的命令backup_dir="/home/bak_file"date=`date +%Y-%m-%d`#删除旧的备份数据find $backup_dir -name "file_*" -type d -ctime +3 |xargs rm -rf;#检测备份目录是否存在,不存在则建立目录test ! -d "$backup_dir/file_$date" && mkdir -p "$backup_dir/file_$date/"#备份目录tar -zcf $backup_dir/file_$date/web.tgz /home/wwwroot#copy到远程服务器配置remote_backup_dir="/home/bak_file_all/"`hostname`#定义远程连接说明remote_user="root"#ssh-keygen -t rsa#cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keysremote_host="192.168.1.2"remote_port="22"#删除旧的备份数据COMMOND="ssh -p $remote_port $remote_user@$remote_host 'find $remote_backup_dir -name \"file_*\" -type d -ctime +3 |xargs rm -rf'"eval $COMMOND#检测备份目录是否存在,不存在则建立目录COMMOND="ssh -p $remote_port $remote_user@$remote_host 'test ! -d \"$remote_backup_dir \" && mkdir -p \"$remote_backup_dir/ \"'"eval $COMMONDCOMMOND="scp -P $remote_port -r $backup_dir/file_$date $remote_user@$remote_host:$remote_backup_dir"eval $COMMOND