2

I wrote a rsync script which uses find command to find all files which are older than 10 minutes and copies them to a remote server.

The relevant part of the code is:

print_log "------ Starting $0 -------"
find $filedir -name \*.gz -mmin +10 >> $varfile
for line in $(awk -F"/" '{print $4}' $varfile); do
  rsync -raPv --ignore-existing --remove-source-files --chmod=u+rwx $filedir/$line rsync://[email protected]/hpfiles/ --password-file /etc/rsync.passwd  
done

The problem I have is related to the find command, when running the script I get the following response while it hangs there and won't continue:

[appadmin@srv01 ~]$ /nfs/hadooper/rsync_hpfiles-lock.sh >> /var/log/rsync_hpfiles.log
find: File system loop detected; `/mass1/hpfiles_staging/.snapshot' is part of the same file system loop as `/mass1/hpfiles_staging'.
find: File system loop detected; `/mass1/hpfiles_staging/.snapshot' is part of the same file system loop as `/mass1/hpfiles_staging'.
^C^Z

I've tried the following things but to no avail:

find $filedir -name \*.gz -a ! -name ".snapshot" -mmin +10 >> $varfile
find $filedir -name \*.gz -a ! -type d -name ".snapshot" -mmin +10 >> $varfile
find $filedir -name -a ! -path "*/.snapshot/*" \*.gz -mmin +10 >> $varfile

How does my command should look in order to be able to exclude the .snapshot directory from the find command output?

2 Answers 2

4

find $filedir -name .snapshot -prune -o -name \*.gz -mmin +10 -print should do it.

3
  • The command now works in terms of displaying the files but the error is still shown
    – Itai Ganot
    Sep 21, 2015 at 8:37
  • Sorry, I don' t have an environment where I can test that. Although if it only prints the error (and doesn't hang), maybe just re-directing stderr to /dev/null might be good enough. Sep 21, 2015 at 10:31
  • While this excludes all folders below .snapshot, it does include the .snapshot folder itself. See ShadSterling's answer for an option that doesn't do this.
    – Mark Booth
    Feb 21, 2023 at 13:07
1

Pruning the name .snapshot works, but I prefer to prune the path /.snapshot:

find $filedir -path "/.snapshots" -prune -o -name \*.gz -mmin +10 -print >> $varfile
1
  • Yes, this. using -name .snapshot -prune leaves the top level .snapshot folder in the list, but -path /.snapshot -prune doesn't.
    – Mark Booth
    Feb 21, 2023 at 13:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .