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

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",

主站蜘蛛池模板: 塔河县| 海晏县| 安国市| 大方县| 普宁市| 永吉县| 通化市| 潜山县| 尤溪县| 福贡县| 梧州市| 肥乡县| 东阿县| 内江市| 田林县| 邳州市| 平定县| 孝义市| 苏尼特右旗| 大冶市| 九江市| 通辽市| 新龙县| 沁源县| 留坝县| 英山县| 茶陵县| 江口县| 诸城市| 凤凰县| 满洲里市| 新蔡县| 梅州市| 台东县| 万源市| 阿勒泰市| 余姚市| 保德县| 大荔县| 北宁市| 海阳市|