Skip to content

Commit

Permalink
B #2144: Added logdb table to backup with federation (#2240)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmont authored and Ruben S. Montero committed Jul 10, 2018
1 parent 47fd5f6 commit 4462ba5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/onedb/onedb_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def backup(bck_file, federated = false)
FEDERATED_TABLES.each do |table|
f.puts "DROP TABLE IF EXISTS \"#{table}\";"
end
f.puts "DROP TABLE IF EXISTS \"logdb\";"
end

FEDERATED_TABLES.each do |table|
Expand All @@ -368,6 +369,34 @@ def backup(bck_file, federated = false)
end

end

rc = system("sqlite3 #{@sqlite_file} 'CREATE TABLE logdb_tmp AS SELECT * FROM logdb WHERE fed_index!=-1;'")

if !rc
raise "Error creating logdb_tmp."
end

Open3.popen3("sqlite3 #{@sqlite_file} '.dump logdb_tmp' >> #{bck_file}") do |i,o,e,t|
stdout = o.read
if !stdout.empty?
puts stdout
end

stderr = e.read
if !stderr.empty?
stderr.lines.each do |line|
STDERR.puts line unless line.match(/^-- Loading/)
end
end
end

rc = system("sqlite3 #{@sqlite_file} 'DROP TABLE logdb_tmp;'")

if !rc
raise "Error trying to drop the logdb tmp table."
end

File.write("#{bck_file}",File.open("#{bck_file}",&:read).gsub("logdb_tmp","logdb"))
else
connect_db

Expand Down

0 comments on commit 4462ba5

Please sign in to comment.