]> git.openstreetmap.org Git - chef.git/commitdiff
Add chef server backup scripts
authorTom Hughes <tom@compton.nu>
Fri, 12 Jul 2013 07:45:47 +0000 (08:45 +0100)
committerTom Hughes <tom@compton.nu>
Fri, 12 Jul 2013 07:50:17 +0000 (08:50 +0100)
cookbooks/chef/recipes/repository.rb
cookbooks/chef/recipes/server.rb
cookbooks/chef/templates/default/repository-backup.cron.erb [new file with mode: 0644]
cookbooks/chef/templates/default/server-backup.cron.erb [new file with mode: 0644]

index b4bd2fa069780306002aa75fb84a604fcf2d3fb0..09713b4be1e0d874c38b1861fa05b5189dd26b97 100644 (file)
@@ -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
index 2c33218c59db40b97d5a39e31b851e4721cc70cf..e6fed21510f43bf956c594ab532a4482abc24220 100644 (file)
@@ -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 (file)
index 0000000..2e55f05
--- /dev/null
@@ -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 (file)
index 0000000..3b7e953
--- /dev/null
@@ -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