1

When I use locate on my server and the result is in my rsnapshot backup then I get all those duplicates.

I could use grep to filter out all rsnapshot files:

locate something_in_backup | grep -v /var/cache/rsnapshot

but then I would miss files in the backup that are coming from other servers.

How could I filter the output to show only results from the rsnapshot/daily.0/ folder?

rubo77
  • 2,469
  • 4
  • 34
  • 66
  • Best way would be to find the scripts that build the locate database and add the directories you want to filter to the blacklist in the script. – user10489 Dec 15 '21 at 05:34
  • Good idea, but I don't want that, because, I need all old backupped files in the locate database also – rubo77 Dec 15 '21 at 06:03
  • If you don't want to prune the database, then `grep -v` is your friend. Locate can do some pattern matching, but it doesn't have a blacklist feature. Although it can filter by permissions, so you could make the directories unsearchable to some users. – user10489 Dec 15 '21 at 06:15

1 Answers1

1

You can use regular expressions in the grep command:

locate something_in_backup | grep -v 'rsnapshot/\(hourly.[1-5]\|daily\|weekly\|monthly\)'

or if you don't backup hourly:

locate something_in_backup | grep -v 'rsnapshot/\(daily.[1-7]\|weekly\|monthly\)'

note the right escaping of pipe and brackets

rubo77
  • 2,469
  • 4
  • 34
  • 66