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 +4 -4
- data/bin/cloud_backup +9 -3
- data/lib/cloud_backup.rb +1 -0
- data/lib/cloud_backup/cli.rb +17 -15
- data/lib/cloud_backup/dumper.rb +49 -46
- data/lib/cloud_backup/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7ce4b62142a9506fc386f290d8a64e4234ff492
|
4
|
+
data.tar.gz: 176b92ca564e076349c0e76773a1290e8e727c10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5b64fa403ab98102a1239278825c218bf873a884b75147ce0b1d9b07e9e497bfb6f511118b52276ea824f1f88e601a1af293e6325a026f91f9d13be14eb80ff
|
7
|
+
data.tar.gz: 852d545d9af2508d29220669257f4bf9ec36008a084a89f1adf5bd28c29d4d6fad7d8f85fefff642ea557f2f0f20d514cc62398ce24112decae77e654fc72c93
|
data/bin/cloud_backup
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
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
|
data/lib/cloud_backup.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'cloud_backup/cli'
|
data/lib/cloud_backup/cli.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
|
1
|
+
require 'cloud_backup/dumper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
data/lib/cloud_backup/dumper.rb
CHANGED
@@ -1,62 +1,65 @@
|
|
1
1
|
require 'dropbox_sdk'
|
2
2
|
require 'yaml'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
+
if @access_token
|
21
22
|
puts 'Your access token is ' + @access_token
|
22
|
-
|
23
|
+
else
|
23
24
|
authorize
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
+
|
data/lib/cloud_backup/version.rb
CHANGED
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.
|
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
|