cloud_backup 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b1ddec795b76861727222e47c8a0142683df3ed
4
+ data.tar.gz: e7ae1367cce78dcdf79d14c1ae97f6568cbab49f
5
+ SHA512:
6
+ metadata.gz: 7d76d796542c55caa5106e7d037d3022167760f49bfb8add041a26e9c0b389c470e47a7b42fe04143c780b3edb9995f9c3b7b1dee4044c012fd0201ecdf3b8c0
7
+ data.tar.gz: d640d936a3bd3585500fa85e5beaf31a735508025fb7294270c128db09cb3d81d72e8a268ae15cf6e9f5210c5e295a6d1ae457b181a54973ca79144808797b08
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cloud_backup.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Serdar Dogruyol
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ ## What is it?
2
+
3
+ A tiny Ruby program to dump your Database and store it in the Cloud.
4
+
5
+ #### Currently supported DBs
6
+ - MySQL
7
+
8
+ #### Currently supported Clouds
9
+ - Dropbox
10
+
11
+ ##Requirements
12
+
13
+ The only requirements are working a Ruby installation and RubyGems.
14
+
15
+ For Dropbox : You also need to have a working Dropbox account of your own and need to create an app for yourself.
16
+
17
+ ##Configuration
18
+
19
+ All the configuration including your Dropbox app token and secret is done via settings.yml
20
+
21
+ ##How to
22
+
23
+ Just clone this repo
24
+
25
+ git clone https://github.com/Sdogruyol/dump-to-cloud
26
+
27
+ And bundle.
28
+
29
+ https://github.com/Sdogruyol/dump-to-cloud
30
+
31
+ Then
32
+
33
+ ruby dump.rb
34
+
35
+ ##Planned
36
+ - Add more databases (E.g Postgres)
37
+ - Add more cloud providers (E.g Google Drive, S3)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cloud_backup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cloud_backup"
8
+ spec.version = CloudBackup::VERSION
9
+ spec.authors = ["Serdar Dogruyol"]
10
+ spec.email = ["dogruyolserdar@gmail.com"]
11
+ spec.summary = %q{Backup files and database dumps to Cloud.}
12
+ spec.description = %q{Backup files and database dumps to Cloud.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'dropbox-sdk'
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency 'rspec'
25
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'dumper'
2
+
3
+ class CLI
4
+ def initialize
5
+ @dumper = Dumper.new
6
+ puts 'What type of dump do you want?'
7
+ puts '1. Auto Dump (Auto Dumps the Db and Stores it to Dropbox)'
8
+ puts '2. Select dump file by yourself'
9
+ dump_type = gets.strip
10
+ case dump_type
11
+ when '1'
12
+ @dumper.dump_db()
13
+ when '2'
14
+ puts 'Please enter the dump file name.'
15
+ file_name = gets.strip
16
+ @dumper.upload_file file_name
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,61 @@
1
+ require 'dropbox_sdk'
2
+ require 'yaml'
3
+
4
+ class Dumper
5
+
6
+ def initialize
7
+ settings = YAML.load_file('settings.yml')
8
+ @app_key = settings['dropbox']['app_key']
9
+ @app_secret = settings['dropbox']['app_secret']
10
+ @db_name = settings['database']['db_name']
11
+ @db_password = settings['database']['db_password']
12
+ @db_user = settings['database']['db_user']
13
+
14
+ if File::exists?(".dump_db")
15
+ data = File.read(".dump_db")
16
+ @access_token = Marshal.load(data)
17
+ end
18
+
19
+ if @access_token
20
+ puts 'Your access token is ' + @access_token
21
+ else
22
+ authorize
23
+ end
24
+ end
25
+
26
+ def authorize
27
+ flow = DropboxOAuth2FlowNoRedirect.new(@app_key, @app_secret)
28
+ authorize_url = flow.start()
29
+
30
+ # Have the user sign in and authorize this app
31
+ puts '1. Go to this link in your web browser: ' + authorize_url
32
+ puts '2. Click "Allow" (you might have to log in first)'
33
+ puts '3. Copy the authorization code'
34
+ print 'Enter the authorization code here: '
35
+ code = gets.strip
36
+
37
+ # This will fail if the user gave us an invalid authorization code
38
+ @access_token, user_id = flow.finish(code)
39
+ data = Marshal.dump(@access_token)
40
+ open('.dump_db', 'wb') { |f| f.puts data }
41
+ end
42
+
43
+ def upload_file(file_name)
44
+ client = DropboxClient.new(@access_token)
45
+ file = open(file_name)
46
+ puts 'Uploading file!! Please wait.'
47
+ response = client.put_file("/#{file_name}", file)
48
+ puts "uploaded:", response.inspect
49
+ end
50
+
51
+ def dump_db
52
+ date = Time.now.strftime('%d%m%y')
53
+ file_name = "#{@db_name}_#{date}.sql"
54
+ puts "Backing up the db to #{file_name}"
55
+ `mysqldump -u #{@db_user} -p#{@db_password} #{@db_name} > #{file_name}`
56
+ upload_file file_name
57
+ end
58
+
59
+ end
60
+
61
+
@@ -0,0 +1,3 @@
1
+ module CloudBackup
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "cloud_backup/version"
2
+ require "cloud_backup/cli"
3
+
4
+ module CloudBackup
5
+ CLI.new
6
+ end
data/lib/settings.yml ADDED
@@ -0,0 +1,7 @@
1
+ dropbox:
2
+ app_key: Your Dropbox App Key
3
+ app_secret: Your Dropbox App Secret
4
+ database:
5
+ db_name: Your Database Name
6
+ db_password: Your Database Password
7
+ db_user: Your Database User Name
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/cloud_backup/dumper'
3
+
4
+ describe 'Dumper' do
5
+
6
+ before { @settings_path = File.join(File.dirname(__FILE__), '../lib/settings.yml') }
7
+
8
+ it 'should have settings.yml' do
9
+ expect(File).to exist(@settings_path)
10
+ end
11
+
12
+ context 'setting values' do
13
+ before do
14
+ @settings = YAML.load_file(@settings_path)
15
+ end
16
+
17
+ it 'should have app key' do
18
+ expect(@settings['dropbox']['app_key']).not_to be_nil
19
+ end
20
+
21
+ it 'should have app secret' do
22
+ expect(@settings['dropbox']['app_secret']).not_to be_nil
23
+ end
24
+
25
+ it 'should have db user' do
26
+ expect(@settings['database']['db_user']).not_to be_nil
27
+ end
28
+
29
+ it 'should have db name' do
30
+ expect(@settings['database']['db_name']).not_to be_nil
31
+ end
32
+
33
+ it 'should have db password' do
34
+ expect(@settings['database']['db_password']).not_to be_nil
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloud_backup
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Serdar Dogruyol
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dropbox-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Backup files and database dumps to Cloud.
70
+ email:
71
+ - dogruyolserdar@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - cloud_backup.gemspec
82
+ - lib/cloud_backup.rb
83
+ - lib/cloud_backup/cli.rb
84
+ - lib/cloud_backup/dumper.rb
85
+ - lib/cloud_backup/version.rb
86
+ - lib/settings.yml
87
+ - spec/dumper_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Backup files and database dumps to Cloud.
113
+ test_files:
114
+ - spec/dumper_spec.rb
115
+ - spec/spec_helper.rb