Class: MysqlBackup

Inherits:
QuartzPlugin show all
Defined in:
lib/plugins/mysql_backup.rb

Constant Summary collapse

@@version_major =
0
@@version_minor =
0
@@version_revision =
1

Instance Method Summary collapse

Methods inherited from QuartzPlugin

#get_version, #initialize, #payload, #run_result, #run_shell

Constructor Details

This class inherits a constructor from QuartzPlugin

Instance Method Details

#infoObject



10
11
12
# File 'lib/plugins/mysql_backup.rb', line 10

def info
	{ :uid => "67deb35a555344c8a7651c656e6c8e2e", :name => "MySQL Backup", :version => get_version }
end

#run(message) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/plugins/mysql_backup.rb', line 14

def run(message)
	pl = payload(message)
	pl = pl.select { |k,v| !v.nil? && !v.empty? }

	@log.debug "Pruned payload #{pl}"

	@job_name 			= pl['job_name'].gsub(/[^\w\s_-]+/, '').gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2').gsub(/\s/, '_')
	@mysqldump_utility 	= pl['dump_utility'] || '/usr/bin/mysqldump'
	@name 				= pl['db_name'] || :all
	@username 			= pl['username']
	@password 			= pl['password']
	@socket 			= pl['socket']
	@host 				= pl['host']
	@port 				= pl['port']
	@skip_tables 		= pl['skip_tables']
	@only_tables 		= pl['only_tables']
	@additional_options = pl['additional_options'] || ['--single-transaction', '--quick']
	@path 				= pl['backup_folder']

	@only_tables = @only_tables.split(',') unless @only_tables.nil?
	@skip_tables = @skip_tables.split(',') unless @skip_tables.nil?

       dump_cmd = "#{mysqldump} | gzip > '#{ File.join(@path, @job_name.downcase) }.sql.gz'"
       @log.debug "Running #{dump_cmd}"
       
       FileUtils.mkdir_p(@path)

	result = run_shell dump_cmd
	if result[:ok]
		run_result(true, "MySQL Backup finished successfully")
	else
		run_result(false, result[:message])
	end
end