data_keeper 0.1.7 → 0.1.8

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
  SHA256:
3
- metadata.gz: c525131692e6a1de920301cbc4b55360fc7dd089ccfc1b1db1068ef328b78e0c
4
- data.tar.gz: ee646b314fc7203cadab9c366559c060c91ae9a45cea906f4ee4f4409c5bcd76
3
+ metadata.gz: 0666762022ca90ffac33878de1b342661885b9aeecfdac775a729f3de2b48cc3
4
+ data.tar.gz: 0c17de29ea41f6023579bd8e8b6bb1e5bf34e682ff934291686d3c5721af02c2
5
5
  SHA512:
6
- metadata.gz: 2b7ae402b492cd31c8d82b0481f0c8088ef09f28d9fb09b37f86040e14c4ce6f1d2b4d2b75dca6f5bf78d18306844ed26657bcfcadfda0c0001523e8fac88534
7
- data.tar.gz: 38c8bb4d0fcdb05cd43f93f7a0d70f69f33067e2e40dea1c0e8ddc4e6b4910cc7f635e5291059801a5cecade692ca4e714deb841b152b9fe792785c9435408ca
6
+ metadata.gz: 6369301be6b94b87e5a8ea26d0e56926d560c9229c3ed7dba6a12e70193324584d7eec1e10ca7f3d02a4de5f5473a2b4fb0a4109094dd7176af5e8f2a5729995
7
+ data.tar.gz: c6ef2e6e5d521def03e06e3eb8c7113f9a8f61376d6b7d3f3e3d2b26fdc4c8ebc5cfba615d84224517fb5955c15d16e89e6a7a170f21bd6eb751aac810fdc975
@@ -21,14 +21,15 @@ module DataKeeper
21
21
  def retrieve(dump_name)
22
22
  tempfile = Tempfile.new
23
23
  local_store_dir = @local_store_dir
24
+ last_dump_filename = nil
24
25
 
25
26
  on complete_host do
26
- last_dump = capture :ls, "-1t #{File.join(local_store_dir, dump_name.to_s)} | head -n 1"
27
+ last_dump_filename = capture :ls, "-1t #{File.join(local_store_dir, dump_name.to_s)} | head -n 1"
27
28
 
28
- download! File.join(local_store_dir, dump_name.to_s, last_dump), tempfile.path
29
+ download! File.join(local_store_dir, dump_name.to_s, last_dump_filename), tempfile.path
29
30
  end
30
31
 
31
- yield(tempfile)
32
+ yield(tempfile, last_dump_filename)
32
33
  ensure
33
34
  tempfile.delete
34
35
  end
@@ -78,7 +78,7 @@ module DataKeeper
78
78
  end
79
79
 
80
80
  def retrieve(dump_name)
81
- prefix = "#{@store_dir}#{dump_name.to_s}"
81
+ prefix = "#{@store_dir}#{dump_name.to_s}/"
82
82
  last_dump = s3_client.list_contents(prefix).sort_by(&:last_modified).reverse.first
83
83
 
84
84
  Tempfile.create do |tmp_file|
@@ -86,7 +86,7 @@ module DataKeeper
86
86
  s3_client.stream_to_io(last_dump.key, tmp_file)
87
87
  tmp_file.flush
88
88
 
89
- yield(tmp_file)
89
+ yield(tmp_file, File.basename(last_dump.key))
90
90
  end
91
91
  end
92
92
 
@@ -35,4 +35,15 @@ namespace :data_keeper do
35
35
 
36
36
  DataKeeper.load_dump!(name, path)
37
37
  end
38
+
39
+ desc "Downloads the given dump raw file in the current directory"
40
+ task :download, [:name] => [:environment] do |_t, args|
41
+ name = args[:name]
42
+
43
+ if name.blank? || !DataKeeper.dump?(name)
44
+ raise "Please use this rake task giving a name of a configured dump. Ex: bin/rake data_keeper:pull[full]"
45
+ end
46
+
47
+ DataKeeper.download_dump!(name, ".")
48
+ end
38
49
  end
@@ -1,3 +1,3 @@
1
1
  module DataKeeper
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/lib/data_keeper.rb CHANGED
@@ -44,6 +44,15 @@ module DataKeeper
44
44
  end
45
45
  end
46
46
 
47
+ def self.download_dump!(name, path)
48
+ raise DumpDoesNotExist unless dump?(name)
49
+ raise NoStorageDefined if @storage.nil?
50
+
51
+ @storage.retrieve(name) do |file, filename|
52
+ FileUtils.cp file.path, File.join(path, filename)
53
+ end
54
+ end
55
+
47
56
  def self.load_dump!(name, path)
48
57
  raise DumpDoesNotExist unless File.file?(path)
49
58
  raise NoStorageDefined if @storage.nil?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_keeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Campos
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-05 00:00:00.000000000 Z
11
+ date: 2021-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -100,7 +100,7 @@ licenses:
100
100
  - MIT
101
101
  metadata:
102
102
  homepage_uri: https://github.com/rogercampos/data_keeper
103
- post_install_message:
103
+ post_install_message:
104
104
  rdoc_options: []
105
105
  require_paths:
106
106
  - lib
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements: []
118
118
  rubygems_version: 3.1.6
119
- signing_key:
119
+ signing_key:
120
120
  specification_version: 4
121
121
  summary: Easy management of database dumps for dev env
122
122
  test_files: []