shell编程跨服务器备份文件

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

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

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

查看所有标签

猜你喜欢:

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

Head First Design Patterns

Head First Design Patterns

Elisabeth Freeman、Eric Freeman、Bert Bates、Kathy Sierra、Elisabeth Robson / O'Reilly Media / 2004-11-1 / USD 49.99

You're not alone. At any given moment, somewhere in the world someone struggles with the same software design problems you have. You know you don't want to reinvent the wheel (or worse, a flat tire),......一起来看看 《Head First Design Patterns》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换