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

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

查看所有标签

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

Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

Lincoln Stein、Doug MacEachern / O'Reilly Media, Inc. / 1999-03 / USD 39.95

Apache is the most popular Web server on the Internet because it is free, reliable, and extensible. The availability of the source code and the modular design of Apache makes it possible to extend Web......一起来看看 《Writing Apache Modules with Perl and C》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

MD5 加密
MD5 加密

MD5 加密工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具