shell跨服务器备份文件 shell编程跨服务器备份文件

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

shell跨服务器备份文件 shell编程跨服务器备份文件

Alighieri   2021-03-28 我要评论
想了解shell编程跨服务器备份文件的相关内容吗,Alighieri在本文为您仔细讲解shell跨服务器备份文件的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:shell跨服务器备份文件,shell服务器备份文件,shell备份文件,下面大家一起来学习吧。


需求:查询某个文件夹下的所有文件,将文件修改时间小于当前时间,并大于当前时间前一天的文件备份到另一台服务器对应的文件夹下

思路:

1、递归查询文件夹下的文件

2、如果文件夹中含有空格,则将文件按列显示,并将IFS设为 \x0A

代码如下:

#! /bin/bash
function read_dir(){
  IFS=$'\x0A'
    executeDate=`date -d ' -1 day ' +%F" "%T`
    executeDate1=`date -d "${executeDate}" +%s`

  for file in `ls $1 | paste`
  do
    modifyDate=`stat $1"/"$file -c %y`
      currentDate=`date +%F" "%T`
      currentDate1=`date -d "${currentDate}" +%s`
      modifyDate1=`date -d "${modifyDate}" +%s`

    if [ -d $1"/"$file ]
    then
      read_dir $1"/"$file
    elif [ $modifyDate1 -lt $currentDate1 ] && [ $modifyDate1 -gt $executeDate1 ];
    then 
        scp -r "$1""/" "$ip:"$path
    fi
  done
}

path=/root/hu
ip=root@192.168.11.66
read_dir $path $ip

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们