shell编程跨服务器备份文件

栏目: Linux · 发布时间: 8年前

内容简介:这篇文章主要介绍了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

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Machine Learning in Action

Machine Learning in Action

Peter Harrington / Manning Publications / 2012-4-19 / GBP 29.99

It's been said that data is the new "dirt"—the raw material from which and on which you build the structures of the modern world. And like dirt, data can seem like a limitless, undifferentiated mass. ......一起来看看 《Machine Learning in Action》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器