croner 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d7450c7f6c94d41f65897bbd9491d1ab909e40c
4
- data.tar.gz: 17a15b5b8ea604e50a81c66d9060462db8885692
3
+ metadata.gz: efc9c6a7b39c3b76b42e258d51a6885c3677777b
4
+ data.tar.gz: e0e6eee03ba96525d16ea175863359de857041c8
5
5
  SHA512:
6
- metadata.gz: a06ebef4e8c31bfb8b6fea9f8da6d34a00e7fcd7ab255e08492caf618ab22cf5a5bcd4ab24f6c281d34de99bf037a203442fea7dce505ae08c028d73c21d1b2b
7
- data.tar.gz: 156c0dc859b84e6582ecbcf6153456cf4ce276a1cfd69a9bd12246173e693ccc191a9dc3f137de4743100131e3e69166db9f40b770b3aaf9a968f2ba4cded7f3
6
+ metadata.gz: a2dde3fec84aa51ca08fc1ef32b8b01a5d90b3d1918fdda89892823bb95c75465805a97022a521dcb7be93903e9ad7d4b0da8dec816150f37f0ab5cdd0de91e7
7
+ data.tar.gz: b45d2ac3a088060bd6db5cc1b0841bef920bd96326938c984a7165e8506275537479e057961ba748c2893f1ce115b281649201b7f6ff5fb5d24529b0e08cf66e
data/README.md CHANGED
@@ -26,6 +26,8 @@ Edit the `/config/initializers/croner.rb` file and customize following settings.
26
26
  Settings that save backup file.
27
27
  #### backup_path
28
28
  Backup file's path.
29
+ #### keep_backups
30
+ Num of keep backup files.
29
31
 
30
32
  ## Usage
31
33
  Make `config/croner/hosts/[hostname]` and run task `croner:update`.
@@ -13,9 +13,22 @@ module Croner
13
13
  # backup current cron contents
14
14
  if Croner.config.enable_backup
15
15
  if Croner.config.backup_path.blank?
16
- `crontab -l > ./cron_#{Time.current.strftime('%Y%m%d%H%M%S')}.bak`
16
+ backup_path = '.'
17
17
  else
18
- `crontab -l > ./#{Croner.config.backup_path}/cron_#{Time.current.strftime('%Y%m%d%H%M%S')}.bak`
18
+ backup_path = "./#{Croner.config.backup_path}"
19
+ end
20
+ `crontab -l > #{backup_path}/cron_#{Time.current.strftime('%Y%m%d%H%M%S')}.bak`
21
+
22
+ # delete over backup files
23
+ backup_files = Dir.glob("#{backup_path}/cron_*.bak")
24
+ if backup_files.count > Croner.config.keep_backups
25
+ backup_dates = backup_files.map do |backup_file|
26
+ backup_file.match(/cron_([0-9]{14}).bak$/)[1] rescue nil
27
+ end
28
+ delete_backup_files = backup_dates.compact.sort.first(backup_files.count - Croner.config.keep_backups).map{|backup_date| "#{backup_path}/cron_#{backup_date}.bak"}
29
+ delete_backup_files.each do |delete_backup_file|
30
+ File.delete(delete_backup_file)
31
+ end
19
32
  end
20
33
  end
21
34
 
@@ -1,6 +1,8 @@
1
1
  module Croner
2
2
  class Config
3
3
  # Variables detail is writen in lib/generators/templates/croner.rb.
4
+ attr_accessor :enable_backup
4
5
  attr_accessor :backup_path
6
+ attr_accessor :keep_backups
5
7
  end
6
8
  end
@@ -1,3 +1,3 @@
1
1
  module Croner
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -3,5 +3,8 @@ Croner.configure do |config|
3
3
  config.enable_backup = true
4
4
 
5
5
  # Backup path
6
- config.backup_path = ""
6
+ config.backup_path = ""
7
+
8
+ # num of keep backups
9
+ config.keep_backups = 5
7
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: croner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ykogure
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-10 00:00:00.000000000 Z
11
+ date: 2017-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails