Skip to content

Commit

Permalink
cleanup and path substitutions support (remove prefix)
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Mar 16, 2009
1 parent f7767d5 commit 68c702c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 39 deletions.
8 changes: 0 additions & 8 deletions lib/astrails/safe/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@ def command
"tar -cf - #{@config[:options]} #{tar_exclude_files} #{tar_files}"
end

def backup_filename
@backup_filename ||= "archive-#{@id}.#{timestamp}.tar"
end

protected

def default_path
"archive/#{@id}"
end

def tar_exclude_files
[*@config[:exclude]].compact.map{|x| "--exclude=#{x}"} * " "
end
Expand Down
2 changes: 1 addition & 1 deletion lib/astrails/safe/config/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Safe
module Config
class Builder
COLLECTIONS = %w/database archive/
ITEMS = %w/s3 key secret bucket path prefix gpg password keep local mysqldump options
ITEMS = %w/s3 key secret bucket path gpg password keep local mysqldump options
user socket tar files exclude/
NAMES = COLLECTIONS + ITEMS
def initialize(node)
Expand Down
26 changes: 13 additions & 13 deletions lib/astrails/safe/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Engine

def self.run(config, timestamp)
unless config
puts "No configuration found for #{name}"
puts "No configuration found for #{kind}"
return
end
config.each do |key, value|
Expand All @@ -19,7 +19,7 @@ def initialize(id, config, timestamp)
end

def run
puts "#{name}: #{@id}" if $_VERBOSE
puts "#{kind}: #{@id}" if $_VERBOSE

stream = Stream.new(@config, command, File.join(path, backup_filename))
stream.run # execute backup comand. result is file stream.filename
Expand All @@ -34,24 +34,24 @@ def run

protected

def name
def kind
self.class.name.split('::').last.downcase
end

def backup_filename
@backup_filename ||= "#{kind}-#{id}.#{timestamp}.tar"
end

def expand(path)
path.gsub(/:kind\b/, kind).gsub(/:id\b/, id)
end

def s3_path
@s3_path ||=
File.join(
@config[:s3, :path] || "",
@config[:s3, :prefix] || "#{name}/#{id}"
)
@s3_path ||= expand(@config[:s3, :path] || ":kind/:id")
end

def path
@path ||=
File.expand_path(File.join(
@config[:path] || raise(RuntimeError, "missing :path in configuration"),
@config[:prefix] || "#{name}/#{id}"
))
@path ||= File.expand_path(expand(@config[:path] || raise(RuntimeError, "missing :path in configuration")))
end


Expand Down
8 changes: 0 additions & 8 deletions lib/astrails/safe/mysqldump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@ def command
"mysqldump --defaults-extra-file=#{password_file} #{@config[:options]} #{mysql_skip_tables} #{@id}"
end

def backup_filename
@backup_filename ||= "mysql-#{@id}.#{timestamp}.sql"
end

protected

def default_path
"mysql/#{@id}"
end

def password_file
Astrails::Safe::TmpFile.create("mysqldump") do |file|
file.puts "[mysqldump]"
Expand Down
2 changes: 1 addition & 1 deletion safe.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "safe"
s.version = "0.0.6"
s.version = "0.0.7"
s.date = "2009-03-15"
s.summary = "Astrails Safe"
s.email = "we@astrails.com"
Expand Down
16 changes: 8 additions & 8 deletions templates/script.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
safe do
# global path
# actual backup oath is :path/:prefix/:filename
# you can set :path for all backups (or once globally here)
path "/backup"
# supported substitutions:
# :kind -> backup 'engine' kind, e.g. "mysqldump" or "archive"
# :id -> backup 'id', e.g. "blog", "production", etc.
# you can set separate :path for all backups (or once globally here)
path "/backup/:kind/:id"

## uncomment to enable uploads to Amazon S3
## Amazon S3 auth (optional)
Expand Down Expand Up @@ -32,8 +34,8 @@
# backup mysql databases with mysqldump
mysqldump do
# you can override any setting from parent in a child:
# local path override for mysqldump
prefix "/mysql"
path "/backup/mysql/:id"

options "-ceKq --single-transaction --create-options"

user "astrails"
Expand All @@ -43,16 +45,14 @@
socket "/var/run/mysqld/mysqld.sock"

# database is a 'collection' element. it must have a hash or block parameter
# it will be 'collected' in a 'databases', with database name (1st arg) used as hash key
# it will be 'collected' in a 'databases', with database id (1st arg) used as hash key
# the following code will create mysqldump/databases/blog and mysqldump/databases/mysql ocnfiguration 'nodes'

# backup database with default values
# database :blog

# backup overriding some values
# database :production do
# # default prefix for this backup is mysqldump/production, you can override it here.
# # prefix "production/mysql"
# # you can override 'partially'
# keep :local => 3
# # keep/local is 3, and keep/s3 is 20 (from parent)
Expand Down

0 comments on commit 68c702c

Please sign in to comment.