easy_backup 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +60 -35
- data/easy_backup.gemspec +13 -15
- data/lib/easy_backup/configuration.rb +8 -14
- data/lib/easy_backup/{adapter → resources}/file_system.rb +30 -30
- data/lib/easy_backup/resources/postgres.rb +86 -0
- data/lib/easy_backup/{adapter → resources}/sftp.rb +14 -10
- data/lib/easy_backup/specification.rb +36 -0
- data/lib/easy_backup/version.rb +1 -1
- data/lib/easy_backup.rb +14 -43
- data/spec/file_system_spec.rb +136 -0
- data/spec/postgres_spec.rb +91 -0
- data/spec/scheduler_spec.rb +26 -0
- data/spec/sftp_spec.rb +47 -0
- data/spec/spec_helper.rb +17 -3
- data/spec/specification_spec.rb +40 -0
- data/spec/support/helpers/fake_storage.rb +11 -0
- data/spec/support/helpers/file_helper.rb +54 -0
- data/spec/support/helpers/{postgre_sql_helper.rb → postgres_helper.rb} +1 -1
- metadata +32 -68
- data/lib/easy_backup/adapter/db/postgre_sql.rb +0 -90
- data/lib/easy_backup/base.rb +0 -46
- data/lib/easy_backup/frequency.rb +0 -13
- data/lib/easy_backup/runner.rb +0 -9
- data/spec/execution/runner_spec.rb +0 -131
- data/spec/execution/scheduled_spec.rb +0 -29
- data/spec/files/config/backup_config.rb +0 -20
- data/spec/specification/configuration_spec.rb +0 -100
- data/spec/specification/easy_backup_spec.rb +0 -34
- data/spec/specification/file_system_adapter_spec.rb +0 -39
- data/spec/specification/postgre_sql_adapter_spec.rb +0 -36
- data/spec/specification/sftp_adapter_spec.rb +0 -18
@@ -1,131 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'JSON'
|
3
|
-
require 'yaml'
|
4
|
-
require 'sequel'
|
5
|
-
require 'zip/zip'
|
6
|
-
require 'net/sftp'
|
7
|
-
|
8
|
-
describe Runner, '-> Execution' do
|
9
|
-
|
10
|
-
after :all do
|
11
|
-
FileUtils.rm_rf BACKUP_PATH
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'Backup a file to file system' do
|
15
|
-
config = Configuration.new do
|
16
|
-
save FileSystem do
|
17
|
-
file "#{DATA_PATH}/sample.json"
|
18
|
-
end
|
19
|
-
into FileSystem do
|
20
|
-
folder "#{BACKUP_PATH}/#{Time.now.strftime('%Y%m%d%H%M%S%L')}"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
Runner.run config
|
25
|
-
|
26
|
-
file = "#{config.storages.first.folders.first}/sample.json"
|
27
|
-
File.exist?(file).should be_true
|
28
|
-
data = File.open(file, 'r') { |f| JSON.parse f.readlines.join }
|
29
|
-
data['id'].should eq 1234
|
30
|
-
data['name'].should eq 'sample'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'Backup folder to file system' do
|
34
|
-
config = Configuration.new do
|
35
|
-
save FileSystem do
|
36
|
-
folder "#{DATA_PATH}/txt"
|
37
|
-
end
|
38
|
-
into FileSystem do
|
39
|
-
folder "#{BACKUP_PATH}/#{Time.now.strftime('%Y%m%d%H%M%S%L')}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
Runner.run config
|
44
|
-
|
45
|
-
path = "#{config.storages.first.folders.first}/txt"
|
46
|
-
(1..2).each do |i|
|
47
|
-
file = "#{path}/#{i}/text#{i}.txt"
|
48
|
-
File.exist?(file).should be_true
|
49
|
-
File.open(file, 'r') { |f| f.gets.should eq "Text file #{i}" }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'Backup file and folder zipped to file system' do
|
54
|
-
zip_file = "data_#{Time.now.strftime('%Y%m%d%H%M%S%L')}.zip"
|
55
|
-
backup_path = "#{BACKUP_PATH}/#{Time.now.strftime('%Y%m%d%H%M%S%L')}"
|
56
|
-
|
57
|
-
config = Configuration.new do
|
58
|
-
save FileSystem do
|
59
|
-
folder "#{DATA_PATH}/txt"
|
60
|
-
folder "#{DATA_PATH}/sample.json"
|
61
|
-
zip zip_file
|
62
|
-
end
|
63
|
-
into FileSystem do
|
64
|
-
folder backup_path
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
Runner.run config
|
69
|
-
|
70
|
-
File.exists?("#{backup_path}/#{zip_file}").should be_true
|
71
|
-
|
72
|
-
Zip::ZipFile.open("#{backup_path}/#{zip_file}") do |zip|
|
73
|
-
zip.find_entry('sample.json').should_not be_nil
|
74
|
-
zip.find_entry('txt/1/text1.txt').should_not be_nil
|
75
|
-
zip.find_entry('txt/2/text2.txt').should_not be_nil
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'Backup PostgreSQL to file system' do
|
80
|
-
PostgreSQLHelper.create_db
|
81
|
-
db = PostgreSQLHelper.configuration
|
82
|
-
backup_path = "#{BACKUP_PATH}/#{Time.now.strftime('%Y%m%d%H%M%S%L')}"
|
83
|
-
|
84
|
-
config = Configuration.new do
|
85
|
-
save PostgreSQL do
|
86
|
-
host db['host']
|
87
|
-
database db['database']
|
88
|
-
port db['port']
|
89
|
-
username db['username']
|
90
|
-
password db['password']
|
91
|
-
zip
|
92
|
-
end
|
93
|
-
into FileSystem do
|
94
|
-
folder backup_path
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
Runner.run config
|
99
|
-
|
100
|
-
PostgreSQLHelper.drop_db
|
101
|
-
|
102
|
-
Dir["#{backup_path}/#{db['database']}_*.zip"].should have(1).items
|
103
|
-
Zip::ZipFile.foreach(Dir["#{backup_path}/#{db['database']}_*.zip"].first) do |entry|
|
104
|
-
entry.get_input_stream.read.should include 'PostgreSQL database dump'
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'Backup a file to sftp' do
|
109
|
-
storage = ConfigHelper.get 'sftp'
|
110
|
-
backup_path = "tmp/#{Time.now.strftime('%Y%m%d%H%M%S%L')}"
|
111
|
-
config = Configuration.new do
|
112
|
-
save FileSystem do
|
113
|
-
file "#{DATA_PATH}/txt/1/text1.txt"
|
114
|
-
end
|
115
|
-
into SFTP do
|
116
|
-
host storage['host']
|
117
|
-
username storage['username']
|
118
|
-
password storage['password']
|
119
|
-
folder backup_path
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
Runner.run config
|
124
|
-
|
125
|
-
Net::SFTP.start(storage['host'], storage['username'], :password => storage['password']) do |sftp|
|
126
|
-
sftp.dir.glob(backup_path, 'text1.txt').should have(1).item
|
127
|
-
sftp.file.open("#{backup_path}/text1.txt", 'r') { |f| f.gets.should eq 'Text file 1' }
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe EasyBackup, '-> Scheduled run' do
|
4
|
-
|
5
|
-
after :all do
|
6
|
-
FileUtils.rm_rf BACKUP_PATH
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'Run scheduled backup' do
|
10
|
-
test_path = "#{BACKUP_PATH}/#{Time.now.to_f}"
|
11
|
-
|
12
|
-
EasyBackup::Base.new 0.5 do
|
13
|
-
config :test_backup do
|
14
|
-
save FileSystem do
|
15
|
-
file "#{DATA_PATH}/txt/1/text1.txt"
|
16
|
-
end
|
17
|
-
into FileSystem do
|
18
|
-
folder lambda { "#{test_path}/#{Time.now.strftime('%Y-%m-%d %H_%M_%S_%L')}" }
|
19
|
-
end
|
20
|
-
every 0.5, from: 1.second.from_now
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
sleep(2)
|
25
|
-
|
26
|
-
Dir.glob("#{test_path}/*").should have(2).items
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
config :test_backup do
|
2
|
-
|
3
|
-
save PostgreSQL do
|
4
|
-
host 'localhost'
|
5
|
-
database 'test_db'
|
6
|
-
username 'user'
|
7
|
-
password 'password'
|
8
|
-
end
|
9
|
-
|
10
|
-
save FileSystem do
|
11
|
-
folder 'c:/data'
|
12
|
-
end
|
13
|
-
|
14
|
-
into FileSystem do
|
15
|
-
folder 'c:/backup'
|
16
|
-
end
|
17
|
-
|
18
|
-
every 1.day, from: 'today at 22:30'
|
19
|
-
|
20
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Configuration, '-> Specification' do
|
4
|
-
|
5
|
-
it 'Save file system' do
|
6
|
-
config = Configuration.new
|
7
|
-
|
8
|
-
config.resources.should be_empty
|
9
|
-
|
10
|
-
config.save FileSystem do
|
11
|
-
folder 'c:/folder1'
|
12
|
-
file 'c:/folder2/file.txt'
|
13
|
-
end
|
14
|
-
|
15
|
-
config.save FileSystem do
|
16
|
-
folder 'c:/folder3'
|
17
|
-
folder 'c:/folder4'
|
18
|
-
folder 'c:/folder5'
|
19
|
-
end
|
20
|
-
|
21
|
-
config.resources.should have(2).items
|
22
|
-
|
23
|
-
config.resources[0].should be_a FileSystem
|
24
|
-
config.resources[0].folders.should have(1).items
|
25
|
-
config.resources[0].folders.should include 'c:/folder1'
|
26
|
-
config.resources[0].files.should have(1).items
|
27
|
-
config.resources[0].files.should include 'c:/folder2/file.txt'
|
28
|
-
|
29
|
-
config.resources[1].should be_a FileSystem
|
30
|
-
config.resources[1].folders.should have(3).items
|
31
|
-
config.resources[1].folders.should include 'c:/folder3'
|
32
|
-
config.resources[1].folders.should include 'c:/folder4'
|
33
|
-
config.resources[1].folders.should include 'c:/folder5'
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'Save postgre sql' do
|
37
|
-
config = Configuration.new
|
38
|
-
|
39
|
-
config.resources.should be_empty
|
40
|
-
|
41
|
-
config.save PostgreSQL do
|
42
|
-
host '192.168.0.0'
|
43
|
-
database 'db0'
|
44
|
-
username 'user0'
|
45
|
-
password 'password0'
|
46
|
-
end
|
47
|
-
|
48
|
-
config.save PostgreSQL do
|
49
|
-
host '192.168.0.1'
|
50
|
-
database 'db1'
|
51
|
-
username 'user1'
|
52
|
-
password 'password1'
|
53
|
-
end
|
54
|
-
|
55
|
-
config.resources.should have(2).items
|
56
|
-
|
57
|
-
(0..1).each do |i|
|
58
|
-
config.resources[i].should be_a PostgreSQL
|
59
|
-
config.resources[i].host.should eq "192.168.0.#{i}"
|
60
|
-
config.resources[i].database.should eq "db#{i}"
|
61
|
-
config.resources[i].username.should eq "user#{i}"
|
62
|
-
config.resources[i].password.should eq "password#{i}"
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'In file system' do
|
68
|
-
config = Configuration.new
|
69
|
-
|
70
|
-
config.storages.should be_empty
|
71
|
-
|
72
|
-
config.into FileSystem do
|
73
|
-
folder 'c:/backup'
|
74
|
-
end
|
75
|
-
|
76
|
-
config.into FileSystem do
|
77
|
-
folder 'c:/other_backup'
|
78
|
-
end
|
79
|
-
|
80
|
-
config.storages.should have(2).items
|
81
|
-
config.storages[0].folders[0].should eq 'c:/backup'
|
82
|
-
config.storages[1].folders[0].should eq 'c:/other_backup'
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'Every day at 22:30 and weekly at 03:00' do
|
86
|
-
config = Configuration.new
|
87
|
-
|
88
|
-
config.frequencies.should be_empty
|
89
|
-
|
90
|
-
config.every 1.day, from: 'today at 22:30'
|
91
|
-
config.every 1.week, from: 'today at 03:00'
|
92
|
-
|
93
|
-
config.frequencies.should have(2).items
|
94
|
-
config.frequencies[0].interval.should eq 1.day
|
95
|
-
config.frequencies[0].from.should eq Time.local(Time.now.year, Time.now.month, Time.now.day, 22, 30)
|
96
|
-
config.frequencies[1].interval.should eq 1.week
|
97
|
-
config.frequencies[1].from.should eq Time.local(Time.now.year, Time.now.month, Time.now.day, 3)
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe EasyBackup, '-> Specification' do
|
4
|
-
|
5
|
-
it 'Simple configuration' do
|
6
|
-
backup = EasyBackup.config do
|
7
|
-
save PostgreSQL do
|
8
|
-
host 'localhost'
|
9
|
-
database 'test_db'
|
10
|
-
username 'user'
|
11
|
-
password 'password'
|
12
|
-
end
|
13
|
-
|
14
|
-
save FileSystem do
|
15
|
-
folder 'c:/data'
|
16
|
-
end
|
17
|
-
|
18
|
-
into FileSystem do
|
19
|
-
folder 'c:/backup'
|
20
|
-
end
|
21
|
-
|
22
|
-
every 1.day, from: 'today at 22:30'
|
23
|
-
end
|
24
|
-
|
25
|
-
backup[:default].should be_a Configuration
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'Configure from file' do
|
29
|
-
backup = EasyBackup.load "#{File.dirname(__FILE__)}/../files/config/backup_config.rb"
|
30
|
-
|
31
|
-
backup[:test_backup].should be_a Configuration
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe FileSystem, '-> Specification' do
|
4
|
-
|
5
|
-
it 'Append folders' do
|
6
|
-
fs = FileSystem.new
|
7
|
-
fs.folder 'c:/folder1'
|
8
|
-
fs.folder 'c:/folder2'
|
9
|
-
|
10
|
-
fs.folders.should have(2).items
|
11
|
-
fs.folders.should include('c:/folder1')
|
12
|
-
fs.folders.should include('c:/folder2')
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'Append files' do
|
16
|
-
fs = FileSystem.new
|
17
|
-
fs.file 'c:/file1.txt'
|
18
|
-
fs.file 'c:/file2.txt'
|
19
|
-
|
20
|
-
fs.files.should have(2).items
|
21
|
-
fs.files.should include('c:/file1.txt')
|
22
|
-
fs.files.should include('c:/file2.txt')
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'Zip files and folders' do
|
26
|
-
fs = FileSystem.new
|
27
|
-
|
28
|
-
fs.zip_file.should be_nil
|
29
|
-
|
30
|
-
fs.zip 'data.zip'
|
31
|
-
|
32
|
-
fs.zip_file.should eq 'data.zip'
|
33
|
-
|
34
|
-
fs.zip lambda { "#{Time.now}.zip" }
|
35
|
-
|
36
|
-
fs.zip_file.should eq "#{Time.now}.zip"
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PostgreSQL, '-> Specification' do
|
4
|
-
|
5
|
-
it 'Specify database parameters' do
|
6
|
-
db = PostgreSQL.new
|
7
|
-
db.host '192.168.0.1'
|
8
|
-
db.port 1234
|
9
|
-
db.database 'test_db'
|
10
|
-
db.username 'user'
|
11
|
-
db.password 'password'
|
12
|
-
db.dump_file 'db.sql'
|
13
|
-
db.zip
|
14
|
-
|
15
|
-
db.host.should eq '192.168.0.1'
|
16
|
-
db.port.should eq 1234
|
17
|
-
db.database.should eq 'test_db'
|
18
|
-
db.username.should eq 'user'
|
19
|
-
db.password.should eq 'password'
|
20
|
-
db.dump_file.should eq 'db.sql'
|
21
|
-
db.zip_file.should eq 'db.zip'
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'Get database default parameters' do
|
25
|
-
db = PostgreSQL.new
|
26
|
-
|
27
|
-
db.host.should eq 'localhost'
|
28
|
-
db.port.should eq 5432
|
29
|
-
db.database.should be_nil
|
30
|
-
db.username.should eq 'postgres'
|
31
|
-
db.password.should be_nil
|
32
|
-
db.dump_file.should eq "#{db.database}_#{Time.now.strftime('%Y%m%d%H%M%S')}.sql"
|
33
|
-
db.zip_file.should be_nil
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SFTP, '-> Specification' do
|
4
|
-
|
5
|
-
it 'Specify sftp parameters' do
|
6
|
-
sftp = SFTP.new
|
7
|
-
sftp.host '192.168.0.1'
|
8
|
-
sftp.username 'user'
|
9
|
-
sftp.password 'password'
|
10
|
-
sftp.folder '/backup'
|
11
|
-
|
12
|
-
sftp.host.should eq '192.168.0.1'
|
13
|
-
sftp.username.should eq 'user'
|
14
|
-
sftp.password.should eq 'password'
|
15
|
-
sftp.folder.should eq '/backup'
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|