2017-09-18 17 views
0

我试图用很少经验的logrotate,目前正在运行我将文件旋转,压缩和重命名到同一文件夹中。现在我需要而不是将文件放在同一个地方,我需要让他们放在另一个位置。他们还需要具有相同的文件夹结构,如果不存在,则需要创建新文件夹。所有的压缩文件需要被添加,而不是覆盖现有的文件多个子目录中的Logrotate文件在同一文件夹结构中备份位置

我在想,olddir将他们放入目标文件夹,但不知道如何让它放在相应的文件夹或创建它如果它还不在那里。

实施例源

无功/日志/ DEVICE1/*。登录

无功/日志/设备2/*。登录

无功/日志/设备3/*。登录

实施例目的地下降。广州文件到

选择/存档/ DEVICE1/

Ø PT/archvie /设备2/

(需要创建选择/存档/设备3,把旋转的文件在这里)

回答

0

最终没有找到一种方法,用logrotate的移动,但与脚本做上来同样的事情。非常简单,不会为超过1级的子文件夹工作。

#!/bin/bash 

source="/opt/log/host" 
destination="/opt/archive/" 

for i in $(find $source -maxdepth 2 -type f -name "*.gz") 
do 

#removing /opt/log/host from string 
dd="$(echo "$i" | sed -e 's#^/opt/log/host/##')" 

#removing everything after the first/
ff=$(echo "$dd" | cut -f1 -d"/") 

#setting the correct destination string 
ee=$destination$dd 

#create new folders if they do not exist 
mkdir -p -- "$destination$ff" 

#move files 
mv $i $ee 

done 
相关问题