BudgetTracker

From ICELabWiki

Jump to: navigation, search

This is an in-house budget & inventory tracker.

Contents

[edit] Plans

  • Show venues and budget-pre-venue?
  • Filter shopping list by venue

[edit] Backups

Every day, the database will be sent to the RIT Ice Lab email, as well as myself.

[edit] How it works

[edit] Improvements

It would be better if the database were bzipped. To do that, I'd need to:

  • make a temporary directory (probably with mktemp -d),
  • copy the database there,
  • run bzip2 on it,
  • send the mail,
  • and erase the directory.

[edit] Code

budget-database-backup.rb

#!/usr/bin/ruby

require 'fileutils'
require 'logger'

DATABASE_FILE = "/home/user/rails/Budget/db/development.sqlite2"
LAST_RUN_FILE = "/var/cache/budget-database-backup.time"

TO_MAILS = %q{edbrannin@gmail.com riticelab@gmail.com}
MAIL_SUBJECT = "Archer's Budget-backup for #{Time.now}"

last_run_at = File.stat(LAST_RUN_FILE).mtime rescue Time.at(0)
begin
  logger = Logger.new('/var/log/budget-backup.log')
  FileUtils.touch LAST_RUN_FILE
rescue
  logger = Logger.new STDERR
  logger.warn "Warning: Could not record the last-run-at time."
end

if last_run_at < File.stat(DATABASE_FILE).mtime
  command = %Q{mutt -a #{DATABASE_FILE} -s "#{MAIL_SUBJECT}" #{TO_MAILS}}
  logger.info command
  IO.popen(command, "r+") do |ios|
    ios << "This is the latest version of Archer's Budget database.  Guard it well."
  end
  logger.info "Sent the database."
end