On 15 Apr 2005 20:44:32 +0700, catur <[EMAIL PROTECTED]> wrote:
> Salam hormat,
> 
> saya bikin shell script yg membackup database mysql tiap 10 menit (rh9),
> yang jadi masalah gimana adalah cara kita menghapus file hasil backup
> tsb, supaya ada hanya 5 file terakhir...
> 
> mis:
> ...
> backup200505150000.sql 2000 Apr 15 00:00
> backup200505150010.sql 2000 Apr 15 00:10
> backup200505150020.sql 2000 Apr 15 00:20
> backup200505150030.sql 2000 Apr 15 00:30
> backup200505150040.sql 2000 Apr 15 00:40
> backup200505150050.sql 2000 Apr 15 00:50
> backup200505150100.sql 2000 Apr 15 01:00
> 
> waktu dihapus ( setiap 1 jam ) yg tersisa
> 
> backup200505150020.sql 2000 Apr 15 00:20
> backup200505150030.sql 2000 Apr 15 00:30
> backup200505150040.sql 2000 Apr 15 00:40
> backup200505150050.sql 2000 Apr 15 00:50
> backup200505150100.sql 2000 Apr 15 01:00
> 
> mohon solusi atau ulrnya...
> 
> salam hormat,
> 
> catur pn

coba bantu pake ruby, taruh aja di cron

#!/usr/bin/env ruby
#file : autodelete.rb

# letak backup direktori 
backup_dir = "./"

#pattern file (bukan regex)
file_pattern = "*.txt"

# ambil list dan sort terbalik
files = Dir[backup_dir+file_pattern].sort{|a,b| b.downcase <=> a.downcase }

#hapus kecuali lima file terakhir
files[5..-1].each do |file|
  puts "hapus #{file}"
  File.delete file
end





-- 
http://ngopi.blogspot.com

--
Berhenti langganan: [EMAIL PROTECTED]
Arsip dan info: http://linux.or.id/milis

Kirim email ke