N i c k M e r w i n . c o m http://nickmerwin.com ruby | 80's | iphone pics | what else? posterous.com Thu, 08 Oct 2009 13:42:00 -0700 Easily backup your Heroku database to S3 http://nickmerwin.com/easily-backup-your-heroku-database-to-s3 http://nickmerwin.com/easily-backup-your-heroku-database-to-s3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Heroku S3 Database backup task
# by Nick Merwin (Lemur Heavy Industries) 10.08.09
# * dumps db to yaml, gzip's and sends to S3
#
# Setup:
# 1) replace APP_NAME and BACKUP_BUCKET with your info
# 2) add config/s3.yml like so (same as Paperclip's):
# production:
# access_key_id: ...
# secret_access_key: ...
# 2) install the yaml_db plugin:
# script/plugin install git://github.com/adamwiggins/yaml_db.git
# 3) add aws-s3 to your .gems
#
# Usage:
# heroku rake backup
# rake backup remote=true # this will pull the db locally first
# * or add this to your cron.rake for hourly or nightly backups:
# Rake::Task['backup'].invoke
 
desc "backup db from heroku and send to S3"
task :backup => :environment do
 
  APP_NAME = '' # put your app name here
  BACKUP_BUCKET = 'heroku-db-backups' # put your backup bucket name here
 
  puts "Back up started @ #{Time.now}"
 
  puts "Pulling DB..."
  
  backup_name = "ew#{Time.now.to_i}.db"
  backup_path = "tmp/#{backup_name}"
  
  if ENV['remote'] == 'true'
    puts `heroku db:pull sqlite://#{backup_path} --app #{APP_NAME}`
  else
    YamlDb.dump backup_path
  end
  
  puts "gzipping db..."
  `gzip #{backup_path}`
 
  backup_name += ".gz"
  backup_path = "tmp/#{backup_name}"
  
  puts "Uploading #{backup_name} to S3..."
  
  config = YAML.load(File.open("#{RAILS_ROOT}/config/s3.yml"))[RAILS_ENV]
  AWS::S3::Base.establish_connection!(
      :access_key_id => config['access_key_id'],
      :secret_access_key => config['secret_access_key']
    )
    
  begin
    bucket = AWS::S3::Bucket.find BACKUP_BUCKET
  rescue AWS::S3::NoSuchBucket
    AWS::S3::Bucket.create BACKUP_BUCKET
    bucket = AWS::S3::Bucket.find BACKUP_BUCKET
  end
  
  AWS::S3::S3Object.store backup_name, File.read(backup_path), bucket.name, :content_type => 'application/x-gzip'
  
  puts "Done @ #{Time.now}"
end

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/505/DSC02775_2.JPG http://posterous.com/people/3ZNbqSsA Nick Merwin yickster Nick Merwin
Wed, 20 May 2009 16:39:27 -0700 Some links for learning Ruby &&|| Rails from scratch http://nickmerwin.com/some-links-for-learning-ruby-andand-rails-fro http://nickmerwin.com/some-links-for-learning-ruby-andand-rails-fro

A few people have been asking me for some direction on starting to learn Ruby or programming in general, so I've compiled some links to get started.

Ruby:

Ruby in Twenty Minutes

Why's (Poignant) Guide to Ruby

Try Ruby in your browser

Programming Ruby (online book) this is good to own for reference too

Other Ruby resources

Rails:
(the framework for creating web applications in Ruby)

Installing locally (along with RubyGems)

Setting up your development environment on OS X 10.5

Creating a weblog in 15 minutes with Rails 2 (this links to a .mov)

RailsGuides - Getting Started

Lots of screencasts on different rails topics

News:

Reddt:Ruby

Ruby Inside

Rails Inside

In general, I've always said the best way to tackle a new programming language or framework is to have a very clearly defined goal you're working towards.  Something that has been eating away at your soul and has to be conquered -- the LESS you can live without figuring it out, the better.  So get ready to pull some hair out and scream some WTF!?'s at your computer like a maniac (if you didn't already do so) on your way to figuring this all out.  But trust me it's worth it!  

Good luck all!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/505/DSC02775_2.JPG http://posterous.com/people/3ZNbqSsA Nick Merwin yickster Nick Merwin