@@ -7,11 +7,11 @@ class S3ConnectError < StandardError; end
77
88class BackupFu
99
10- def initialize ( period = 'daily' )
11- @period = period
10+ def initialize
1211 db_conf = YAML . load_file ( File . join ( RAILS_ROOT , 'config' , 'database.yml' ) )
1312 @db_conf = db_conf [ RAILS_ENV ] . symbolize_keys
1413 @fu_conf = YAML . load_file ( File . join ( RAILS_ROOT , 'config' , 'backup_fu.yml' ) ) . symbolize_keys
14+ @fu_conf [ :mysqldump_options ] ||= '--complete-insert --skip-extended-insert'
1515 @verbose = !@fu_conf [ :verbose ] . nil?
1616 check_conf
1717 create_dirs
@@ -29,7 +29,12 @@ def dump
2929 password = "--password=#{ @db_conf [ :password ] } "
3030 end
3131 full_dump_path = File . join ( dump_base_path , db_filename )
32- cmd = niceify "#{ mysqldump_path } --complete-insert --skip-extended-insert #{ host } #{ port } --user=#{ @db_conf [ :username ] } #{ password } #{ @db_conf [ :database ] } > #{ full_dump_path } "
32+ case @db_conf [ :adapter ]
33+ when 'postgresql'
34+ cmd = niceify "PGPASSWORD=#{ password } #{ dump_path } --user=#{ @db_conf [ :username ] } --host=#{ host } --port=#{ port } #{ @db_conf [ :database ] } > #{ full_dump_path } "
35+ when 'mysql'
36+ cmd = niceify "#{ dump_path } #{ @fu_conf [ :mysqldump_options ] } #{ host } #{ port } --user=#{ @db_conf [ :username ] } #{ password } #{ @db_conf [ :database ] } > #{ full_dump_path } "
37+ end
3338 puts cmd if @verbose
3439 `#{ cmd } `
3540
@@ -125,13 +130,21 @@ def check_conf
125130 raise BackupFuConfigError , 'Application name (app_name) key not set in config/backup_fu.yml.'
126131 elsif @fu_conf [ :s3_bucket ] == 'some-s3-bucket'
127132 raise BackupFuConfigError , 'S3 bucket (s3_bucket) not set in config/backup_fu.yml. This bucket must be created using an external S3 tool like S3 Browser for OS X, or JetS3t (Java-based, cross-platform).'
128- elsif @fu_conf [ :aws_access_key_id ] . include? ( '--replace me' ) || @fu_conf [ :aws_secret_access_key ] . include? ( '--replace me' )
129- raise BackupFuConfigError , 'AWS Access Key Id or AWS Secret Key not set in config/backup_fu.yml.'
133+ else
134+ # Check for access keys set as environment variables:
135+ if ENV . keys . include? ( 'AMAZON_ACCESS_KEY_ID' ) && ENV . keys . include? ( 'AMAZON_SECRET_ACCESS_KEY' )
136+ @fu_conf [ :aws_access_key_id ] = ENV [ 'AMAZON_ACCESS_KEY_ID' ]
137+ @fu_conf [ :aws_secret_access_key ] = ENV [ 'AMAZON_SECRET_ACCESS_KEY' ]
138+ elsif @fu_conf [ :aws_access_key_id ] . include? ( '--replace me' ) || @fu_conf [ :aws_secret_access_key ] . include? ( '--replace me' )
139+ raise BackupFuConfigError , 'AWS Access Key Id or AWS Secret Key not set in config/backup_fu.yml.'
140+ end
130141 end
131142 end
132143
133- def mysqldump_path
134- @fu_conf [ :mysqldump_path ] || 'mysqldump'
144+ def dump_path
145+ dump = { :postgresql => 'pg_dump' , :mysql => 'mysqldump' }
146+ # Note: the 'mysqldump_path' config option is DEPRECATED but keeping this in for legacy config file support
147+ @fu_conf [ :mysqldump_path ] || @fu_conf [ :dump_path ] || dump [ @db_conf [ :adapter ] . intern ]
135148 end
136149
137150 def dump_base_path
0 commit comments