1 |
On 01/20/14 14:37, Tanstaafl wrote: |
2 |
> On 2014-01-20 6:51 AM, Neil Bothwick <neil@××××××××××.uk> wrote: |
3 |
>> On Mon, 20 Jan 2014 06:38:40 -0500, Tanstaafl wrote: |
4 |
>> |
5 |
>>> The pertinent part of the script is: |
6 |
>>> |
7 |
>>>> # delete aged backup files, keeping 60 nightlies and 45 (5 days of) |
8 |
>>>> hourlies rm $(ls -1t $MySQL_BACKUP_DIR_nightly/* | tail -n +61) |
9 |
>>>> rm $(ls -1t $MySQL_BACKUP_DIR_hourly/* | tail -n +46) |
10 |
>>> |
11 |
>>> It works fine and does what it is supposed to, but the email I get as a |
12 |
>>> result of the script running says only this in the body: |
13 |
>>> |
14 |
>>> rm: missing operand |
15 |
>>> Try 'rm --help' for more information. |
16 |
>> |
17 |
>> Do you have a file with an odd name in either of those directories, |
18 |
>> particularly one starting with a - |
19 |
> |
20 |
> No, they are all sql.gz files, starting with the date, like: |
21 |
> |
22 |
> 2014-01-05_0958-hostname-all.sql.gz |
23 |
> |
24 |
>> You could try adding "echo rm $(ls -1t ..." to the script to see what it |
25 |
>> is actually trying to run. |
26 |
>> |
27 |
>> Or you could use find instead |
28 |
>> |
29 |
>> find $MySQL_BACKUP_DIR_nightly -type f -mtime +60 -exec rm {} + |
30 |
> |
31 |
> Ok, may try that... thx... |
32 |
|
33 |
|
34 |
find -exec (or the shorter find -delete) is the preffered tool for this |
35 |
job. As you have it, you are blindly deleting whatever happens to show |
36 |
up in ls and woe betide the results on the next run if one fails. |
37 |
|
38 |
find OTOH lets you specify exactly what you want to delete rather than |
39 |
doing text manipulation on ls output and praying it might coincide with |
40 |
what you want. [been there, done that, caused catastrophic data loss, |
41 |
bought lots of beer as penance] |
42 |
|
43 |
|
44 |
-- |
45 |
Alan McKinnon |
46 |
alan.mckinnon@×××××.com |