-4

We have a backup strategy where every day 6 db dumps are taken. We want to delete backups which are older than 7 days, but we also want to retain single backup of every day. The backup files are in the format 2015_08_09_01_00_01.sql.gz

Any help would be appreciated

Karthik K
  • 213
  • 3
  • 13

2 Answers2

1

Tried below commands which worked just fine.

find . -mtime +7 -mtime -24 | sort -n > testbackups.txt
sort -u -t_ -k5,5 testbackups.txt > testbackups2.txt
grep -v -x -f testbackups2.txt testbackups.txt > delbackups7.txt
cat delbackups7.txt | while read file ; do rm ~/"$file" ; done

I am listing files between 7 days and 24 days, retaining one of the backup out of 6 backups, then deleting the remaining files.

Karthik K
  • 213
  • 3
  • 13
0

In Linux Bash, you'll want something like /usr/bin/find /PATH/TO/BACKUPS/ -type d -mtime +6 -exec rm -r {} \. That will use the find command to find files in the /PATH/TO/BACKUPS/ that are older than 6 days and remove them. -type d is for directories

Coder-guy
  • 414
  • 6
  • 16