本文实例为大家分享了shell跨服务器备份文件的具体代码,供大家参考,具体内容如下
需求:查询某个文件夹下的所有文件,将文件修改时间小于当前时间,并大于当前时间前一天的文件备份到另一台服务器对应的文件夹下
思路:
1、递归查询文件夹下的文件
2、如果文件夹中含有空格,则将文件按列显示,并将IFS设为 x0A
代码如下:
#! /bin/bashfunction 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/huip=root@192.168.11.66read_dir $path $ip
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
- 自动化下载并检测ftp文件备份的shell脚本
- Shell脚本自动删除指定大小以上的备份文件
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中
- 3个备份系统文件并邮件发送的Shell脚本分享
- shell备份文件、重命名文件、删除指定文件的3个脚本分享