dropbox_server_backup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+
9
+ gem "dropbox-sdk"
10
+ gem "term-ansicolor"
11
+
12
+ group :development do
13
+ gem "bundler", "~> 1.1.3"
14
+ gem "jeweler", "~> 1.6.4"
15
+ #gem "rcov"
16
+ gem "rdoc"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ dropbox-sdk (1.2)
5
+ json
6
+ git (1.2.5)
7
+ jeweler (1.6.4)
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ json (1.6.5)
12
+ rake (0.9.2.2)
13
+ rdoc (3.12)
14
+ json (~> 1.4)
15
+ term-ansicolor (1.0.7)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ bundler (~> 1.1.3)
22
+ dropbox-sdk
23
+ jeweler (~> 1.6.4)
24
+ rdoc
25
+ term-ansicolor
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Roman Snitko
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,13 @@
1
+ Dropbox Server Backup
2
+ =================
3
+
4
+ Allows you to upload the backups from your server into your Dropbox.
5
+
6
+ INSTALLATION
7
+ ------------
8
+
9
+ 1. `sudo gem install dropbox_server_backup`
10
+ 2. `sudo dropbox_server_backup` and follow the instructions
11
+
12
+ Essentially, you would have to add a list of files to `/etc/dropbox_server_backup/filelist` and
13
+ set up a cron task. All is explained during the setup process.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "dropbox_server_backup"
18
+ gem.homepage = "http://github.com/snitko/dropbox_server_backup"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Backs up stuff from your server to your Dropbox account}
21
+ gem.description = %Q{Backs up stuff from your server to your Dropbox account}
22
+ gem.email = "roman.snitko@gmail.com"
23
+ gem.authors = ["Roman Snitko"]
24
+ gem.executables << 'dropbox_server_backup'
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
38
+ require 'rdoc/task'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "dropbox_server_backup #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require "dropbox_server_backup"
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dropbox_server_backup}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Roman Snitko"]
12
+ s.date = %q{2012-03-26}
13
+ s.description = %q{Backs up stuff from your server to your Dropbox account}
14
+ s.email = %q{roman.snitko@gmail.com}
15
+ s.executables = ["dropbox_server_backup", "dropbox_server_backup"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.markdown"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.markdown",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/dropbox_server_backup",
29
+ "dropbox_server_backup.gemspec",
30
+ "lib/dropbox_server_backup.rb",
31
+ "lib/dropbox_server_backup_app.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/snitko/dropbox_server_backup}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{Backs up stuff from your server to your Dropbox account}
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<dropbox-sdk>, [">= 0"])
45
+ s.add_runtime_dependency(%q<term-ansicolor>, [">= 0"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.3"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
48
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<dropbox-sdk>, [">= 0"])
51
+ s.add_dependency(%q<term-ansicolor>, [">= 0"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.1.3"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
54
+ s.add_dependency(%q<rdoc>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<dropbox-sdk>, [">= 0"])
58
+ s.add_dependency(%q<term-ansicolor>, [">= 0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.1.3"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
61
+ s.add_dependency(%q<rdoc>, [">= 0"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,59 @@
1
+ require 'dropbox_sdk'
2
+ require 'term/ansicolor'
3
+ require 'dropbox_server_backup_app'
4
+
5
+ c = Term::ANSIColor
6
+
7
+ if ARGV[0] == "setup"
8
+
9
+ settings_path = ARGV[1] || "/etc/dropbox_server_backup"
10
+
11
+ print c.bold, c.on_yellow, "Setting up dropbox server backup utility...", c.clear, "\n"
12
+ begin
13
+
14
+ Dir.mkdir "/etc/dropbox_server_backup" unless File.exists?("#{settings_path}")
15
+ puts "First create a Dropbox app here: https://www.dropbox.com/developers/apps"
16
+ puts "and then click \"Enable additional users\""
17
+ puts "Done? Hit ENTER and continue."
18
+ $stdin.gets.chomp
19
+ puts "Now, please insert your Dropbox APP_KEY and press ENTER:"
20
+ app_key = $stdin.gets.chomp
21
+ puts ""
22
+ puts "and also your APP_SECRET:"
23
+ app_secret = $stdin.gets.chomp
24
+ app = DropboxServerBackupApp.create(:app_key => app_key, :app_secret => app_secret) do |auth_url|
25
+ puts "Now please visit this URL and approve the app: #{auth_url}"
26
+ puts "Done? Hit ENTER and continue."
27
+ $stdin.gets.chomp
28
+ end
29
+
30
+ puts "Settings written to #{settings_path}/credentials"
31
+ if File.exists?("#{settings_path}/credentials")
32
+ print "File #{settings_path}/credentials exists. Rewrite? (y/n): "
33
+ rewrite_credentials_file = ($stdin.gets.chomp == "y")
34
+ end
35
+ File.open("#{settings_path}/credentials", "w") { |f| f.puts app.session.serialize } unless rewrite_credentials_file == false
36
+
37
+ `touch #{settings_path}/filelist`
38
+ puts "#{c.green}Please add paths of the files you want to be backed up to the #{c.white}#{settings_path}/filelist#{c.clear}#{c.green}\nSeparate each file path with a newline#{c.clear}."
39
+ puts ""
40
+ puts "#{c.green}Then run #{c.white}crontab -e#{c.green} and put the following in it: #{c.white}0 0 * * * dropbox_server_backup\n #{c.green}to run it every day at midnight.#{c.clear}"
41
+
42
+
43
+ rescue Errno::EACCES
44
+ print c.red, "ERROR: it looks like you don't have access to your /etc directory\nwhere dropbox_server_backup utility stores its settings.", "\n"
45
+ print "Try running with ", c.bold, "sudo", c.clear, "\n"
46
+
47
+ rescue DropboxAuthError
48
+ print c.red, "ERROR: Dropbox authentication failed.", c.clear, "\n"
49
+ end
50
+
51
+ else
52
+
53
+ settings_path = ARGV[0] || "/etc/dropbox_server_backup"
54
+ app = DropboxServerBackupApp.new DropboxSession.deserialize(File.read("#{settings_path}/credentials"))
55
+ files = File.readlines("#{settings_path}/filelist").compact.uniq.map { |l| l.chomp }
56
+
57
+ files.each { |f| app.upload(f) unless f.empty? }
58
+
59
+ end
@@ -0,0 +1,49 @@
1
+ class DropboxServerBackupApp
2
+
3
+ attr_reader :session
4
+
5
+ def initialize(session)
6
+ @access_type = :app_folder
7
+ @session = session
8
+ @client = DropboxClient.new(session, @access_type)
9
+ end
10
+
11
+ def self.create(options)
12
+ session = DropboxSession.new(options[:app_key], options[:app_secret])
13
+ session.get_request_token
14
+ yield(session.get_authorize_url)
15
+ session.get_access_token
16
+ self.new(session)
17
+ end
18
+
19
+ def upload(filename)
20
+ dropbox_filename = File.basename(filename)
21
+ begin
22
+ metadata = @client.metadata(dropbox_filename)
23
+ unless metadata[:is_deleted]
24
+ log "deleting existing file #{dropbox_filename} from Dropbox"
25
+ @client.file_delete(dropbox_filename)
26
+ end
27
+ rescue DropboxError
28
+ end
29
+
30
+ begin
31
+ @client.put_file(dropbox_filename, open(filename))
32
+ log "uploading file #{filename} from Dropbox"
33
+ rescue DropboxAuthError
34
+ log("can't authenticate with dropbox.", :error)
35
+ rescue Errno::ENOENT
36
+ log("file #{filename} doesn't exist.", :error)
37
+ rescue Errno::EACCES
38
+ log("no access to file #{filename}.", :error)
39
+ end
40
+ end
41
+
42
+ def log(message, error=false)
43
+ full_message = ""
44
+ full_message += "ERROR: " if error
45
+ full_message += message
46
+ puts full_message
47
+ end
48
+
49
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dropbox_server_backup
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Roman Snitko
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-26 00:00:00 +04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ name: dropbox-sdk
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ requirement: *id001
34
+ type: :runtime
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ name: term-ansicolor
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ requirement: *id002
48
+ type: :runtime
49
+ - !ruby/object:Gem::Dependency
50
+ prerelease: false
51
+ name: bundler
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 21
58
+ segments:
59
+ - 1
60
+ - 1
61
+ - 3
62
+ version: 1.1.3
63
+ requirement: *id003
64
+ type: :development
65
+ - !ruby/object:Gem::Dependency
66
+ prerelease: false
67
+ name: jeweler
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 7
74
+ segments:
75
+ - 1
76
+ - 6
77
+ - 4
78
+ version: 1.6.4
79
+ requirement: *id004
80
+ type: :development
81
+ - !ruby/object:Gem::Dependency
82
+ prerelease: false
83
+ name: rdoc
84
+ version_requirements: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirement: *id005
94
+ type: :development
95
+ description: Backs up stuff from your server to your Dropbox account
96
+ email: roman.snitko@gmail.com
97
+ executables:
98
+ - dropbox_server_backup
99
+ - dropbox_server_backup
100
+ extensions: []
101
+
102
+ extra_rdoc_files:
103
+ - LICENSE.txt
104
+ - README.markdown
105
+ files:
106
+ - .document
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.markdown
111
+ - Rakefile
112
+ - VERSION
113
+ - bin/dropbox_server_backup
114
+ - dropbox_server_backup.gemspec
115
+ - lib/dropbox_server_backup.rb
116
+ - lib/dropbox_server_backup_app.rb
117
+ has_rdoc: true
118
+ homepage: http://github.com/snitko/dropbox_server_backup
119
+ licenses:
120
+ - MIT
121
+ post_install_message:
122
+ rdoc_options: []
123
+
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ hash: 3
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ requirements: []
145
+
146
+ rubyforge_project:
147
+ rubygems_version: 1.3.7
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: Backs up stuff from your server to your Dropbox account
151
+ test_files: []
152
+