我有一个日志备份,每天运行 5 次。
2.1G -rw-r--r-- 1 root root 2.1G Jan 25 03:50 xxxxxxx.jrnl.428612
514M -rw-r--r-- 1 root root 512M Jan 25 11:50 xxxxxxx.jrnl.428629
2.1G -rw-r--r-- 1 root root 2.1G Jan 25 19:50 xxxxxxx.jrnl.428664
18M -rw-r--r-- 1 root root 18M Jan 25 20:32 xxxxxxx.jrnl.428699
194M -rw-r--r-- 1 root root 193M Jan 25 23:50 xxxxxxx.jrnl.428704
我有一个脚本的开头,该脚本将在 04:00 运行以复制在两者之间创建的文件 03:45 和 03:55 到标记为“1”的子目录。
#!/bin/bash
# Daily Journal Backup Number 1
# Establish target directory
DIRsource="/mnt/Backup/INCREMENTAL/*"
DIRdestination="/mnt/Backup/Yesterday/JOURNAL/1"
# Calculate the current date, concatenate with specific target time
TIMESTART="$(date '+%Y'-'%d'-'%m') 03:45:00" # $TIMESTART returns 2018-25-01 03:45:00
TIMESTOP="$(date '+%Y'-'%d'-'%m') 03:55:00" # $TIMESTOP returns 2018-25-01 03:55:00
# If the destination directory is not empty, delete all files in it.
if [ "$(ls -A $DIRdestination)" ]; then
# "Take action $DIRdestination is not empty"
rm -f $DIRdestination/*
# Look for the files which have a modify time between 20:25:00 and 20:45:00 on the prior day
find $DIRsource -type f -newermt $TIMESTART ! -newermt $TIMESTOP -exec cp --preserve=timestamps {} $DIRdestination/ \;
脚本运行时出现此错误:
find: I cannot figure out how to interpret ‘2018-26-01’ as a date or time
我该如何解决这个解释问题?
最佳答案
日期的顺序应该是年-月-日,而不是年-日-月。所以将其更改为:
TIMESTART="$(date '+%Y-%m-%d 03:45:00')"
TIMESTOP="$(date '+%Y-%m-%d 03:55:00')"
关于linux - bash 错误 : find: I cannot figure out how to interpret ‘2018-26-01’ as a date or time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48466493/