cloud_backup 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dba0c7f461d2aae4b37c0e42f2b2db21f912d4f5
4
- data.tar.gz: 68e912eca56fc4611b9832a1cd4c7944b85c8dc0
3
+ metadata.gz: f7ce4b62142a9506fc386f290d8a64e4234ff492
4
+ data.tar.gz: 176b92ca564e076349c0e76773a1290e8e727c10
5
5
  SHA512:
6
- metadata.gz: c38df4f723d7d970e1e38078ad5d6b8a9dade60c39e86307ca3f98fa231737008b3277e4aab7ab60886cef3b51d835bb7f39cfbc54ff3e51d6a9019d981ab351
7
- data.tar.gz: 36ca656f59be3219e202f9b4e636d6802ef0b4216311efc30660052d60b7b3588d38fed951c4a0fafbbe4cc2cd4b2cf6c4da5a1230d80e3248eff3f29c48afcf
6
+ metadata.gz: e5b64fa403ab98102a1239278825c218bf873a884b75147ce0b1d9b07e9e497bfb6f511118b52276ea824f1f88e601a1af293e6325a026f91f9d13be14eb80ff
7
+ data.tar.gz: 852d545d9af2508d29220669257f4bf9ec36008a084a89f1adf5bd28c29d4d6fad7d8f85fefff642ea557f2f0f20d514cc62398ce24112decae77e654fc72c93
@@ -1,6 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require '../lib/cloud_backup/cli'
4
-
5
- Cli.new
3
+ # encoding: utf-8
6
4
 
5
+ if RUBY_VERSION >= '1.9.2'
6
+ $LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
7
+ require 'cloud_backup'
8
+ CloudBackup::Cli.new
9
+ else
10
+ puts 'Cloud Backup supports only Ruby 1.9.2+'
11
+ exit(-1)
12
+ end
@@ -0,0 +1 @@
1
+ require 'cloud_backup/cli'
@@ -1,19 +1,21 @@
1
- require_relative 'dumper'
1
+ require 'cloud_backup/dumper'
2
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
3
+ module CloudBackup
4
+ class Cli
5
+ def initialize
6
+ @dumper = Dumper.new
7
+ puts 'What type of dump do you want?'
8
+ puts '1. Auto Dump (Auto Dumps the Db and Stores it to Dropbox)'
9
+ puts '2. Select dump file by yourself'
10
+ dump_type = gets.strip
11
+ case dump_type
12
+ when '1'
13
+ @dumper.dump_db()
14
+ when '2'
15
+ puts 'Please enter the dump file name.'
16
+ file_name = gets.strip
17
+ @dumper.upload_file file_name
18
+ end
17
19
  end
18
20
  end
19
21
  end
@@ -1,62 +1,65 @@
1
1
  require 'dropbox_sdk'
2
2
  require 'yaml'
3
3
 
4
- class Dumper
5
-
6
- def initialize
7
- settings_path = File.join(File.dirname(__FILE__), '../settings.yml')
8
- settings = YAML.load_file(settings_path)
9
- @app_key = settings['dropbox']['app_key']
10
- @app_secret = settings['dropbox']['app_secret']
11
- @db_name = settings['database']['db_name']
12
- @db_password = settings['database']['db_password']
13
- @db_user = settings['database']['db_user']
14
-
15
- if File::exists?(".dump_db")
4
+ module CloudBackup
5
+ class Dumper
6
+
7
+ def initialize
8
+ settings_path = File.join(File.dirname(__FILE__), '../settings.yml')
9
+ settings = YAML.load_file(settings_path)
10
+ @app_key = settings['dropbox']['app_key']
11
+ @app_secret = settings['dropbox']['app_secret']
12
+ @db_name = settings['database']['db_name']
13
+ @db_password = settings['database']['db_password']
14
+ @db_user = settings['database']['db_user']
15
+
16
+ if File::exists?(".dump_db")
16
17
  data = File.read(".dump_db")
17
18
  @access_token = Marshal.load(data)
18
- end
19
+ end
19
20
 
20
- if @access_token
21
+ if @access_token
21
22
  puts 'Your access token is ' + @access_token
22
- else
23
+ else
23
24
  authorize
25
+ end
24
26
  end
25
- end
26
27
 
27
- def authorize
28
- flow = DropboxOAuth2FlowNoRedirect.new(@app_key, @app_secret)
29
- authorize_url = flow.start()
30
-
31
- # Have the user sign in and authorize this app
32
- puts '1. Go to this link in your web browser: ' + authorize_url
33
- puts '2. Click "Allow" (you might have to log in first)'
34
- puts '3. Copy the authorization code'
35
- print 'Enter the authorization code here: '
36
- code = gets.strip
37
-
38
- # This will fail if the user gave us an invalid authorization code
39
- @access_token, user_id = flow.finish(code)
40
- data = Marshal.dump(@access_token)
41
- open('.dump_db', 'wb') { |f| f.puts data }
42
- end
28
+ def authorize
29
+ flow = DropboxOAuth2FlowNoRedirect.new(@app_key, @app_secret)
30
+ authorize_url = flow.start()
43
31
 
44
- def upload_file(file_name)
45
- client = DropboxClient.new(@access_token)
46
- file = open(file_name)
47
- puts 'Uploading file!! Please wait.'
48
- response = client.put_file("/#{file_name}", file)
49
- puts "uploaded:", response.inspect
50
- end
32
+ # Have the user sign in and authorize this app
33
+ puts '1. Go to this link in your web browser: ' + authorize_url
34
+ puts '2. Click "Allow" (you might have to log in first)'
35
+ puts '3. Copy the authorization code'
36
+ print 'Enter the authorization code here: '
37
+ code = gets.strip
51
38
 
52
- def dump_db
53
- date = Time.now.strftime('%d%m%y')
54
- file_name = "#{@db_name}_#{date}.sql"
55
- puts "Backing up the db to #{file_name}"
56
- `mysqldump -u #{@db_user} -p#{@db_password} #{@db_name} > #{file_name}`
57
- upload_file file_name
58
- end
39
+ # This will fail if the user gave us an invalid authorization code
40
+ @access_token, user_id = flow.finish(code)
41
+ data = Marshal.dump(@access_token)
42
+ open('.dump_db', 'wb') { |f| f.puts data }
43
+ end
44
+
45
+ def upload_file(file_name)
46
+ client = DropboxClient.new(@access_token)
47
+ file = open(file_name)
48
+ puts 'Uploading file!! Please wait.'
49
+ response = client.put_file("/#{file_name}", file)
50
+ puts "uploaded:", response.inspect
51
+ end
59
52
 
53
+ def dump_db
54
+ date = Time.now.strftime('%d%m%y')
55
+ file_name = "#{@db_name}_#{date}.sql"
56
+ puts "Backing up the db to #{file_name}"
57
+ `mysqldump -u #{@db_user} -p#{@db_password} #{@db_name} > #{file_name}`
58
+ upload_file file_name
59
+ end
60
+
61
+ end
60
62
  end
61
63
 
62
64
 
65
+
@@ -1,3 +1,3 @@
1
1
  module CloudBackup
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serdar Dogruyol
@@ -81,6 +81,7 @@ files:
81
81
  - Rakefile
82
82
  - bin/cloud_backup
83
83
  - cloud_backup.gemspec
84
+ - lib/cloud_backup.rb
84
85
  - lib/cloud_backup/cli.rb
85
86
  - lib/cloud_backup/dumper.rb
86
87
  - lib/cloud_backup/version.rb