daily_weekly_monthly 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +0 -2
- data/.travis.yml +4 -6
- data/README.md +2 -0
- data/daily_weekly_monthly.gemspec +3 -0
- data/features/daily_weekly_monthly.feature +5 -0
- data/features/step_definitions/daily_weekly_monthly_steps.rb +18 -0
- data/features/support/env.rb +7 -1
- data/lib/daily_weekly_monthly/cli.rb +39 -10
- data/lib/daily_weekly_monthly/downloader.rb +1 -1
- data/lib/daily_weekly_monthly/notifier.rb +29 -0
- data/lib/daily_weekly_monthly/runner.rb +7 -0
- data/lib/daily_weekly_monthly/version.rb +1 -1
- data/spec/daily_weekly_monthly/cleaner_spec.rb +1 -1
- data/spec/daily_weekly_monthly/cli_spec.rb +7 -1
- data/spec/daily_weekly_monthly/downloader_spec.rb +2 -2
- data/spec/spec_helper.rb +18 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b16518761e83780613149ff2f50e838e2178565
|
4
|
+
data.tar.gz: ee7a046fb559a0727e723400e8d6a8a5c3cc4224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41ca3df810e29e6ed57683a89a07db7f4b07b685776deaca30971c75c54822df496e28d741e8179e5f413491903c01ff3ff695d974f58c4a240e447cad389925
|
7
|
+
data.tar.gz: 787660aba84ac6f557c0d929123bbb34f545b9f6e79ee3644ba0ab119ee7fe3fa44e18b4a270fcee024b41b630c08fd8c31fa4242a92e1fda26d643d701f21ac
|
data/.codeclimate.yml
CHANGED
data/.travis.yml
CHANGED
@@ -4,10 +4,8 @@ branches:
|
|
4
4
|
- master
|
5
5
|
- /^v[0-9]+\.[0-9]+\.[0-9]+/
|
6
6
|
rvm:
|
7
|
-
-
|
8
|
-
-
|
9
|
-
- 2.0.0
|
10
|
-
- 2.3.0
|
7
|
+
- 2.1.10
|
8
|
+
- 2.3.3
|
11
9
|
script:
|
12
10
|
- bundle exec rake
|
13
11
|
deploy:
|
@@ -17,5 +15,5 @@ deploy:
|
|
17
15
|
on:
|
18
16
|
tags: true
|
19
17
|
all_branches: true
|
20
|
-
repo: tpbowden/
|
21
|
-
rvm: 2.
|
18
|
+
repo: tpbowden/daily_weekly_monthly
|
19
|
+
rvm: 2.3.3
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Daily Weekly Monthly
|
2
2
|
|
3
|
+
[](https://travis-ci.org/tpbowden/daily_monthly_weekly)
|
4
|
+
|
3
5
|
Keep your data safe by backing up on a daily, weekly and monthly basis.
|
4
6
|
|
5
7
|
This tool allows you to take regular backups whilst automatically removing old ones.
|
@@ -17,9 +17,12 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.license = "MIT"
|
18
18
|
s.required_ruby_version = ">= 2.0.0"
|
19
19
|
|
20
|
+
s.add_dependency "mail", ">= 2.6"
|
21
|
+
|
20
22
|
s.add_development_dependency "rake", ">= 10.4"
|
21
23
|
s.add_development_dependency "rubocop", ">= 0.35"
|
22
24
|
s.add_development_dependency "rspec", ">= 3.4"
|
23
25
|
s.add_development_dependency "simplecov", ">= 0.11"
|
24
26
|
s.add_development_dependency "cucumber", ">= 2.0"
|
27
|
+
s.add_development_dependency "codeclimate-test-reporter", ">= 0.4"
|
25
28
|
end
|
@@ -27,6 +27,20 @@ When "I run the backups" do
|
|
27
27
|
months_to_keep: 3)
|
28
28
|
end
|
29
29
|
|
30
|
+
When "I run the backup and it fails" do
|
31
|
+
begin
|
32
|
+
DailyWeeklyMonthly.start("exit 10;", backups_dir: backups_dir,
|
33
|
+
day_of_week: @weekly_backup_day || 1,
|
34
|
+
day_of_month: @monthly_backup_day || 1,
|
35
|
+
days_to_keep: 3,
|
36
|
+
weeks_to_keep: 3,
|
37
|
+
months_to_keep: 3,
|
38
|
+
notify: "person@example.com")
|
39
|
+
rescue RuntimeError => e
|
40
|
+
@exception = e
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
30
44
|
Then(/I can see a (.+) backup file/) do |period|
|
31
45
|
expect(File.exist?(File.join(backups_dir, period, "#{Date.today.iso8601}.pgdump.gz"))).to be true
|
32
46
|
end
|
@@ -43,3 +57,7 @@ Then(/the old (.+) backups have been removed/) do |period|
|
|
43
57
|
"#{Date.today.iso8601}.pgdump.gz",
|
44
58
|
]
|
45
59
|
end
|
60
|
+
|
61
|
+
Then "I have been notified of the failure" do
|
62
|
+
expect(Mail::TestMailer.deliveries.length).to eq 1
|
63
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require "simplecov"
|
2
|
-
SimpleCov.start
|
2
|
+
SimpleCov.start do
|
3
|
+
coverage_dir "coverage/features"
|
4
|
+
end
|
3
5
|
|
4
6
|
require "tmpdir"
|
5
7
|
require "daily_weekly_monthly"
|
6
8
|
|
9
|
+
Mail.defaults do
|
10
|
+
delivery_method :test
|
11
|
+
end
|
12
|
+
|
7
13
|
def backups_dir
|
8
14
|
@backups_dir ||= Dir.mktmpdir
|
9
15
|
end
|
@@ -3,6 +3,19 @@ require "daily_weekly_monthly"
|
|
3
3
|
|
4
4
|
module DailyWeeklyMonthly
|
5
5
|
class Cli
|
6
|
+
OPTIONS = [
|
7
|
+
:dir,
|
8
|
+
:ext,
|
9
|
+
:week_day,
|
10
|
+
:month_day,
|
11
|
+
:keep_days,
|
12
|
+
:keep_weeks,
|
13
|
+
:keep_months,
|
14
|
+
:smtp_server,
|
15
|
+
:smtp_port,
|
16
|
+
:notify,
|
17
|
+
].freeze
|
18
|
+
|
6
19
|
def initialize args
|
7
20
|
@options = {}
|
8
21
|
@command = parse args
|
@@ -16,29 +29,45 @@ module DailyWeeklyMonthly
|
|
16
29
|
|
17
30
|
private
|
18
31
|
|
19
|
-
# rubocop : disable Metrics/MethodLength
|
20
32
|
def parse args
|
21
33
|
args.options do |opts|
|
22
34
|
opts.banner = "Usage: daily_weekly_monthly \"database backup command\" [options]"
|
23
|
-
|
24
|
-
parse_ext(opts)
|
25
|
-
parse_week_day(opts)
|
26
|
-
parse_month_day(opts)
|
27
|
-
parse_keep_days(opts)
|
28
|
-
parse_keep_weeks(opts)
|
29
|
-
parse_keep_months(opts)
|
30
|
-
opts.parse!
|
35
|
+
parse_all_options(opts)
|
31
36
|
end
|
32
|
-
|
33
37
|
args
|
34
38
|
end
|
35
39
|
|
40
|
+
def parse_all_options opts
|
41
|
+
OPTIONS.each do |option|
|
42
|
+
send("parse_#{option}", opts)
|
43
|
+
end
|
44
|
+
opts.parse!
|
45
|
+
end
|
46
|
+
|
36
47
|
def parse_keep_months opts
|
37
48
|
opts.on("-M n", "--months-to-keep=n", "Monthly backups to keep", OptionParser::DecimalInteger) do |n|
|
38
49
|
@options[:months_to_keep] = n
|
39
50
|
end
|
40
51
|
end
|
41
52
|
|
53
|
+
def parse_smtp_server opts
|
54
|
+
opts.on("-s s", "--smtp-server=s", "SMTP server for notifications", String) do |s|
|
55
|
+
@options[:smtp_server] = s
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse_smtp_port opts
|
60
|
+
opts.on("-p p", "--smtp-server=p", "SMTP port for notifications", OptionParser::DecimalInteger) do |p|
|
61
|
+
@options[:smtp_port] = p
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse_notify opts
|
66
|
+
opts.on("-n s", "--notify=s", "Notification email address", String) do |s|
|
67
|
+
@options[:notify] = s
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
42
71
|
def parse_keep_weeks opts
|
43
72
|
opts.on("-W n", "--weeks-to-keep=n", "Weekly backups to keep", OptionParser::DecimalInteger) do |n|
|
44
73
|
@options[:weeks_to_keep] = n
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "mail"
|
2
|
+
|
3
|
+
module DailyWeeklyMonthly
|
4
|
+
class Notifier
|
5
|
+
def initialize smtp_server, smtp_port
|
6
|
+
@smtp_server = smtp_server
|
7
|
+
@smtp_port = smtp_port
|
8
|
+
end
|
9
|
+
|
10
|
+
# rubocop: disable Metrics/MethodLength
|
11
|
+
def call exception, deliver_to
|
12
|
+
mail = Mail.new {
|
13
|
+
from "backups@localhost"
|
14
|
+
to deliver_to
|
15
|
+
subject "Backup failed"
|
16
|
+
body <<EOF
|
17
|
+
Backup failure
|
18
|
+
|
19
|
+
#{exception.message}
|
20
|
+
|
21
|
+
#{exception.backtrace.join("\n")}
|
22
|
+
EOF
|
23
|
+
}
|
24
|
+
mail.delivery_method :smtp, address: @smtp_server, port: @smtp_port if @smtp_server && @smtp_port
|
25
|
+
mail.deliver
|
26
|
+
end
|
27
|
+
# rubocop: enable all
|
28
|
+
end
|
29
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "daily_weekly_monthly/processor"
|
2
2
|
require "daily_weekly_monthly/downloader"
|
3
|
+
require "daily_weekly_monthly/notifier"
|
3
4
|
|
4
5
|
module DailyWeeklyMonthly
|
5
6
|
class Runner
|
@@ -11,6 +12,9 @@ module DailyWeeklyMonthly
|
|
11
12
|
days_to_keep: 7,
|
12
13
|
weeks_to_keep: 5,
|
13
14
|
months_to_keep: 12,
|
15
|
+
smtp_server: false,
|
16
|
+
smtp_port: false,
|
17
|
+
notify: false,
|
14
18
|
}.freeze
|
15
19
|
|
16
20
|
def initialize backup_command, options = {}
|
@@ -37,6 +41,9 @@ module DailyWeeklyMonthly
|
|
37
41
|
|
38
42
|
def backup
|
39
43
|
Downloader.new(@backup_command).call
|
44
|
+
rescue StandardError => e
|
45
|
+
Notifier.new(@options[:smtp_server], @options[:smtp_port]).call(e, @options[:notify]) if @options[:notify]
|
46
|
+
raise e
|
40
47
|
end
|
41
48
|
end
|
42
49
|
end
|
@@ -18,7 +18,7 @@ describe DailyWeeklyMonthly::Cleaner do
|
|
18
18
|
|
19
19
|
it "removes all files except the newest N from the target directory" do
|
20
20
|
subject.call "weekly", 2
|
21
|
-
expect(Dir[File.join(backups_dir, "weekly", "*.#{ext}")].map {
|
21
|
+
expect(Dir[File.join(backups_dir, "weekly", "*.#{ext}")].map {|f|
|
22
22
|
File.basename(f)
|
23
23
|
}).to match_array ["2020-01-01.txt", "2019-01-01.txt"]
|
24
24
|
end
|
@@ -25,6 +25,9 @@ describe DailyWeeklyMonthly::Cli do
|
|
25
25
|
"-e", "foo",
|
26
26
|
"-w", "2",
|
27
27
|
"-d", "bar",
|
28
|
+
"-n", "me@example.com",
|
29
|
+
"-s", "smpt.example.com",
|
30
|
+
"-p", "25",
|
28
31
|
"some", "command"
|
29
32
|
]
|
30
33
|
end
|
@@ -36,7 +39,10 @@ describe DailyWeeklyMonthly::Cli do
|
|
36
39
|
day_of_month: 1,
|
37
40
|
output_extension: "foo",
|
38
41
|
day_of_week: 2,
|
39
|
-
backups_dir: "bar"
|
42
|
+
backups_dir: "bar",
|
43
|
+
smtp_server: "smpt.example.com",
|
44
|
+
smtp_port: 25,
|
45
|
+
notify: "me@example.com")
|
40
46
|
subject.call
|
41
47
|
end
|
42
48
|
end
|
@@ -4,10 +4,10 @@ require "daily_weekly_monthly/downloader"
|
|
4
4
|
describe DailyWeeklyMonthly::Downloader do
|
5
5
|
describe "#call" do
|
6
6
|
context "when the command fails" do
|
7
|
-
subject { described_class.new "
|
7
|
+
subject { described_class.new "echo 'foo' && exit 1" }
|
8
8
|
|
9
9
|
it "raises a runtime error" do
|
10
|
-
expect { subject.call }.to raise_error RuntimeError, "Failed to download backup"
|
10
|
+
expect { subject.call }.to raise_error RuntimeError, "Failed to download backup: foo\n"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,19 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
1
2
|
require "simplecov"
|
2
|
-
|
3
|
+
|
4
|
+
CodeClimate::TestReporter.configure do |config|
|
5
|
+
config.logger.level = Logger::WARN
|
6
|
+
end
|
7
|
+
|
8
|
+
SimpleCov.start do
|
9
|
+
formatter(
|
10
|
+
SimpleCov::Formatter::MultiFormatter.new(
|
11
|
+
[
|
12
|
+
SimpleCov::Formatter::HTMLFormatter,
|
13
|
+
CodeClimate::TestReporter::Formatter,
|
14
|
+
],
|
15
|
+
),
|
16
|
+
)
|
17
|
+
|
18
|
+
coverage_dir "coverage/rspec"
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daily_weekly_monthly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Bowden
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mail
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.6'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.4'
|
83
111
|
description: Automatically manage daily, weekly and monthly database backups
|
84
112
|
email: tom.b1992@gmail.com
|
85
113
|
executables:
|
@@ -105,6 +133,7 @@ files:
|
|
105
133
|
- lib/daily_weekly_monthly/cli.rb
|
106
134
|
- lib/daily_weekly_monthly/creator.rb
|
107
135
|
- lib/daily_weekly_monthly/downloader.rb
|
136
|
+
- lib/daily_weekly_monthly/notifier.rb
|
108
137
|
- lib/daily_weekly_monthly/processor.rb
|
109
138
|
- lib/daily_weekly_monthly/runner.rb
|
110
139
|
- lib/daily_weekly_monthly/version.rb
|
@@ -136,9 +165,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
165
|
version: '0'
|
137
166
|
requirements: []
|
138
167
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.5.1
|
140
169
|
signing_key:
|
141
170
|
specification_version: 4
|
142
171
|
summary: Manage database backups
|
143
172
|
test_files: []
|
144
|
-
has_rdoc:
|