rmybackup 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.
Files changed (4) hide show
  1. data/Readme +1 -0
  2. data/bin/rmybackup +23 -0
  3. data/lib/rmybackup.rb +62 -0
  4. metadata +63 -0
data/Readme ADDED
@@ -0,0 +1 @@
1
+ #RMyBackup runs mysql dumps from an /etc/rmybackup.conf file
data/bin/rmybackup ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #Load the libraries, see if we're local or not for testing
4
+ begin
5
+ require 'rubygems'
6
+ require 'rmybackup'
7
+ rescue LoadError
8
+ require '../lib/rmybackup'
9
+ end
10
+
11
+ require 'optparse'
12
+
13
+ OPTIONS = { :config_file => "/etc/rmybackup.conf" }
14
+ GEM_VERSION = "0.0.1"
15
+
16
+ ARGV.options do |opts|
17
+ opts.on("-f /etc/rmybackup.conf","--config_file /etc/rmybackup.conf","Set Config File",String) { |OPTIONS[:config_file]| }
18
+ opts.on("-v","--version","Outputs version") { puts "Version - #{GEM_VERSION}"; exit }
19
+ opts.parse!
20
+ end
21
+
22
+ #Run
23
+ RMyBackup.new(OPTIONS[:config_file])
data/lib/rmybackup.rb ADDED
@@ -0,0 +1,62 @@
1
+ #Require Yaml
2
+ require 'yaml'
3
+ require 'time'
4
+
5
+ class RMyBackup
6
+
7
+ def initialize(config_file)
8
+ @config_file = config_file
9
+ #if the config has been parsed correctly, run the backups
10
+ run_backups if parse_config
11
+ end
12
+
13
+ private
14
+ #Run the backups, we should have proper validation at this point
15
+ def run_backups
16
+ #Grab some config variables
17
+ mysql_dump = @config['mysqldump_command']
18
+ backup_dir = @config['backup_dir']
19
+ gzip = @config['gzip_command']
20
+ date_string = Time.now.strftime "%m_%d_%Y_%H_%M"
21
+
22
+ #Cycle through databases to backup
23
+ @config['databases'].each do |db|
24
+ puts "Backing up #{db}\n"
25
+ system "#{mysql_dump} #{db} |#{gzip} > #{backup_dir}#{db}_#{date_string}.sql.gz"
26
+ end
27
+ end
28
+
29
+ def parse_config
30
+ @config = YAML::load(File.open(@config_file))
31
+
32
+ @error = Array.new
33
+
34
+ #Defaults
35
+ @config['gzip_command'] = "/usr/bin/gzip" if @config['gzip_command'].nil?
36
+ @config['mysqldump_command'] = "/usr/bin/mysqldump" if @config['mysqldump_command'].nil?
37
+ @config['find_command'] = "/usr/bin/find" if @config['find_command'].nil?
38
+
39
+ #Fix Slash at the end of the path
40
+ @config['backup_dir'] += "/" unless @config['backup_dir'][-1,1] == "/"
41
+
42
+ #Run Some checks
43
+ @error << "No Such Backup Directory #{@config['backup_dir']}" unless File.directory? @config['backup_dir']
44
+
45
+ #Check Commands
46
+ @error << "Can't locate find command: #{@config['find_command']}" unless File.exists? @config['find_command']
47
+ @error << "Can't locate gzip command: #{@config['gzip_command']}" unless File.exists? @config['gzip_command']
48
+ @error << "Can't locate mysqldump command: #{@config['mysqldump_command']}" unless File.exists? @config['mysqldump_command']
49
+
50
+ #See if we've created any errors, if so, display them and exit
51
+ if @error.empty?
52
+ return true
53
+ else
54
+ @error.each {|e| puts "#{e}\n" }
55
+ exit
56
+ end
57
+ rescue
58
+ @error.each {|e| puts "#{e}\n" }
59
+ exit
60
+ return false
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rmybackup
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Bryan Shelton
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-15 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Ruby mysql backup script, the script uses mysqldump from the system
22
+ email: bryan@sheltonopensolutions.com
23
+ executables:
24
+ - rmybackup
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/rmybackup.rb
31
+ - Readme
32
+ has_rdoc: true
33
+ homepage: http://github.com/bshelton229/rmybackup/
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.3.6
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Ruby Mysql Backup Script
62
+ test_files: []
63
+