Commit cc41a771 authored by Will Chandler's avatar Will Chandler

Add timestamps to gitlab-rake gitlab:backup:restore

Adds a new method 'puts_time' that prepends the time of a
message when printing it.  All instances of 'progress.puts'
in the gitlab:backup:restore tasks are replaced with puts_time.
Example output:
  2018-06-03 16:33:25 -0400 -- Restoring uploads ..
Closes #46448
parent fe0ebf76
---
title: Display timestamps to messages printed by gitlab:backup:restore rake tasks
merge_request:
author: Will Chandler
type: changed
...@@ -47,9 +47,9 @@ namespace :gitlab do ...@@ -47,9 +47,9 @@ namespace :gitlab do
# Drop all tables Load the schema to ensure we don't have any newer tables # Drop all tables Load the schema to ensure we don't have any newer tables
# hanging out from a failed upgrade # hanging out from a failed upgrade
progress.puts 'Cleaning the database ... '.color(:blue) puts_time 'Cleaning the database ... '.color(:blue)
Rake::Task['gitlab:db:drop_tables'].invoke Rake::Task['gitlab:db:drop_tables'].invoke
progress.puts 'done'.color(:green) puts_time 'done'.color(:green)
Rake::Task['gitlab:backup:db:restore'].invoke Rake::Task['gitlab:backup:db:restore'].invoke
rescue Gitlab::TaskAbortedByUserError rescue Gitlab::TaskAbortedByUserError
puts "Quitting...".color(:red) puts "Quitting...".color(:red)
...@@ -72,165 +72,169 @@ namespace :gitlab do ...@@ -72,165 +72,169 @@ namespace :gitlab do
namespace :repo do namespace :repo do
task create: :gitlab_environment do task create: :gitlab_environment do
progress.puts "Dumping repositories ...".color(:blue) puts_time "Dumping repositories ...".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("repositories") if ENV["SKIP"] && ENV["SKIP"].include?("repositories")
progress.puts "[SKIPPED]".color(:cyan) puts_time "[SKIPPED]".color(:cyan)
else else
Backup::Repository.new(progress).dump Backup::Repository.new(progress).dump
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
task restore: :gitlab_environment do task restore: :gitlab_environment do
progress.puts "Restoring repositories ...".color(:blue) puts_time "Restoring repositories ...".color(:blue)
Backup::Repository.new(progress).restore Backup::Repository.new(progress).restore
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
namespace :db do namespace :db do
task create: :gitlab_environment do task create: :gitlab_environment do
progress.puts "Dumping database ... ".color(:blue) puts_time "Dumping database ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("db") if ENV["SKIP"] && ENV["SKIP"].include?("db")
progress.puts "[SKIPPED]".color(:cyan) puts_time "[SKIPPED]".color(:cyan)
else else
Backup::Database.new(progress).dump Backup::Database.new(progress).dump
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
task restore: :gitlab_environment do task restore: :gitlab_environment do
progress.puts "Restoring database ... ".color(:blue) puts_time "Restoring database ... ".color(:blue)
Backup::Database.new(progress).restore Backup::Database.new(progress).restore
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
namespace :builds do namespace :builds do
task create: :gitlab_environment do task create: :gitlab_environment do
progress.puts "Dumping builds ... ".color(:blue) puts_time "Dumping builds ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("builds") if ENV["SKIP"] && ENV["SKIP"].include?("builds")
progress.puts "[SKIPPED]".color(:cyan) puts_time "[SKIPPED]".color(:cyan)
else else
Backup::Builds.new(progress).dump Backup::Builds.new(progress).dump
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
task restore: :gitlab_environment do task restore: :gitlab_environment do
progress.puts "Restoring builds ... ".color(:blue) puts_time "Restoring builds ... ".color(:blue)
Backup::Builds.new(progress).restore Backup::Builds.new(progress).restore
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
namespace :uploads do namespace :uploads do
task create: :gitlab_environment do task create: :gitlab_environment do
progress.puts "Dumping uploads ... ".color(:blue) puts_time "Dumping uploads ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("uploads") if ENV["SKIP"] && ENV["SKIP"].include?("uploads")
progress.puts "[SKIPPED]".color(:cyan) puts_time "[SKIPPED]".color(:cyan)
else else
Backup::Uploads.new(progress).dump Backup::Uploads.new(progress).dump
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
task restore: :gitlab_environment do task restore: :gitlab_environment do
progress.puts "Restoring uploads ... ".color(:blue) puts_time "Restoring uploads ... ".color(:blue)
Backup::Uploads.new(progress).restore Backup::Uploads.new(progress).restore
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
namespace :artifacts do namespace :artifacts do
task create: :gitlab_environment do task create: :gitlab_environment do
progress.puts "Dumping artifacts ... ".color(:blue) puts_time "Dumping artifacts ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("artifacts") if ENV["SKIP"] && ENV["SKIP"].include?("artifacts")
progress.puts "[SKIPPED]".color(:cyan) puts_time "[SKIPPED]".color(:cyan)
else else
Backup::Artifacts.new(progress).dump Backup::Artifacts.new(progress).dump
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
task restore: :gitlab_environment do task restore: :gitlab_environment do
progress.puts "Restoring artifacts ... ".color(:blue) puts_time "Restoring artifacts ... ".color(:blue)
Backup::Artifacts.new(progress).restore Backup::Artifacts.new(progress).restore
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
namespace :pages do namespace :pages do
task create: :gitlab_environment do task create: :gitlab_environment do
progress.puts "Dumping pages ... ".color(:blue) puts_time "Dumping pages ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("pages") if ENV["SKIP"] && ENV["SKIP"].include?("pages")
progress.puts "[SKIPPED]".color(:cyan) puts_time "[SKIPPED]".color(:cyan)
else else
Backup::Pages.new(progress).dump Backup::Pages.new(progress).dump
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
task restore: :gitlab_environment do task restore: :gitlab_environment do
progress.puts "Restoring pages ... ".color(:blue) puts_time "Restoring pages ... ".color(:blue)
Backup::Pages.new(progress).restore Backup::Pages.new(progress).restore
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
namespace :lfs do namespace :lfs do
task create: :gitlab_environment do task create: :gitlab_environment do
progress.puts "Dumping lfs objects ... ".color(:blue) puts_time "Dumping lfs objects ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("lfs") if ENV["SKIP"] && ENV["SKIP"].include?("lfs")
progress.puts "[SKIPPED]".color(:cyan) puts_time "[SKIPPED]".color(:cyan)
else else
Backup::Lfs.new(progress).dump Backup::Lfs.new(progress).dump
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
task restore: :gitlab_environment do task restore: :gitlab_environment do
progress.puts "Restoring lfs objects ... ".color(:blue) puts_time "Restoring lfs objects ... ".color(:blue)
Backup::Lfs.new(progress).restore Backup::Lfs.new(progress).restore
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
end end
namespace :registry do namespace :registry do
task create: :gitlab_environment do task create: :gitlab_environment do
progress.puts "Dumping container registry images ... ".color(:blue) puts_time "Dumping container registry images ... ".color(:blue)
if Gitlab.config.registry.enabled if Gitlab.config.registry.enabled
if ENV["SKIP"] && ENV["SKIP"].include?("registry") if ENV["SKIP"] && ENV["SKIP"].include?("registry")
progress.puts "[SKIPPED]".color(:cyan) puts_time "[SKIPPED]".color(:cyan)
else else
Backup::Registry.new(progress).dump Backup::Registry.new(progress).dump
progress.puts "done".color(:green) puts_time "done".color(:green)
end end
else else
progress.puts "[DISABLED]".color(:cyan) puts_time "[DISABLED]".color(:cyan)
end end
end end
task restore: :gitlab_environment do task restore: :gitlab_environment do
progress.puts "Restoring container registry images ... ".color(:blue) puts_time "Restoring container registry images ... ".color(:blue)
if Gitlab.config.registry.enabled if Gitlab.config.registry.enabled
Backup::Registry.new(progress).restore Backup::Registry.new(progress).restore
progress.puts "done".color(:green) puts_time "done".color(:green)
else else
progress.puts "[DISABLED]".color(:cyan) puts_time "[DISABLED]".color(:cyan)
end end
end end
end end
def puts_time(msg)
progress.puts "#{Time.now} -- #{msg}"
end
def progress def progress
if ENV['CRON'] if ENV['CRON']
# We need an object we can say 'puts' and 'print' to; let's use a # We need an object we can say 'puts' and 'print' to; let's use a
......
...@@ -71,7 +71,8 @@ describe 'gitlab:app namespace rake task' do ...@@ -71,7 +71,8 @@ describe 'gitlab:app namespace rake task' do
end.to raise_error(SystemExit) end.to raise_error(SystemExit)
end end
it 'invokes restoration on match' do context 'restore with matching gitlab version' do
before do
allow(YAML).to receive(:load_file) allow(YAML).to receive(:load_file)
.and_return({ gitlab_version: gitlab_version }) .and_return({ gitlab_version: gitlab_version })
expect(Rake::Task['gitlab:db:drop_tables']).to receive(:invoke) expect(Rake::Task['gitlab:db:drop_tables']).to receive(:invoke)
...@@ -84,8 +85,16 @@ describe 'gitlab:app namespace rake task' do ...@@ -84,8 +85,16 @@ describe 'gitlab:app namespace rake task' do
expect(Rake::Task['gitlab:backup:lfs:restore']).to receive(:invoke) expect(Rake::Task['gitlab:backup:lfs:restore']).to receive(:invoke)
expect(Rake::Task['gitlab:backup:registry:restore']).to receive(:invoke) expect(Rake::Task['gitlab:backup:registry:restore']).to receive(:invoke)
expect(Rake::Task['gitlab:shell:setup']).to receive(:invoke) expect(Rake::Task['gitlab:shell:setup']).to receive(:invoke)
end
it 'invokes restoration on match' do
expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout
end end
it 'prints timestamps on messages' do
expect { run_rake_task('gitlab:backup:restore') }.to output(/.*\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s[-+]\d{4}\s--\s.*/).to_stdout
end
end
end end
end # backup_restore task end # backup_restore task
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment