Skip to content

Commit

Permalink
Add bin_path to config.
Browse files Browse the repository at this point in the history
  • Loading branch information
macournoyer committed Nov 27, 2009
1 parent 27aaee4 commit 2ab0de0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@ The MySQL user needs to have the RELOAD and the SUPER privileges, these can be g
Create a YAML config file:

mysql:
# Database name to backup
database: muffins_development
# Mysql user and password to execute commands
user: root
password: secret
# Path to mysql binaries, like mysql, mysqldump (optional)
bin_path: /usr/bin/
# Path to the binary logs, should match the bin_log option in your my.cnf
bin_log: /var/lib/mysql/binlog/mysql-bin

s3:
# S3 bucket name to backup to
bucket: db_backups
# S3 credentials
access_key_id: XXXXXXXXXXXXXXX
secret_access_key: XXXXXXXXXXXXXXXXXXXXXX


Create a full backup:

Expand Down
8 changes: 8 additions & 0 deletions config/sample.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
mysql:
# Database name to backup
database: muffins_development
# Mysql user and password to execute commands
user: root
password: secret
# Path to mysql binaries, like mysql, mysqldump (optional)
bin_path: /usr/bin/
# Path to the binary logs, should match the bin_log option in your my.cnf
bin_log: /var/lib/mysql/binlog/mysql-bin

s3:
# S3 bucket name to backup to
bucket: db_backups
# S3 credentials
access_key_id: XXXXXXXXXXXXXXX
secret_access_key: XXXXXXXXXXXXXXXXXXXXXX

11 changes: 6 additions & 5 deletions lib/mysql_s3_backup/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(options)
@password = options[:password]
@database = options[:database] || raise(ArgumentError, "database required")
@bin_log_path = options[:bin_log]
@bin_path = options[:bin_path]
end

def cli_options
Expand All @@ -20,23 +21,23 @@ def cli_options
end

def execute(sql)
run %{mysql -e "#{sql}" #{cli_options}}
run %{#{@bin_path}mysql -e "#{sql}" #{cli_options}}
end

def execute_file(file)
run "cat '#{file}' | mysql #{cli_options}"
run "cat '#{file}' | #{@bin_path}mysql #{cli_options}"
end

def dump(file)
cmd = "mysqldump --quick --single-transaction --create-options -u'#{@user}'"
cmd = "#{@bin_path}mysqldump --quick --single-transaction --create-options -u'#{@user}'"
cmd += " --flush-logs --master-data=2 --delete-master-logs" if @bin_log_path
cmd += " -p'#{@password}'" if @password
cmd += " #{@database} | gzip > #{file}"
run cmd
end

def restore(file)
run "gunzip -c #{file} | mysql #{cli_options}"
run "gunzip -c #{file} | #{@bin_path}mysql #{cli_options}"
end

def each_bin_log
Expand All @@ -50,7 +51,7 @@ def each_bin_log
end

def apply_bin_log(file)
cmd = "mysqlbinlog --database=#{@database} #{file} | mysql -u#{@user} "
cmd = "#{@bin_path}mysqlbinlog --database=#{@database} #{file} | mysql -u#{@user} "
cmd += " -p'#{@password}' " if @password
run cmd
end
Expand Down

0 comments on commit 2ab0de0

Please sign in to comment.