xref: /dragonfly/bin/cpdup/scripts/do_cleanup (revision 37de577a)
1#!/bin/csh
2#
3# $DragonFly: src/bin/cpdup/scripts/do_cleanup,v 1.1 2006/09/16 21:57:10 dillon Exp $
4
5source params
6
7if ( "$argv" == "" ) then
8	echo "./do_cleanup percentage"
9	exit 1
10endif
11
12set full = $argv[1]
13
14while (1)
15    set dcap = `df -i $cleaning_path | tail -1 | awk '{ print $5; }' | sed -e 's/%//'`
16    set icap = `df -i $cleaning_path | tail -1 | awk '{ print $8; }' | sed -e 's/%//'`
17    echo "space $dcap/$full inodes $icap/$full"
18
19    if ( $dcap < $full && $icap < $full ) then
20	break
21    endif
22
23    foreach i ( ${backup_nfs}/* )
24	set host = ${i:t}
25	if ( ! -d $backup_nfs/$host ) then
26	    continue
27	endif
28	set curbackup = `readlink $cleaning_path/mirrors/$host`
29	foreach item ( `ls -1da $cleaning_path/mirrors/$host.*` )
30	    if ( ! -d $item ) then
31		continue
32	    endif
33	    if ( "${item:t}" == "$curbackup" ) then
34		continue
35	    endif
36	    echo "Removing $item"
37	    # for safety, use a full path and do not rely on item's path
38	    #
39	    rm -rf $cleaning_path/mirrors/${item:t}
40	    break
41	end
42    end
43
44    # let the fs catch up and update the df info
45    #
46    sync
47    sync
48    foreach benice ( 1 2 3 4 5 )
49	sync
50	sleep 5
51    end
52    sync
53    sync
54end
55