Skip to content

Commit

Permalink
worked local backups into the Rsync class
Browse files Browse the repository at this point in the history
  • Loading branch information
Emerson Lackey committed Jun 29, 2011
1 parent b8e9317 commit f1e8cdb
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/backup/storage/rsync.rb
Expand Up @@ -25,15 +25,20 @@ class RSync < Base
# Path to store backups to
attr_accessor :path

##
# Path to store backups to
attr_accessor :local

##
# Creates a new instance of the RSync storage object
# First it sets the defaults (if any exist) and then evaluates
# the configuration block which may overwrite these defaults
def initialize(&block)
load_defaults!

@port ||= 22
@path ||= 'backups'
@port ||= 22
@path ||= 'backups'
@local ||= false

instance_eval(&block) if block_given?
write_password_file!
Expand Down Expand Up @@ -72,7 +77,11 @@ def connection
def transfer!
Logger.message("#{ self.class } started transferring \"#{ remote_file }\".")
create_remote_directories!
run("#{ utility(:rsync) } #{ options } #{ password } '#{ File.join(local_path, local_file) }' '#{ username }@#{ ip }:#{ File.join(remote_path, remote_file[20..-1]) }'")
if @local
run("#{ utility(:rsync) } #{ options } #{ password } '#{ File.join(local_path, local_file) }' '#{ File.join(remote_path, TIME+'.'+remote_file[20..-1]) }'")
else
run("#{ utility(:rsync) } #{ options } #{ password } '#{ File.join(local_path, local_file) }' '#{ username }@#{ ip }:#{ File.join(remote_path, remote_file[20..-1]) }'")
end
end

##
Expand All @@ -88,7 +97,11 @@ def remove!
# Creates (if they don't exist yet) all the directories on the remote
# server in order to upload the backup file.
def create_remote_directories!
connection.exec!("mkdir -p '#{ remote_path }'")
if @local
mkdir(remote_path)
else
connection.exec!("mkdir -p '#{ remote_path }'")
end
end

##
Expand Down

0 comments on commit f1e8cdb

Please sign in to comment.