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.

2

1 Answer 1

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.