Skip to content

Instantly share code, notes, and snippets.

@ratbeard
Created May 23, 2011 20:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ratbeard/987506 to your computer and use it in GitHub Desktop.
Save ratbeard/987506 to your computer and use it in GitHub Desktop.
Basic Implementation of Local Storage Adapter for Backup gem
# assuming running script from home dir, with local.rb inside the backup folder, load it:
require 'Backup/local'
Backup::Model.new(:my_backup, 'My Backup') do
archive :vim do |archive|
archive.add '/Users/mike.frawley/.vim'
end
store_with ::Backup::Storage::Local do |local|
local.path = '/tmp/backup2'
end
end
module ::Backup
module Configuration
module Storage
class Local < Base
class << self
# Path to save files to
attr_accessor :path
end
end
end
end
end
module ::Backup
module Storage
class Local < Base
attr_accessor :path
def initialize(&block)
load_defaults!
@path ||= '/var/backups'
instance_eval(&block) if block_given?
@time = TIME
end
def perform!
transfer!
cycle!
end
##
# Transfers the archived file to the specified Dropbox folder
def transfer!
Logger.message("#{ self.class } started transferring \"#{ local_file }\". to #{path}")
src = File.join(local_path, local_file)
dst = File.join(path, local_file)
FileUtils.mkdir_p(dst)
FileUtils.cp(src, dst)
end
##
# Removes the transferred archive file from the Dropbox folder
def remove!
file = File.join(remote_path, remote_file)
if File.exist? file
FileUtils.rm file
else
Logger.warn "Could not remove file \"#{ file }\"."
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment