backup2s3.rb
1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
#
# Cookbook Name:: cfe-mariadb
# Recipe:: backup2s3
#
# Copyright 2016, Chromedia
#
# All rights reserved - Do Not Redistribute
#
# Sets up the shell script that backs up the databases
# and uploads them to a S3 bucket.
# Also sets up the cron job to regularly run this script.
# TODO: set up logrotate
include_recipe 'awscli'
md = node['cfe-mariadb']
mdb = md['backup']
mdbc = mdb['cron']
template "#{scr_dir}/backup_db_to_s3" do
only_if "test -d #{mdb['script_dir']} || mkdir -p #{mdb['script_dir']}"
variables(
:db_map => md['db_map'],
:db_ip => node['mariadb']['mysqld']['bind_address'],
:db_port => node['mariadb']['mysqld']['port'],
:s3_region => mdb['s3_region'],
:s3_bucket => mdb['s3_bucket'],
:aws_bin => mdb['aws_bin'],
:mysqldump_bin => mdb['mysqldump_bin']
)
end
cron 'backup_db_to_s3' do
command "bash #{scr_dir}/backup_db_to_s3"
minute mdbc['min']
hour mdbc['hour']
day mdbc['day']
month mdbc['mon']
weekday mdbc['wday']
mailto mdbc['mailto']
path '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
end