Created
May 17, 2011 18:25
-
-
Save thattommyhall/977048 to your computer and use it in GitHub Desktop.
Clean up files/folders older than 5 days on HDFS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "date" | |
five_days_ago = Date.parse(Time.now.to_s) - 5 | |
IO.popen("hadoop fs -lsr /tmp").each_line do |line| | |
permissions,replication,user,group,size,mod_date,mod_time,path = *line.split(/\s+/) | |
if (mod_date) | |
if Date.parse(mod_date.to_s) < five_days_ago | |
puts line | |
if permissions.split('')[0] == 'd' | |
puts "deleting #{path}" | |
`hadoop fs -rmr -skipTrash #{path}` | |
dirname = path | |
next | |
end | |
next if path.start_with? dirname | |
`hadoop fs -rm -skipTrash #{path}` | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment