scp从远程指定目录拷贝文件到本地指定目录
scp从远程指定目录拷贝文件到本地指定目录
[root@picts ~]# cat /root/scp_pictures.sh #!/bin/bash # Function: copy files from remoute hosts to directory # Author: davie # Date: 2018/3/15 # Version: 1.0 # Script name: /root/scp_pictures.sh DATE_TIME=`date +%Y_%m_%d_%H_%M_%S` TARGET_DIR='/www_webfiles' if [ ! -d "${TARGET_DIR}" ]; then mkdir -p "${TARGET_DIR}" else cd "${TARGET_DIR}" tar -czPf www_webfiles."${DATE_TIME}".tar.gz * sleep 180 fi if [ "$?" -eq 0 ]; then # 拷贝远程目录下的文件和目录到本地/www_webfiles/ scp -q -r -l 50000 -C root@122.10.84.129:/www_webfiles/* /www_webfiles/ fi chown -R www.www "${TARGET_DIR}"/* if [ ! -d /backup/ ]; then mkdir -p /backup/ fi find "${TARGET_DIR}"/* -name "*.gz" -type f -mtime -3 |xargs -i mv {} /backup/ # 删除14天前的压缩文档 find /backup/* -name "*.gz" -type f -mtime +14 -exec rm {} \; exit 0 [root@picts ~]#