phpmyadmin-backup 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/phpmyadmin_backup +15 -0
- data/lib/phpmyadmin/backup.rb +101 -0
- data/lib/phpmyadmin/backup/version.rb +5 -0
- data/phpmyadmin-backup.gemspec +25 -0
- metadata +111 -0
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
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,29 @@
|
|
1
|
+
# Phpmyadmin::Backup
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'phpmyadmin-backup'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install phpmyadmin-backup
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'phpmyadmin/backup'
|
5
|
+
|
6
|
+
unless ARGV.size == 3
|
7
|
+
program = File.basename($0)
|
8
|
+
abort "Usage: #{program} url username password"
|
9
|
+
end
|
10
|
+
|
11
|
+
host, username, password = *ARGV
|
12
|
+
backup = Phpmyadmin::Backup.new(host, username, password)
|
13
|
+
filename = backup.export do |filename|
|
14
|
+
puts "Saved to #{filename}"
|
15
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'phpmyadmin/backup/version'
|
2
|
+
require 'mechanize'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Phpmyadmin
|
6
|
+
class Backup
|
7
|
+
attr_reader :agent, :last_page
|
8
|
+
|
9
|
+
def initialize(host, username, password)
|
10
|
+
@host = host
|
11
|
+
@agent = create_agent
|
12
|
+
@last_page = nil
|
13
|
+
login(username, password)
|
14
|
+
end
|
15
|
+
|
16
|
+
def export(database_names=[])
|
17
|
+
export_url = last_page.search("#li_export a").first['href']
|
18
|
+
|
19
|
+
get export_url do |page|
|
20
|
+
dump_form = page.form_with :name => 'dump'
|
21
|
+
if database_names.empty?
|
22
|
+
database_names = dump_form.field_with(:name => 'db_select[]').options
|
23
|
+
end
|
24
|
+
database_names.each do |database_name|
|
25
|
+
filename = export_single(export_url, database_name)
|
26
|
+
yield filename if block_given?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def export_single(export_url, database_name)
|
34
|
+
get export_url do |page|
|
35
|
+
dump_form = page.form_with :name => 'dump'
|
36
|
+
dump_form.field_with(:name => 'db_select[]').value = database_name
|
37
|
+
dump_form.checkbox_with(:name => 'asfile').checked = true
|
38
|
+
dump_form.field_with(:name => 'filename_template').value = "#{timestamp}.#{database_name}"
|
39
|
+
dump_form.radiobutton_with(:name => 'compression').value = 'bzip'
|
40
|
+
result = submit(dump_form)
|
41
|
+
result.filename
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_agent
|
46
|
+
agent = Mechanize.new
|
47
|
+
agent.log = Logger.new $stderr if $DEBUG
|
48
|
+
agent.pluggable_parser.default = Mechanize::FileSaver
|
49
|
+
agent.keep_alive = false
|
50
|
+
agent.agent.ignore_bad_chunking = true
|
51
|
+
agent
|
52
|
+
end
|
53
|
+
|
54
|
+
def login(username, password)
|
55
|
+
get url do |page|
|
56
|
+
login_form = page.form_with :name => 'login_form'
|
57
|
+
login_form.field_with(:name => 'pma_username').value = username
|
58
|
+
login_form.field_with(:name => 'pma_password').value = password
|
59
|
+
|
60
|
+
submit login_form
|
61
|
+
end
|
62
|
+
|
63
|
+
frame = last_page.frame_with(:src => /main/)
|
64
|
+
get frame.src do |page|
|
65
|
+
unless page.search("#li_user_info").text.include?(username)
|
66
|
+
error! "user #{username} not found"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def get(url)
|
72
|
+
@last_page = agent.get url
|
73
|
+
if block_given?
|
74
|
+
yield @last_page
|
75
|
+
else
|
76
|
+
@last_page
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def submit(*args)
|
81
|
+
@last_page = agent.submit *args
|
82
|
+
if block_given?
|
83
|
+
yield @last_page
|
84
|
+
else
|
85
|
+
@last_page
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def url(ext=nil)
|
90
|
+
@host + ext.to_s
|
91
|
+
end
|
92
|
+
|
93
|
+
def error!(message)
|
94
|
+
raise ArgumentError, message
|
95
|
+
end
|
96
|
+
|
97
|
+
def timestamp
|
98
|
+
@timestamp ||= Time.new.strftime("%Y-%m-%dT%T")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -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 'phpmyadmin/backup/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "phpmyadmin-backup"
|
8
|
+
spec.version = Phpmyadmin::Backup::VERSION
|
9
|
+
spec.authors = ["Peter Suschlik"]
|
10
|
+
spec.email = ["peter-phpmyadmin-backup@suschlik.de"]
|
11
|
+
spec.description = %q{Backup SQL dumps via phpmyadmin}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = "https://github.com/splattael/phpmyadmin-backup"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "mechanize", "~> 2.7.1"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phpmyadmin-backup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Peter Suschlik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mechanize
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.7.1
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.7.1
|
62
|
+
description: Backup SQL dumps via phpmyadmin
|
63
|
+
email:
|
64
|
+
- peter-phpmyadmin-backup@suschlik.de
|
65
|
+
executables:
|
66
|
+
- phpmyadmin_backup
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- .ruby-version
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- bin/phpmyadmin_backup
|
77
|
+
- lib/phpmyadmin/backup.rb
|
78
|
+
- lib/phpmyadmin/backup/version.rb
|
79
|
+
- phpmyadmin-backup.gemspec
|
80
|
+
homepage: https://github.com/splattael/phpmyadmin-backup
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
hash: -4399238548509879015
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
hash: -4399238548509879015
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.25
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Backup SQL dumps via phpmyadmin
|
111
|
+
test_files: []
|