Created
May 23, 2011 20:19
-
-
Save ratbeard/987506 to your computer and use it in GitHub Desktop.
Basic Implementation of Local Storage Adapter for Backup gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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