官术网_书友最值得收藏!

Cleaning up old files

Puppet's tidy resource will help you clean up old or out-of-date files, reducing disk usage. For example, if you have Puppet reporting enabled as described in the section on generating reports, you might want to regularly delete old report files.

How to do it...

Let's get started.

  1. Modify your site.pp file as follows:
    node 'cookbook' {
      tidy { '/var/lib/puppet/reports':
        age     => '1w',
        recurse => true,
      }
    }
  2. Run Puppet:
    [root@cookbook clients]# puppet agent -t
    Info: Caching catalog for cookbook.example.com
    Notice: /Stage[main]/Main/Node[cookbook]/File[/var/lib/puppet/reports/cookbook.example.com/201409090637.yaml]/ensure: removed
    Notice: /Stage[main]/Main/Node[cookbook]/File[/var/lib/puppet/reports/cookbook.example.com/201409100556.yaml]/ensure: removed
    Notice: /Stage[main]/Main/Node[cookbook]/File[/var/lib/puppet/reports/cookbook.example.com/201409090631.yaml]/ensure: removed
    Notice: /Stage[main]/Main/Node[cookbook]/File[/var/lib/puppet/reports/cookbook.example.com/201408210557.yaml]/ensure: removed
    Notice: /Stage[main]/Main/Node[cookbook]/File[/var/lib/puppet/reports/cookbook.example.com/201409080557.yaml]/ensure: removed
    Notice: /Stage[main]/Main/Node[cookbook]/File[/var/lib/puppet/reports/cookbook.example.com/201409100558.yaml]/ensure: removed
    Notice: /Stage[main]/Main/Node[cookbook]/File[/var/lib/puppet/reports/cookbook.example.com/201408210546.yaml]/ensure: removed
    Notice: /Stage[main]/Main/Node[cookbook]/File[/var/lib/puppet/reports/cookbook.example.com/201408210539.yaml]/ensure: removed
    Notice: Finished catalog run in 0.80 seconds
    

How it works...

Puppet searches the specified path for any files matching the age parameter; in this case, 2w (two weeks). It also searches subdirectories (recurse => true).

Any files matching your criteria will be deleted.

There's more...

You can specify file ages in seconds, minutes, hours, days, or weeks by using a single character to specify the time unit, as follows:

  • 60s
  • 180m
  • 24h
  • 30d
  • 4w

You can specify that files greater than a given size should be removed, as follows:

size => '100m',

This removes files of 100 megabytes and over. For kilobytes, use k, and for bytes, use b.

Note

Note that if you specify both age and size parameters, they are treated as independent criteria. For example, if you specify the following, Puppet will remove all files that are either at least one day old, or at least 512 KB in size:

age => "1d",

size => "512k",

主站蜘蛛池模板: 大竹县| 古浪县| 罗平县| 绥德县| 封开县| 巴南区| 太湖县| 阿拉善右旗| 香港 | 克山县| 蓬莱市| 正蓝旗| 云阳县| 海安县| 康马县| 东港市| 封丘县| 奇台县| 安化县| 凤翔县| 界首市| 德保县| 琼结县| 杭锦后旗| 泗水县| 绥宁县| 石首市| 自贡市| 荣昌县| 江西省| 商城县| 广饶县| 华安县| 舟山市| 三河市| 富源县| 蓝山县| 清苑县| 丘北县| 菏泽市| 名山县|