Requirements: Query all files under a folder, change the file modification time to less than the current time, and be larger than the current time the previous day of the file backup to another server corresponding to the folder
Ideas:
1, recursive query folder under the file
2. If the folder contains spaces, the files are displayed as columns and IFS is set to \x0a
The code is as follows:
#!/bin/bashfunction Read_dir () {IFS=$'\x0a'executedate= ' date-d'-1 Day'+%F" "%T' ExecuteDate1= ' date-d"${executedate}"+%s` forFile in ' LS $1|Paste ' Domodifydate=`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"/"$fileElif [$modifyDate 1-lt$currentDate 1] && [$modifyDate 1-gt$executeDate 1 ]; Then SCP-R" $""/" "$ip:"$pathfi Done}path=/root/Huip[Email protected]192.168.11.66Read_dir$path $ip
Shell programming, backing up files across servers