From: Tom Hughes Date: Fri, 12 Jul 2013 07:45:47 +0000 (+0100) Subject: Add chef server backup scripts X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/f1fcd97392a104350c03f6b8618d7f2c7f52fffe Add chef server backup scripts --- diff --git a/cookbooks/chef/recipes/repository.rb b/cookbooks/chef/recipes/repository.rb index b4bd2fa06..09713b4be 100644 --- a/cookbooks/chef/recipes/repository.rb +++ b/cookbooks/chef/recipes/repository.rb @@ -61,3 +61,10 @@ template "#{node[:chef][:repository]}/hooks/post-receive" do group "chefrepo" mode 0750 end + +template "/etc/cron.daily/chef-repository-backup" do + source "repository-backup.cron.erb" + owner "root" + group "root" + mode 0755 +end diff --git a/cookbooks/chef/recipes/server.rb b/cookbooks/chef/recipes/server.rb index 2c33218c5..e6fed2151 100644 --- a/cookbooks/chef/recipes/server.rb +++ b/cookbooks/chef/recipes/server.rb @@ -46,3 +46,10 @@ end apache_site "chef.openstreetmap.org" do template "apache.erb" end + +template "/etc/cron.daily/chef-server-backup" do + source "server-backup.cron.erb" + owner "root" + group "root" + mode 0755 +end diff --git a/cookbooks/chef/templates/default/repository-backup.cron.erb b/cookbooks/chef/templates/default/repository-backup.cron.erb new file mode 100644 index 000000000..2e55f0575 --- /dev/null +++ b/cookbooks/chef/templates/default/repository-backup.cron.erb @@ -0,0 +1,14 @@ +#!/bin/sh + +T=$(mktemp -d -t -p /var/tmp chef-repository.XXXXXXXXXX) +D=$(date +%Y-%m-%d) +B=chef-repository-$D.tar.gz + +ln -s /var/lib/git/chef.git $T/chef-repository-$D + +export GZIP="--rsyncable -9" + +nice tar --create --gzip --dereference --directory=$T --file=$T/$B chef-repository-$D +nice rsync $T/$B backup::backup + +rm -rf $T diff --git a/cookbooks/chef/templates/default/server-backup.cron.erb b/cookbooks/chef/templates/default/server-backup.cron.erb new file mode 100644 index 000000000..3b7e953e7 --- /dev/null +++ b/cookbooks/chef/templates/default/server-backup.cron.erb @@ -0,0 +1,18 @@ +#!/bin/sh + +T=$(mktemp -d -t -p /var/tmp chef-server.XXXXXXXXXX) +D=$(date +%Y-%m-%d) +B=chef-server-$D.tar.gz + +mkdir $T/chef-server-$D +chgrp opscode-pgsql $T $T/chef-server-$D +chmod g+rwx $T $T/chef-server-$D +sudo -u opscode-pgsql /opt/chef-server/embedded/bin/pg_dump --file=$T/chef-server-$D/chef.dmp --clean opscode_chef +ln -s /var/opt/chef-server/bookshelf/data $T/chef-server-$D/bookshelf + +export GZIP="--rsyncable -9" + +nice tar --create --gzip --dereference --directory=$T --file=$T/$B chef-server-$D +nice rsync $T/$B backup::backup + +rm -rf $T