rmybackup 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -33,8 +33,15 @@ The default location for the configuration file is /etc/rmybackup.conf then ~/.r
33
33
 
34
34
  ---
35
35
  backup_dir: /Users/username/mysql_backups/
36
+
37
+ #Pruning. Remove_after is evaluated first, then only_keep
38
+
39
+ #Remove after x days
36
40
  remove_after: 7
37
41
 
42
+ #Only keep x number
43
+ only_keep: 5
44
+
38
45
  #Database
39
46
  username: root
40
47
  password: password
@@ -1,6 +1,13 @@
1
1
  ---
2
2
  backup_dir: /Users/username/mysql_backups/
3
- remove_after: 7
3
+
4
+ #Pruning. Remove_after is evaluated first, then only_keep
5
+
6
+ #Remove after x days
7
+ #remove_after: 7
8
+
9
+ #Only keep x number
10
+ #only_keep: 5
4
11
 
5
12
  #Database
6
13
  username: root
@@ -14,4 +14,14 @@ module RMyBackup
14
14
  end
15
15
  end
16
16
  end
17
+
18
+ def self.purge_number(path,number=false)
19
+ return true unless number
20
+ all_files = Dir[File.join(path,"*.gz")].sort_by {|f| File.mtime(f)}.reverse
21
+ keep = all_files[0..number - 1]
22
+ remove = all_files - keep
23
+ remove.each do |f|
24
+ File.delete f
25
+ end
26
+ end
17
27
  end
data/lib/rmybackup.rb CHANGED
@@ -7,7 +7,7 @@ require File.expand_path('../rmybackup/purge_files',__FILE__)
7
7
 
8
8
  module RMyBackup
9
9
 
10
- GEM_VERSION = "0.2.1"
10
+ GEM_VERSION = "0.3.0"
11
11
 
12
12
  class Base
13
13
  def initialize(config_file)
@@ -44,6 +44,7 @@ module RMyBackup
44
44
 
45
45
  #Purge after x days
46
46
  RMyBackup.purge_days(backup_dir,@config['remove_after'])
47
+ RMyBackup.purge_number(backup_dir,@config['only_keep'])
47
48
  end
48
49
  end
49
50
 
@@ -73,6 +74,7 @@ module RMyBackup
73
74
  @config['mysqldump_command'] = "/usr/bin/mysqldump" if @config['mysqldump_command'].nil?
74
75
  @config['find_command'] = "/usr/bin/find" if @config['find_command'].nil?
75
76
  @config['remove_after'] = @config['remove_after'] || false
77
+ @config['only_keep'] = @config['only_keep'] || false
76
78
 
77
79
  @config['use_mycnf_credentials'] = @config['use_mycnf_credentials'] ? true : false
78
80
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bryan Shelton