
백업 디렉터리에 7일 동안 생성된 모든 파일을 보관하고 오래된 파일을 삭제하고 싶습니다.
-mtime 옵션을 사용해 보았고 3~4일 동안 스크립트가 실행되는 것을 지켜보았습니다. 하지만 5~6일 정도 지나니 작동이 멈췄습니다. 따라서 삭제가 발생하지 않았으며 이제 디렉토리가 가득 찼습니다. -mtime이 작동하지 않는 것 같습니다.
또한 이것을 자동화하기 위해 cron을 실행하고 있습니다.
10 3 * * * su - cassandra -c /opt/cassandra/scripts/backup_cassandra >> /tmp/backup.log
이것은 내가 사용하는 스크립트입니다.
#!/bin/bash
set -x
export PATH=/opt/dse/bin/:/usr/lib/jvm/jre-1.8.0//bin:/sbin:/usr/sbin:/bin:/usr/bin:/root/bin
. /opt/cassandra/.env # source functions & password
# First we delete backup files older than 8 days.
find /data_cassandra/cassandra/backup/ -name "dc_east__*" -mtime 8 -exec rm {} \;
# cd to where the scrips are.
cd /opt/cassandra/scripts/
# And start the backups.
./backup.sh start -all # Kick off a full backup
이 문제를 해결하는 데 도움을 주세요.
답변1
귀하는 find
8일 전의 파일을 보고 있습니다. man find
:
A numeric argument n can be specified to tests (like -amin, -mtime, -gid, -inum, -links, -size, -uid and -used) as +n for greater than n, -n for less than n, n for exactly n.
그럼 - 한번 해보세요-mtime +8