incremental_backup 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f406c74bc2c38c08092f0d93b5156c78c196aa4
4
+ data.tar.gz: 22dfd35797a0b24abbf3a5752161e5dece0fc394
5
+ SHA512:
6
+ metadata.gz: fd12559460f18568aa9adcb0644ff48db2d88cc12e3f814e646fcfbdc17114a18b9ee0fd3430517aaa18b5bd5a6965ab8a8fed6582ee217fb0624c52d0f4fb3a
7
+ data.tar.gz: 8a5c7554e2d044590aa27f241f62fe4cd6c8ad49bd6af084c399d759f94c5c82bca674ca7272c6b044ee40bd78b73501c04206f236070950b6c8b6b010af5d82
data/README.md CHANGED
@@ -13,6 +13,7 @@ The backup is by default performed every hour of a determined set of files and f
13
13
  * Ruby (tested on 1.9.3)
14
14
  * ssh
15
15
  * rsync
16
+ * trickle (only needed if using throttling)
16
17
 
17
18
  ## Installation
18
19
 
@@ -27,6 +28,10 @@ It's recommended to setup a cron job to handle scheduling of the backup.
27
28
 
28
29
  The cron job can be triggered as often as you would like to, the script still only at most perform one backup per hour. This is useful if your computer is usually not online for more than an hour.
29
30
 
