mys3ql 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/README.md +24 -6
- data/bin/mys3ql +56 -1
- data/lib/mys3ql/conductor.rb +10 -16
- data/lib/mys3ql/config.rb +17 -4
- data/lib/mys3ql/mysql.rb +1 -1
- data/lib/mys3ql/s3.rb +5 -5
- data/lib/mys3ql/shell.rb +1 -5
- data/lib/mys3ql/version.rb +1 -1
- data/mys3ql.gemspec +1 -0
- metadata +25 -8
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -9,11 +9,17 @@ Install and configure as below.
|
|
9
9
|
|
10
10
|
To perform a full backup:
|
11
11
|
|
12
|
-
$ mys3ql
|
12
|
+
$ mys3ql -f
|
13
|
+
$ mys3ql --full
|
13
14
|
|
14
15
|
If you are using MySql's binary logging (see below), back up the binary logs like this:
|
15
16
|
|
16
|
-
$ mys3ql
|
17
|
+
$ mys3ql -i
|
18
|
+
$ mys3ql --incremental
|
19
|
+
|
20
|
+
By default mys3ql looks for a configuration file at ~/.mys3ql. You can override this like so:
|
21
|
+
|
22
|
+
$ mys3ql -f --config=FILE
|
17
23
|
|
18
24
|
|
19
25
|
## Installation
|
@@ -21,14 +27,14 @@ If you are using MySql's binary logging (see below), back up the binary logs lik
|
|
21
27
|
First install the gem:
|
22
28
|
|
23
29
|
$ gem install mys3ql
|
24
|
-
|
25
|
-
Second, create your
|
30
|
+
|
31
|
+
Second, create your config file:
|
26
32
|
|
27
33
|
mysql:
|
28
34
|
# Database to back up
|
29
35
|
database: aircms_production
|
30
36
|
# MySql credentials
|
31
|
-
user:
|
37
|
+
user:
|
32
38
|
password:
|
33
39
|
# Path (with trailing slash) to mysql commands e.g. mysqldump
|
34
40
|
bin_path: /usr/local/mysql/bin/
|
@@ -44,6 +50,7 @@ Second, create your `~/.mys3ql` config file:
|
|
44
50
|
# Bucket in which to store your backups
|
45
51
|
bucket: db_backups
|
46
52
|
|
53
|
+
If you only have one database to back up on your server, you can put the config file at `~/.mys3ql`. Otherwise, tell the `mys3ql` command where the config file is with the `--config=FILE` switch.
|
47
54
|
|
48
55
|
## Binary logging
|
49
56
|
|
@@ -67,4 +74,15 @@ Marc-André Cournoyer's [mysql_s3_backup](https://github.com/macournoyer/mysql_s
|
|
67
74
|
- tests ;)
|
68
75
|
- restore (pull latest dump, pull bin files, pipe dump into mysql, pipe binfiles into mysql)
|
69
76
|
- remove old dump files (s3)
|
70
|
-
|
77
|
+
|
78
|
+
|
79
|
+
## Questions, Problems, Feedback
|
80
|
+
|
81
|
+
Please use the GitHub [issue tracker](https://github.com/airblade/mys3ql/issues) or email me.
|
82
|
+
|
83
|
+
|
84
|
+
## Intellectual property
|
85
|
+
|
86
|
+
Copyright 2011 Andy Stewart (boss@airbladesoftware.com).
|
87
|
+
|
88
|
+
Released under the MIT licence.
|
data/bin/mys3ql
CHANGED
@@ -1,8 +1,63 @@
|
|
1
1
|
#!/usr/bin/env ruby-local-exec
|
2
2
|
|
3
|
+
# Hmm, is there a better way which doesn't force rubygems?
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler/setup'
|
6
|
+
|
3
7
|
lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
|
4
8
|
$LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
|
5
9
|
|
6
10
|
require 'mys3ql'
|
11
|
+
require 'choice'
|
12
|
+
|
13
|
+
Choice.options do
|
14
|
+
|
15
|
+
header ''
|
16
|
+
header 'Specific options:'
|
17
|
+
|
18
|
+
option :full do
|
19
|
+
short '-f'
|
20
|
+
long '--full'
|
21
|
+
desc 'Dump database, push to S3, and clean up bin logs on S3'
|
22
|
+
end
|
23
|
+
|
24
|
+
option :incremental do
|
25
|
+
short '-i'
|
26
|
+
long '--incremental'
|
27
|
+
desc "Push mysql's bin logs to S3"
|
28
|
+
end
|
29
|
+
|
30
|
+
option :config do
|
31
|
+
short '-c'
|
32
|
+
long '--config=FILE'
|
33
|
+
desc 'Load configuration from YAML file (default: ~/.mys3ql)'
|
34
|
+
default '~/.mys3ql'
|
35
|
+
end
|
36
|
+
|
37
|
+
separator ''
|
38
|
+
separator 'General options:'
|
39
|
+
|
40
|
+
option :debug do
|
41
|
+
short '-d'
|
42
|
+
long '--debug'
|
43
|
+
desc 'Turn on debugging mode'
|
44
|
+
end
|
45
|
+
|
46
|
+
option :help do
|
47
|
+
long '--help'
|
48
|
+
desc 'Show this message'
|
49
|
+
end
|
50
|
+
|
51
|
+
option :version do
|
52
|
+
short '-v'
|
53
|
+
long '--version'
|
54
|
+
desc 'Show version'
|
55
|
+
action do
|
56
|
+
puts "mys3ql v#{Mys3ql::VERSION}"
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
7
62
|
|
8
|
-
Mys3ql::Conductor.run
|
63
|
+
Mys3ql::Conductor.run Choice.choices
|
data/lib/mys3ql/conductor.rb
CHANGED
@@ -5,26 +5,25 @@ require 'mys3ql/s3'
|
|
5
5
|
module Mys3ql
|
6
6
|
class Conductor
|
7
7
|
|
8
|
-
def self.run(
|
9
|
-
|
10
|
-
conductor =
|
8
|
+
def self.run(options)
|
9
|
+
conductor = Conductor.new(options['config'])
|
10
|
+
conductor.debug = options[:debug]
|
11
11
|
|
12
|
-
|
13
|
-
if command == 'full'
|
12
|
+
if options['full']
|
14
13
|
conductor.full
|
15
|
-
|
14
|
+
elsif options['incremental']
|
16
15
|
conductor.incremental
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
def initialize
|
21
|
-
@config = Config.new
|
19
|
+
def initialize(config_file = nil)
|
20
|
+
@config = Config.new(config_file)
|
22
21
|
@mysql = Mysql.new @config
|
23
22
|
@s3 = S3.new @config
|
24
23
|
end
|
25
24
|
|
26
25
|
def full
|
27
|
-
@mysql.dump
|
26
|
+
@mysql.dump
|
28
27
|
@s3.push_dump_to_s3 @mysql.dump_file
|
29
28
|
@mysql.clean_up_dump
|
30
29
|
@s3.delete_bin_logs_on_s3
|
@@ -34,13 +33,8 @@ module Mys3ql
|
|
34
33
|
@s3.push_bin_logs_to_s3
|
35
34
|
end
|
36
35
|
|
37
|
-
def
|
38
|
-
|
39
|
-
usage:
|
40
|
-
mys3ql full - full backup, push to S3
|
41
|
-
mys3ql incremental - push bin logs to S3
|
42
|
-
END
|
36
|
+
def debug=(val)
|
37
|
+
@config.debug = val
|
43
38
|
end
|
44
|
-
|
45
39
|
end
|
46
40
|
end
|
data/lib/mys3ql/config.rb
CHANGED
@@ -3,13 +3,26 @@ require 'yaml'
|
|
3
3
|
module Mys3ql
|
4
4
|
class Config
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
|
6
|
+
def initialize(config_file = nil)
|
7
|
+
config_file = config_file || default_config_file
|
8
|
+
@config = YAML.load_file File.expand_path(config_file)
|
8
9
|
rescue Errno::ENOENT
|
9
|
-
$stderr.puts "missing
|
10
|
+
$stderr.puts "missing config file #{config_file}"
|
10
11
|
exit 1
|
11
12
|
end
|
12
13
|
|
14
|
+
#
|
15
|
+
# General
|
16
|
+
#
|
17
|
+
|
18
|
+
def debug=(val)
|
19
|
+
@debug = val
|
20
|
+
end
|
21
|
+
|
22
|
+
def debugging?
|
23
|
+
@debug
|
24
|
+
end
|
25
|
+
|
13
26
|
#
|
14
27
|
# MySQL
|
15
28
|
#
|
@@ -60,7 +73,7 @@ module Mys3ql
|
|
60
73
|
@config['s3']
|
61
74
|
end
|
62
75
|
|
63
|
-
def
|
76
|
+
def default_config_file
|
64
77
|
File.join "#{ENV['HOME']}", '.mys3ql'
|
65
78
|
end
|
66
79
|
end
|
data/lib/mys3ql/mysql.rb
CHANGED
data/lib/mys3ql/s3.rb
CHANGED
@@ -15,7 +15,7 @@ module Mys3ql
|
|
15
15
|
s3_file = push_to_s3 dump_file, key
|
16
16
|
if s3_file
|
17
17
|
s3_file.copy @config.bucket, copy_key
|
18
|
-
|
18
|
+
log "copied #{key} to #{copy_key}"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -32,7 +32,7 @@ module Mys3ql
|
|
32
32
|
def delete_bin_logs_on_s3
|
33
33
|
bucket.files.all(:prefix => "#{bin_logs_prefix}").each do |file|
|
34
34
|
file.destroy
|
35
|
-
|
35
|
+
log "destroyed #{file.key}"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -45,7 +45,7 @@ module Mys3ql
|
|
45
45
|
:aws_secret_access_key => @config.secret_access_key,
|
46
46
|
:aws_access_key_id => @config.access_key_id
|
47
47
|
)
|
48
|
-
|
48
|
+
log 'connected to s3'
|
49
49
|
s
|
50
50
|
end
|
51
51
|
end
|
@@ -53,7 +53,7 @@ module Mys3ql
|
|
53
53
|
def bucket
|
54
54
|
@directory ||= begin
|
55
55
|
d = s3.directories.get @config.bucket # assume bucket exists
|
56
|
-
|
56
|
+
log "opened bucket #{@config.bucket}"
|
57
57
|
d
|
58
58
|
end
|
59
59
|
end
|
@@ -66,7 +66,7 @@ module Mys3ql
|
|
66
66
|
:body => File.open(local_file_name),
|
67
67
|
:public => false
|
68
68
|
)
|
69
|
-
|
69
|
+
log "pushed #{local_file_name} to #{s3_key}"
|
70
70
|
s3_file
|
71
71
|
end
|
72
72
|
end
|
data/lib/mys3ql/shell.rb
CHANGED
data/lib/mys3ql/version.rb
CHANGED
data/mys3ql.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
+
s.add_dependency 'choice', '~> 0.1.4'
|
21
22
|
s.add_dependency 'fog', '~> 1.0.0'
|
22
23
|
s.add_development_dependency 'rake'
|
23
24
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mys3ql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andy Stewart
|
@@ -15,13 +15,29 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-31 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: choice
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 19
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 1
|
33
|
+
- 4
|
34
|
+
version: 0.1.4
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
21
37
|
- !ruby/object:Gem::Dependency
|
22
38
|
name: fog
|
23
39
|
prerelease: false
|
24
|
-
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
25
41
|
none: false
|
26
42
|
requirements:
|
27
43
|
- - ~>
|
@@ -33,11 +49,11 @@ dependencies:
|
|
33
49
|
- 0
|
34
50
|
version: 1.0.0
|
35
51
|
type: :runtime
|
36
|
-
|
52
|
+
version_requirements: *id002
|
37
53
|
- !ruby/object:Gem::Dependency
|
38
54
|
name: rake
|
39
55
|
prerelease: false
|
40
|
-
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
57
|
none: false
|
42
58
|
requirements:
|
43
59
|
- - ">="
|
@@ -47,7 +63,7 @@ dependencies:
|
|
47
63
|
- 0
|
48
64
|
version: "0"
|
49
65
|
type: :development
|
50
|
-
|
66
|
+
version_requirements: *id003
|
51
67
|
description: Simple backup of your MySql database onto Amazon S3.
|
52
68
|
email:
|
53
69
|
- boss@airbladesoftware.com
|
@@ -59,6 +75,7 @@ extra_rdoc_files: []
|
|
59
75
|
|
60
76
|
files:
|
61
77
|
- .gitignore
|
78
|
+
- CHANGELOG.md
|
62
79
|
- Gemfile
|
63
80
|
- README.md
|
64
81
|
- Rakefile
|