Skip to content

Instantly share code, notes, and snippets.

@hyoshida
Last active February 16, 2016 03:08
Show Gist options
  • Save hyoshida/647883db9a2941450fed to your computer and use it in GitHub Desktop.
Save hyoshida/647883db9a2941450fed to your computer and use it in GitHub Desktop.
Buckup/Restore GitLab without tar packaging
# original: https://github.com/gitlabhq/gitlabhq/blob/7-10-stable/lib/tasks/gitlab/backup.rake
require 'active_record/fixtures'
namespace :gitlab do
namespace :backup_without_pack do
# Create backup of GitLab system
desc "GITLAB | Create a backup of the GitLab system"
task create: :environment do
warn_user_is_not_gitlab
configure_cron_mode
create_backup_information_yml
Rake::Task["gitlab:backup:db:create"].invoke
Rake::Task["gitlab:backup:repo:create"].invoke
Rake::Task["gitlab:backup:uploads:create"].invoke
end
# Restore backup of GitLab system
desc "GITLAB | Restore a previously created backup"
task restore: :environment do
warn_user_is_not_gitlab
configure_cron_mode
Dir.chdir(Gitlab.config.backup.path) do
backup = Backup::Manager.new
Rake::Task["gitlab:backup:db:restore"].invoke unless backup.skipped?("db")
Rake::Task["gitlab:backup:repo:restore"].invoke unless backup.skipped?("repositories")
Rake::Task["gitlab:backup:uploads:restore"].invoke unless backup.skipped?("uploads")
Rake::Task["gitlab:shell:setup"].invoke
end
end
def create_backup_information_yml
# Make sure there is a connection
ActiveRecord::Base.connection.reconnect!
# saving additional informations
s = {}
s[:db_version] = "#{ActiveRecord::Migrator.current_version}"
s[:backup_created_at] = Time.now
s[:gitlab_version] = Gitlab::VERSION
s[:skipped] = ENV["SKIP"]
Dir.chdir(Gitlab.config.backup.path) do
File.open("#{Gitlab.config.backup.path}/backup_information.yml", "w+") do |file|
file << s.to_yaml.gsub(/^---\n/,'')
end
end
end
end # namespace end: backup
end # namespace end: gitlab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment