Skip to content

Commit 84f5167

Browse files
author
Al Davidson
authored
Merge pull request #1138 from alphagov/gzip-mongo-exports
Gzip Mongo exports
2 parents 0685de5 + a180e39 commit 84f5167

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ spec
1717
test
1818
tmp
1919
vendor
20+
db/mongo-dumps

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
# Ignore the default SQLite database.
1111
/db/*.sqlite3
1212

13+
# Ignore mongo DB dumps
14+
/db/mongo-dumps
15+
1316
# Ignore all logfiles and tempfiles.
1417
/log/*.log
1518
/tmp

app/lib/mongo_exporter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ def self.collection_names
55

66
def self.export(collection:, path:)
77
FileUtils.mkdir_p(path)
8+
zipped_file_path = File.join(path, [collection, "json", "gz"].join("."))
89
execute(
910
"mongoexport",
1011
"--uri=#{ENV['MONGODB_URI']}",
1112
"--collection=#{collection}",
12-
"--out=#{File.join(path, [collection, 'json'].join('.'))}",
1313
"--type=json",
14+
" | gzip > #{zipped_file_path}",
1415
)
1516
end
1617

spec/lib/mongo_exporter_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
anything,
3535
"--uri=#{ENV['MONGODB_URI']}",
3636
"--collection=my_collection",
37-
"--out=/my/path/my_collection.json",
3837
"--type=json",
38+
" | gzip > /my/path/my_collection.json.gz",
3939
)
4040
described_class.export(collection: "my_collection", path: "/my/path")
4141
end

0 commit comments

Comments
 (0)