31
+ ## Alternatives
32
+
33
+ * [meskyanichi/backup](https://github.com/meskyanichi/backup) - An all-in-one solution for backups of files and databases. Pretty awesome!
34
+
30
35
  ## Contributing
31
36
 
32
37
  1. Fork it
@@ -82,9 +82,8 @@ module IncrementalBackup
82
82
 
83
83
  def delete_old_backups(schedule)
84
84
  backups = list_backup_dir schedule
85
- backups_to_keep = settings.send("#{schedule}_backups")
86
85
  backups.sort!
87
- backups_to_delete = backups - backups.last(backups_to_keep)
86
+ backups_to_delete = backups - backups.last(backups_to_keep(schedule))
88
87
  if backups_to_delete.any?
89
88
  if backups_to_delete.length == 1
90
89
  logger.info "Deleting old backup #{backups_to_delete.first}"
@@ -95,6 +94,10 @@ module IncrementalBackup
95
94
  end
96
95
  end
97
96
 
97
+ def backups_to_keep(schedule)
98
+ settings.send("#{schedule}_backups")
99
+ end
100
+
98
101
  def list_backup_dir(schedule)
99
102
  execute_ssh("mkdir -p #{schedule_path schedule}")
100
103
  execute_ssh("find #{schedule_path schedule} -maxdepth 1 -mindepth 1").split("\n")
@@ -149,6 +152,7 @@ module IncrementalBackup
149
152
 
150
153
  now = DateTime.now
151
154
  [:yearly, :monthly, :weekly, :daily, :hourly].each do |schedule|
155
+ next if backups_to_keep(schedule) <= 0
152
156
  list = list_backup_dir schedule
153
157
  date = list.map { |path| parse_backup_dir_name path, now.offset }.max
154
158
  return schedule if !date || (now - date) * 24 * 60 >= minutes[schedule]
@@ -1,3 +1,3 @@
1
1
  module IncrementalBackup
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/live_example/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'incremental_backup', '~> 0.0'
3
+ gem 'incremental_backup'
4
4
 
@@ -16,21 +16,26 @@ task = IncrementalBackup::Task.new do |settings|
16
16
  settings.monthly_backups = 12
17
17
  settings.yearly_backups = 100
18
18
 
19
- # This is where all helper files are saved. These include a log file, a lock
20
- # file and a file remembering the dates of the the last backups. This would
21
- # typically be a hidden directory in the home folder, e.g. ~/.incremental_backup
22
- settings.settings_path = File.dirname(__FILE__)
19
+ # This is where all helper files are saved. These include a log file and a
20
+ # lock file This would typically be a hidden directory in the home folder,
21
+ # e.g. ~/.incremental_backup
22
+ settings.settings_path = '/home/username/.incremental_backup'
23
23
 
24
24
  # Login options
25
25
  settings.remote_server = 'hostname or ip'
26
- settings.remote_user = 'username on server'
26
+ settings.remote_user = 'remote username'
27
27
 
28
- # Paths
29
- settings.local_path = '~'
30
- settings.remote_path = '~/backup'
28
+ # Local path - Trailing slash matters!
29
+ settings.local_path = '/home/username/'
31
30
 
32
- # Exclude all the files and folder listed in this file. This file is in default rsync syntax
33
- settings.exclude_file = File.join File.dirname(__FILE__), 'exclude.file'
31
+ # Remote path
32
+ settings.remote_path = '/home/remote username/backup'
33
+
34
+ # Exclude all the files and folder listed in this file
35
+ settings.exclude_file = '/home/username/.backup_task/exclude.file'
36
+
37
+ # In kB/s - this feature requires trickle
38
+ settings.max_upload_speed = 20
34
39
  end
35
40
 
36
41
  task.run
@@ -1,6 +1,46 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe IncrementalBackup::Task do
4
+
5
+ let(:task) do
6
+ task = IncrementalBackup::Task.new do |settings|
7
+ settings.yearly_backups = yearly_backups
8
+
9
+ settings.task_id = "test_test"
10
+ settings.settings_path = "some/path"
11
+ settings.remote_server = "myserver"
12
+ settings.local_path = "some/path"
13
+ settings.remote_path = "some/path"
14
+ settings.remote_user = "me"
15
+ end
16
+
17
+ logger_double = double('logger')
18
+ logger_double.stub(:error) { |message| logger_errors << message }
19
+ logger_double.stub(:info)
20
+ task.stub(:logger).and_return logger_double
21
+
22
+ task.stub(:execute_ssh)
23
+ task.stub(:list_backup_dir).and_return(list_backup_dir)
24
+
25
+ IncrementalBackup::Lock.stub(:create).and_yield
26
+ IncrementalBackup::Rsync.stub(:execute)
27
+
28
+ task
29
+ end
30
+
31
+ let(:logger_errors) { [] }
32
+ let(:yearly_backups) { 100 }
33
+ let(:list_backup_dir) do
34
+ [
35
+ "/hourly/backup_2013-02-14-T10-39-27",
36
+ "/hourly/backup_2013-02-14-T10-21-43",
37
+ "/hourly/backup_2013-02-14-T11-02-46",
38
+ "/hourly/backup_2013-02-14-T10-35-04",
39
+ "/hourly/backup_2013-02-14-T10-28-11",
40
+ "/hourly/backup_2013-02-14-T10-33-24"
41
+ ]
42
+ end
43
+
4
44
  it 'should be configured' do
5
45
  task = IncrementalBackup::Task.new do |config|
6
46
  config.hourly_backups = 1
@@ -26,34 +66,16 @@ describe IncrementalBackup::Task do
26
66
  task.run
27
67
  end
28
68
 
29
- it 'runs' do
30
- task = IncrementalBackup::Task.new do |settings|
31
- settings.task_id = "test_test"
32
- settings.settings_path = "some/path"
33
- settings.remote_server = "myserver"
34
- settings.local_path = "some/path"
35
- settings.remote_path = "some/path"
36
- settings.remote_user = "me"
37
- end
69
+ context 'when yearly is set to zero' do
70
+ subject { task }
71
+ let(:yearly_backups) { 0 }
72
+ let(:list_backup_dir) { [] }
38
73
 
39
- logger_double = double('logger')
40
- logger_errors = []
41
- logger_double.stub(:error) { |message| logger_errors << message }
42
- logger_double.stub(:info)
43
- task.stub(:logger).and_return logger_double
74
+ its(:find_schedule) { should == :monthly }
75
+ end
44
76
 
45
- task.stub(:execute_ssh)
46
- task.stub(:list_backup_dir).and_return([
47
- "/hourly/backup_2013-02-14-T10-39-27",
48
- "/hourly/backup_2013-02-14-T10-21-43",
49
- "/hourly/backup_2013-02-14-T11-02-46",
50
- "/hourly/backup_2013-02-14-T10-35-04",
51
- "/hourly/backup_2013-02-14-T10-28-11",
52
- "/hourly/backup_2013-02-14-T10-33-24"
53
- ])
77
+ it 'runs' do
54
78
 
55
- IncrementalBackup::Lock.stub(:create).and_yield
56
- IncrementalBackup::Rsync.stub(:execute)
57
79
 
58
80
  task.run
59
81
 
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incremental_backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Lasse Skindstad Ebert
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-03 00:00:00.000000000 Z
11
+ date: 2013-05-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec-mocks
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: guard-rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rb-inotify
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: active_attr
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ~>
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ~>
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: net-ssh
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ~>
124
109
  - !ruby/object:Gem::Version
@@ -153,33 +138,26 @@ files:
153
138
  - spec/unit/version_spec.rb
154
139
  homepage: https://github.com/lasseebert/incremental_backup
155
140
  licenses: []
141
+ metadata: {}
156
142
  post_install_message:
157
143
  rdoc_options: []
158
144
  require_paths:
159
145
  - lib
160
146
  required_ruby_version: !ruby/object:Gem::Requirement
161
- none: false
162
147
  requirements:
163
- - - ! '>='
148
+ - - '>='
164
149
  - !ruby/object:Gem::Version
165
150
  version: '0'
166
- segments:
167
- - 0
168
- hash: 418782939292199546
169
151
  required_rubygems_version: !ruby/object:Gem::Requirement
170
- none: false
171
152
  requirements:
172
- - - ! '>='
153
+ - - '>='
173
154
  - !ruby/object:Gem::Version
174
155
  version: '0'
175
- segments:
176
- - 0
177
- hash: 418782939292199546
178
156
  requirements: []
179
157
  rubyforge_project:
180
- rubygems_version: 1.8.23
158
+ rubygems_version: 2.0.0
181
159
  signing_key:
182
- specification_version: 3
160
+ specification_version: 4
183
161
  summary: incremental_backup can make incremental backups by hour/day/week/month/year
184
162
  remotely through ssh and rsync
185
163
  test_files: