diff options
author | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-10-25 15:57:33 +0300 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-10-25 18:45:36 +0300 |
commit | 5c2780bb1112cc1aa094fcd73c08e101bb7625cc (patch) | |
tree | 2bc4f05dde65af00a961fec41337c8a11e5a0388 | |
parent | b5e7035c1a5e89845faada20addff98fdcefbd1e (diff) | |
download | gitlab-ce-jej/shared-database-seed.tar.gz |
WIP: Exportable developer seed environmentjej/shared-database-seed
-rw-r--r-- | lib/backup/manager.rb | 22 | ||||
-rw-r--r-- | lib/tasks/gitlab/backup.rake | 5 | ||||
-rw-r--r-- | lib/tasks/gitlab/export_seed.rake | 22 |
3 files changed, 38 insertions, 11 deletions
diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb index 092e82bd4d1..2db3814eaeb 100644 --- a/lib/backup/manager.rb +++ b/lib/backup/manager.rb @@ -4,19 +4,23 @@ module Backup FOLDERS_TO_BACKUP = %w[repositories db].freeze FILE_NAME_SUFFIX = '_gitlab_backup.tar'.freeze + def initialize(backup_config: {}) + @backup_config = Gitlab.config.backup.deep_merge(backup_config) + end + def pack # Make sure there is a connection ActiveRecord::Base.connection.reconnect! Dir.chdir(backup_path) do - File.open("#{backup_path}/backup_information.yml", "w+") do |file| + File.open("backup_information.yml", "w+") do |file| file << backup_information.to_yaml.gsub(/^---\n/, '') end # create archive $progress.print "Creating backup archive: #{tar_file} ... " # Set file permissions on open to prevent chmod races. - tar_system_options = { out: [tar_file, 'w', Gitlab.config.backup.archive_permissions] } + tar_system_options = { out: [tar_file, 'w', @backup_config.archive_permissions] } if Kernel.system('tar', '-cf', '-', *backup_contents, tar_system_options) $progress.puts "done".color(:green) else @@ -31,7 +35,7 @@ module Backup def upload $progress.print "Uploading backup archive to remote storage #{remote_directory} ... " - connection_settings = Gitlab.config.backup.upload.connection + connection_settings = @backup_config.upload.connection if connection_settings.blank? $progress.puts "skipped".color(:yellow) return @@ -40,9 +44,9 @@ module Backup directory = connect_to_remote_directory(connection_settings) if directory.files.create(key: remote_target, body: File.open(tar_file), public: false, - multipart_chunk_size: Gitlab.config.backup.upload.multipart_chunk_size, - encryption: Gitlab.config.backup.upload.encryption, - storage_class: Gitlab.config.backup.upload.storage_class) + multipart_chunk_size: @backup_config.upload.multipart_chunk_size, + encryption: @backup_config.upload.encryption, + storage_class: @backup_config.upload.storage_class) $progress.puts "done".color(:green) else puts "uploading backup to #{remote_directory} failed".color(:red) @@ -68,7 +72,7 @@ module Backup def remove_old # delete backups $progress.print "Deleting old backups ... " - keep_time = Gitlab.config.backup.keep_time.to_i + keep_time = @backup_config.keep_time.to_i if keep_time > 0 removed = 0 @@ -160,7 +164,7 @@ module Backup private def backup_path - Gitlab.config.backup.path + @backup_config.path end def backup_file_list @@ -182,7 +186,7 @@ module Backup end def remote_directory - Gitlab.config.backup.upload.remote_directory + @backup_config.upload.remote_directory end def remote_target diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake index 1650263b98d..838c0984050 100644 --- a/lib/tasks/gitlab/backup.rake +++ b/lib/tasks/gitlab/backup.rake @@ -4,7 +4,7 @@ namespace :gitlab do namespace :backup do # Create backup of GitLab system desc "GitLab | Create a backup of the GitLab system" - task create: :environment do + task :create, [:backup_config] => :environment do |task, args| warn_user_is_not_gitlab configure_cron_mode @@ -17,7 +17,8 @@ namespace :gitlab do Rake::Task["gitlab:backup:lfs:create"].invoke Rake::Task["gitlab:backup:registry:create"].invoke - backup = Backup::Manager.new + #TODO: Check task still works without args + backup = Backup::Manager.new(backup_config: args.backup_config) backup.pack backup.cleanup backup.remove_old diff --git a/lib/tasks/gitlab/export_seed.rake b/lib/tasks/gitlab/export_seed.rake new file mode 100644 index 00000000000..8d72e4c0923 --- /dev/null +++ b/lib/tasks/gitlab/export_seed.rake @@ -0,0 +1,22 @@ +namespace :gitlab do + desc "GitLab | Seed GitLab and create a backup" + task export_seed: :environment do + # abort "Do not run outside of CI" unless Rails.env.test? + + # Rake::Task["db:reset"].invoke + # Rake::Task["setup_postgresql"].invoke + # Rake::Task["db:seed_fu"].invoke + + #TODO: Seed more data with generate series + + backup_config = if ENV['BACKUP_CONFIG'] + YAML.load(ENV['BACKUP_CONFIG']) + else + {} + end + + Rake::Task["gitlab:backup:create"].invoke(backup_config) + + #TODO: Upload version sha to S3 + end +end |