- DevOps:Puppet,Docker,and Kubernetes
- Thomas Uphill John Arundel Neependra Khare Hideto Saito Hui Chuan Chloe Lee Ke Jou Carol Hsu
- 266字
- 2021-07-09 18:33:00
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.
- Modify your
site.pp
file as follows:node 'cookbook' { tidy { '/var/lib/puppet/reports': age => '1w', recurse => true, } }
- 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",
- LabVIEW虛擬儀器從入門到測控應用130例
- 精通MATLAB圖像處理
- 離散事件系統建模與仿真
- PyTorch深度學習實戰
- 模型制作
- 樂高創意機器人教程(中級 下冊 10~16歲) (青少年iCAN+創新創意實踐指導叢書)
- Hybrid Cloud for Architects
- 嵌入式操作系統
- JavaScript典型應用與最佳實踐
- 菜鳥起飛系統安裝與重裝
- Practical Big Data Analytics
- Microsoft System Center Confi guration Manager
- 計算機與信息技術基礎上機指導
- HTML5 Canvas Cookbook
- Azure PowerShell Quick Start Guide