summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2015-09-18 14:14:26 +0200
committerJacob Vosmaer <contact@jacobvosmaer.nl>2015-09-18 14:14:26 +0200
commitd1ed3d1c5290e6123df1842188457521fde95c2b (patch)
tree700f2bdaa4edea92ea4844b47bc5ee644a6eecff
parent7ac27f1e34083eb5fc6e36f3abac2f9cac7533b8 (diff)
downloadgitlab-ci-d1ed3d1c5290e6123df1842188457521fde95c2b.tar.gz
Do DB dumps required for final export
-rw-r--r--lib/backup/database.rb29
1 files changed, 9 insertions, 20 deletions
diff --git a/lib/backup/database.rb b/lib/backup/database.rb
index 0c5a3e9..bde9eef 100644
--- a/lib/backup/database.rb
+++ b/lib/backup/database.rb
@@ -2,6 +2,13 @@ require 'yaml'
module Backup
class Database
+ TABLES = %w{
+ ci_application_settings ci_builds ci_commits ci_events ci_jobs ci_projects
+ ci_runner_projects ci_runners ci_services ci_tags ci_taggings ci_trigger_requests
+ ci_triggers ci_variables ci_web_hooks
+ }
+ TABLES.map! { |t| t.sub('ci_', '') } # hack until Kamil's migration lands
+
attr_reader :config, :db_dir
def initialize
@@ -19,11 +26,11 @@ module Backup
dump_pid = case config["adapter"]
when /^mysql/ then
$progress.print "Dumping MySQL database #{config['database']} ... "
- spawn('mysqldump', *mysql_args, config['database'], out: compress_wr)
+ spawn('mysqldump', *mysql_args, config['database'], *TABLES, out: compress_wr)
when "postgresql" then
$progress.print "Dumping PostgreSQL database #{config['database']} ... "
pg_env
- spawn('pg_dump', config['database'], out: compress_wr)
+ spawn('pg_dump', '--clean', *TABLES.map { |t| "--table=#{t}" }, config['database'], out: compress_wr)
end
compress_wr.close
@@ -44,10 +51,6 @@ module Backup
spawn('mysql', *mysql_args, config['database'], in: decompress_rd)
when "postgresql" then
$progress.print "Restoring PostgreSQL database #{config['database']} ... "
- # Drop all tables because PostgreSQL DB dumps do not contain DROP TABLE
- # statements like MySQL.
- drop_all_tables
- drop_all_postgres_sequences
pg_env
spawn('psql', config['database'], in: decompress_rd)
end
@@ -91,19 +94,5 @@ module Backup
$progress.puts '[FAILED]'.red
end
end
-
- def drop_all_tables
- connection = ActiveRecord::Base.connection
- connection.tables.each do |table|
- connection.drop_table(table)
- end
- end
-
- def drop_all_postgres_sequences
- connection = ActiveRecord::Base.connection
- connection.execute("SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';").each do |sequence|
- connection.execute("DROP SEQUENCE #{sequence['relname']}")
- end
- end
end
end