diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-09-01 14:23:13 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-09-01 14:23:13 +0300 |
commit | aa48c0113be59350159788f9efd43d8736e87dcb (patch) | |
tree | 05f6ac39705efbf5acdd86e1629749c80f402409 | |
parent | 1c1930ac5260847b9b6e63caf3ba844be8a7d41f (diff) | |
download | beam-aa48c0113be59350159788f9efd43d8736e87dcb.tar.gz beam-aa48c0113be59350159788f9efd43d8736e87dcb.tar.bz2 |
Clean up remote files
* cleaner.in: Detect if the files are remote, use beam_exec
to remove them.
-rwxr-xr-x | cleaner.in | 28 |
1 files changed, 21 insertions, 7 deletions
@@ -67,6 +67,15 @@ case $# in | |||
67 | exit 1;; | 67 | exit 1;; |
68 | esac | 68 | esac |
69 | 69 | ||
70 | remote=${dir%%:*} | ||
71 | if [ "$remote" != "$dir" ]; then | ||
72 | beam_rsh="${backup_rsh:-ssh} $remote" | ||
73 | localdir=${dir#*:} | ||
74 | else | ||
75 | beam_rsh= | ||
76 | localdir=$dir | ||
77 | fi | ||
78 | |||
70 | thisweek=$(date +%U) | 79 | thisweek=$(date +%U) |
71 | 80 | ||
72 | # Warning: do not use shell arithmetic expansions on week numbers, | 81 | # Warning: do not use shell arithmetic expansions on week numbers, |
@@ -81,23 +90,28 @@ fi | |||
81 | $verbose \# removing from $dir files ending in $suffix and older than week $lastweek | 90 | $verbose \# removing from $dir files ending in $suffix and older than week $lastweek |
82 | 91 | ||
83 | if [ -z "$suffix" ]; then | 92 | if [ -z "$suffix" ]; then |
84 | find $dir -maxdepth 1 -type f -printf '%f\n' | 93 | beam_exec find $localdir -maxdepth 1 -type f -printf '%f>n' |
85 | else | 94 | else |
86 | find $dir -maxdepth 1 -type f -name "*$suffix" -printf '%f\n' | 95 | beam_exec find $localdir -maxdepth 1 -type f -name "*$suffix" -printf '%f>n' |
87 | fi | | 96 | fi | |
88 | while read name | 97 | while read name |
89 | do | 98 | do |
90 | $verbose \# considering $name | ||
91 | week=$(expr "$name" : '.*-\([0-9][0-9]*\)-[0-9][0-9]*-[0-9][0-9]*.*$') | 99 | week=$(expr "$name" : '.*-\([0-9][0-9]*\)-[0-9][0-9]*-[0-9][0-9]*.*$') |
92 | if [ $thisweek -ge $week ]; then | 100 | if [ $thisweek -ge $week ]; then |
93 | if [ $(expr $thisweek - $week) -gt $retainweeks ]; then | 101 | if [ $(expr $thisweek - $week) -gt $retainweeks ]; then |
94 | $verbose \# removing $name | 102 | echo $localdir/$name |
95 | $dry_run rm $dir/$name | ||
96 | fi | 103 | fi |
97 | else | 104 | else |
98 | if [ $(expr $thisweek + 54 - $week) -gt $retainweeks ]; then | 105 | if [ $(expr $thisweek + 54 - $week) -gt $retainweeks ]; then |
99 | $verbose \# removing $name | 106 | echo $localdir/$name |
100 | $dry_run rm $dir/$name | ||
101 | fi | 107 | fi |
102 | fi | 108 | fi |
109 | done | | ||
110 | if [ -z "$dry_run" ]; then | ||
111 | beam_exec xargs --no-run-if-empty rm | ||
112 | else | ||
113 | while read name | ||
114 | do | ||
115 | echo \# rm $name | ||
103 | done | 116 | done |
117 | fi | ||