0

In a backup directory I want to keep all 7 days generated files and want to delete the older days.

I tried with the -mtime option and observed the script for 3-4 days it was working. But after 5-6 days it stopped working. So deletion didnt happen and directory is full now. It seems like the -mtime is not working.

Please note also I have a cron running which automate this.

10 3 * * * su - cassandra -c /opt/cassandra/scripts/backup_cassandra >> /tmp/backup.log

Here is the script I m using :

#!/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

Please help in a solution to this.

terdon
  • 242,166
  • mtime is last modified time. Are you sure the generated files are untouched? Have you tried adding the -f (force remove) flag to rm? – Kaffe Myers Feb 20 '22 at 19:38
  • You have a few options, one being: https://unix.stackexchange.com/questions/386714/finding-and-removing-files-older-than-30-days second https://unix.stackexchange.com/questions/102752/remove-all-files-created-before-a-certain-date/102767#102767 – Valentin Bajrami Feb 20 '22 at 21:22

1 Answers1

1

You are find ing files EXACTLY 8 days old. 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.

So - try -mtime +8

RudiC
  • 8,969