scp从远程指定目录拷贝文件到本地指定目录

时间:2022-09-11 05:20:54

scp从远程指定目录拷贝文件到本地指定目录

[root@picts ~]# cat /root/scp_pictures.sh
#!/bin/bash
# Function: copy files from remoute hosts to directory
# Author: davie
# Date: //
# 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
fi
if [ "$?" -eq ]; then
# 拷贝远程目录下的文件和目录到本地/www_webfiles/
scp -q -r -l -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 ~]#