Skip to content

Commit

Permalink
Merge remote-tracking branch 'seroy/master' into dev0.3.1
Browse files Browse the repository at this point in the history
Conflicts:
	astrails-safe.gemspec
	lib/astrails/safe.rb
  • Loading branch information
vitaly committed Jun 2, 2013
2 parents a4df2a4 + c65a36b commit 9f354f3
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 3 deletions.
2 changes: 1 addition & 1 deletion astrails-safe.gemspec
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
spec.description = <<-DESC
Astrails-Safe is a simple tool to backup databases (MySQL and PostgreSQL), Subversion repositories (with svndump) and just files.
Backups can be stored locally or remotely and can be enctypted.
Remote storage is supported on Amazon S3, Rackspace Cloud Files, or just plain SFTP.
Remote storage is supported on Amazon S3, Rackspace Cloud Files, or just plain FTP/SFTP.
DESC
spec.summary = %Q{Backup filesystem and databases (MySQL and PostgreSQL) locally or to a remote server/service (with encryption)}
spec.homepage = "http://astrails.com/astrails-safe"
Expand Down
4 changes: 3 additions & 1 deletion lib/astrails/safe.rb
Expand Up @@ -3,6 +3,7 @@
require "aws/s3"
require "cloudfiles"
require 'net/sftp'
require 'net/ftp'
require 'fileutils'
require 'benchmark'

Expand Down Expand Up @@ -33,6 +34,7 @@
require 'astrails/safe/s3'
require 'astrails/safe/cloudfiles'
require 'astrails/safe/sftp'
require 'astrails/safe/ftp'

module Astrails
module Safe
Expand All @@ -50,7 +52,7 @@ def safe(&block)
].each do |klass, path|
if collection = config[*path]
collection.each do |name, c|
klass.new(name, c).backup.run(c, :gpg, :gzip, :local, :s3, :cloudfiles, :sftp)
klass.new(name, c).backup.run(c, :gpg, :gzip, :local, :s3, :cloudfiles, :sftp, :ftp)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/astrails/safe/config/builder.rb
Expand Up @@ -4,7 +4,7 @@ module Config
class Builder
COLLECTIONS = %w/database archive repo/
ITEMS = %w/s3 cloudfiles key secret bucket api_key container service_net path gpg password keep local mysqldump pgdump command options
user host port socket skip_tables tar files exclude filename svndump repo_path sftp/
user host port socket skip_tables tar files exclude filename svndump repo_path sftp ftp /
NAMES = COLLECTIONS + ITEMS
def initialize(node)
@node = node
Expand Down
85 changes: 85 additions & 0 deletions lib/astrails/safe/ftp.rb
@@ -0,0 +1,85 @@
module Astrails
module Safe
class Ftp < Sink

protected

def active?
host && user
end

def path
@path ||= expand(config[:ftp, :path] || config[:local, :path] || ":kind/:id")
end

def save
raise RuntimeError, "pipe-streaming not supported for FTP." unless @backup.path

puts "Uploading #{host}:#{full_path} via FTP" if $_VERBOSE || $DRY_RUN

unless $DRY_RUN || $LOCAL
if !port
port = 21
end
Net::FTP.open(host) do |ftp|
ftp.connect(host, port)
ftp.login(user, password)
puts "Sending #{@backup.path} to #{full_path}" if $_VERBOSE
begin
ftp.put(@backup.path, full_path)
rescue Net::FTPPermError
puts "Ensuring remote path (#{path}) exists" if $_VERBOSE
end
end
puts "...done" if $_VERBOSE
end
end

def cleanup
return if $LOCAL || $DRY_RUN

return unless keep = @config[:keep, :ftp]

puts "listing files: #{host}:#{base}*" if $_VERBOSE
if !port
port = 21
end
Net::FTP.open(host) do |ftp|
ftp.connect(host, port)
ftp.login(user, password)
files = ftp.nlst(path)
pattern = File.basename("#{base}")
files = files.reject{ |x| !x.start_with?(pattern)}
puts files.collect {|x| x} if $_VERBOSE

files = files.
collect {|x| x }.
sort

cleanup_with_limit(files, keep) do |f|
file = File.join(path, f)
puts "removing ftp file #{host}:#{file}" if $DRY_RUN || $_VERBOSE
ftp.delete(file) unless $DRY_RUN || $LOCAL
end
end
end

def host
@config[:ftp, :host]
end

def user
@config[:ftp, :user]
end

def password
@config[:ftp, :password]
end

def port
@config[:ftp, :port]
end

end
end
end
9 changes: 9 additions & 0 deletions templates/script.rb
Expand Up @@ -46,6 +46,15 @@
# path ":kind/:id" # this is the default
# end

## uncomment to enable uploads via FTP
# ftp do
# host "YOUR_REMOTE_HOSTNAME"
# user "YOUR_REMOTE_USERNAME"
# # port "NON STANDARD FTP PORT"
# password "YOUR_REMOTE_PASSWORD"
# path ":kind/:id" # this is the default
# end

## uncomment to enable GPG encryption.
## Note: you can use public 'key' or symmetric password but not both!
# gpg do
Expand Down

0 comments on commit 9f354f3

Please sign in to comment.