Commit 319ec206 authored by Bazoud's avatar Bazoud Committed by Olivier Bazoud

Configure cron to make backups

parent fbed3cee
......@@ -238,3 +238,12 @@ default['gitlab']['monitrc']['notify_email'] = nil
# Some events may warrant extra notifcations, e.g. to a pager notification service
default['gitlab']['monitrc']['emergency_email'] = nil
default['gitlab']['monitrc']['emergency_events'] = ['timeout']
# backups
default['gitlab']['backup']['cron']['action'] = :create
default['gitlab']['backup']['cron']['minute'] = 0
default['gitlab']['backup']['cron']['hour'] = 2
default['gitlab']['backup']['cron']['mailto'] = 'gitlab@localhost'
default['gitlab']['backup']['cron']['path'] = '/usr/local/bin:/usr/bin:/bin'
default['gitlab']['backup']['backup_keep_time'] = 0
default['gitlab']['backup']['backup_path'] = 'tmp/backups'
# -*- mode: ruby; coding: utf-8; -*-
#
# Cookbook Name:: gitlab
# Recipe:: backup
#
gitlab = node['gitlab']
if gitlab['env'] == 'production'
cron 'gitlab_backups' do
action node['gitlab']['backup']['cron']['action']
minute node['gitlab']['backup']['cron']['minute']
hour node['gitlab']['backup']['cron']['hour']
user node['gitlab']['user']
mailto node['gitlab']['backup']['cron']['mailto']
path node['gitlab']['backup']['cron']['path']
command "cd #{gitlab['home']}/gitlab && bundle exec rake gitlab:backup:create RAILS_ENV=#{gitlab['env']}"
end
end
......@@ -32,6 +32,7 @@ template File.join(gitlab['path'], 'config', 'gitlab.yml') do
:gravatar => gitlab['gravatar'],
:ldap_config => gitlab['ldap'],
:ssh_port => gitlab['ssh_port'],
:backup => gitlab['backup'],
})
notifies :run, "bash[git config]", :immediately
notifies :reload, "service[gitlab]"
......
# -*- mode: ruby; coding: utf-8; -*-
require 'spec_helper'
describe "gitlab::backup" do
let(:chef_run) { ChefSpec::Runner.new.converge("gitlab::backup") }
describe "under ubuntu" do
["12.04", "10.04"].each do |version|
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::backup")
end
it "creates a cron" do
expect(chef_run).to create_cron('gitlab_backups').with(
minute: '0',
hour: '2',
user: 'git',
mailto: 'gitlab@localhost',
path: '/usr/local/bin:/usr/bin:/bin')
end
describe "when in development environment" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "development"
runner.converge("gitlab::backup")
end
it "do not create a cron" do
expect(chef_run).to_not create_cron('gitlab_backups')
end
end
end
end
describe "under centos" do
["5.8", "6.4"].each do |version|
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::backup")
end
it "creates a cron" do
expect(chef_run).to create_cron('gitlab_backups').with(
minute: '0',
hour: '2',
user: 'git',
mailto: 'gitlab@localhost',
path: '/usr/local/bin:/usr/bin:/bin')
end
describe "when in development environment" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "development"
runner.converge("gitlab::backup")
end
it "do not create a cron" do
expect(chef_run).to_not create_cron('gitlab_backups')
end
end
end
end
end
......@@ -52,7 +52,18 @@ describe "gitlab::install" do
"bind_dn"=>"_the_full_dn_of_the_user_you_will_bind_with",
"password"=>"_the_password_of_the_bind_user",
"allow_username_or_email_login"=>true
}
},
backup: {
"cron"=>{
"action"=>:create,
"minute"=>0,
"hour"=>2,
"mailto"=>"gitlab@localhost",
"path"=>"/usr/local/bin:/usr/bin:/bin"
},
"backup_keep_time"=>0,
"backup_path"=>"tmp/backups"
}
}
)
end
......@@ -463,7 +474,18 @@ describe "gitlab::install" do
"bind_dn"=>"_the_full_dn_of_the_user_you_will_bind_with",
"password"=>"_the_password_of_the_bind_user",
"allow_username_or_email_login"=>true
}
},
backup: {
"cron"=>{
"action"=>:create,
"minute"=>0,
"hour"=>2,
"mailto"=>"gitlab@localhost",
"path"=>"/usr/local/bin:/usr/bin:/bin"
},
"backup_keep_time"=>0,
"backup_path"=>"tmp/backups"
}
}
)
end
......
......@@ -193,8 +193,8 @@ production: &base
## Backup settings
backup:
path: "tmp/backups" # Relative paths are relative to Rails.root (default: tmp/backups/)
# keep_time: 604800 # default: 0 (forever) (in seconds)
path: "<%= @backup["backup_path"] %>" # Relative paths are relative to Rails.root (default: tmp/backups/)
keep_time: <%= @backup["backup_keep_time"] %> # default: 0 (forever) (in seconds)
## GitLab Shell settings
gitlab_shell:
......
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