Ugly mail backup script
Created a small script with ruby thats being executed by a cronjob to automatically backup a mailserver thats uses the Maildir format on Solaris.
The script backups the user home dir’s (This is where the mail is located) to a mounted NFS partition from the backup server. The script also should delete all backups older then 7 days. This is where I had a problem because I am not a real programmer “yet” and I didn’t want to search how to store all in a text file or in a db. So here is what I did (I know it’s a pretty ugly way of doing it, if anyone wants to give me a better code, please do so :- ) )
#!/opt/csw/bin/ruby
#Ruby Mail Backup
#Created by Sander on 05-06-2007
#
require 'date'
class Date
def Date.now
return Date.jd(DateTime.now.jd)
end
end
dateBack = Date.now.to_s
dateDel1 = Date.now - 7
dateDel2 = Date.now - 50
#Deleting old backups (ugly workaround)
while dateDel2 < dateDel1
delstr = dateDel2.to_s
puts 'removing ' + delstr
system('rm /mnt/backup/mail/home' + delstr +'.tar')
dateDel2 = dateDel2 + 1
end
#Making backup of all home dir's
system('tar cf /mnt/backup/mail/home' + dateBack + '.tar /export/home/')