]> git.openstreetmap.org Git - chef.git/commitdiff
Bring stateofthemap backup script under chef control
authorTom Hughes <tom@compton.nu>
Sun, 23 Jun 2013 18:26:05 +0000 (19:26 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 23 Jun 2013 18:26:05 +0000 (19:26 +0100)
cookbooks/stateofthemap/recipes/default.rb
cookbooks/stateofthemap/templates/default/backup.cron.erb [new file with mode: 0644]

index 49349a9fb31174667855022a7cff8c53bd808357..58258be933fb78aadf8bdb400ec2997b56bd8fa7 100644 (file)
@@ -228,3 +228,11 @@ end
 wordpress_plugin "wp-sticky" do
   site "2012.stateofthemap.org"
 end
 wordpress_plugin "wp-sticky" do
   site "2012.stateofthemap.org"
 end
+
+template "/etc/cron.daily/sotm-backup" do
+  source "backup.cron.erb"
+  owner "root"
+  group "root"
+  mode 0750
+  variable :passwords => passwords
+end
diff --git a/cookbooks/stateofthemap/templates/default/backup.cron.erb b/cookbooks/stateofthemap/templates/default/backup.cron.erb
new file mode 100644 (file)
index 0000000..45aafad
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# DO NOT EDIT - This file is being maintained by Chef
+
+T=$(mktemp -d -t -p /var/tmp sotm.XXXXXXXXXX)
+D=$(date +%Y-%m-%d)
+B=sotm-$D.tar.gz
+
+mkdir $T/sotm-$D
+
+<% 2007.upto(2012) do |year| -%>
+mysqldump --user=sotm<%= year %> --password=<%= @passwords["sotm#{year}"] %> --opt sotm<%= year %> > $T/sotm-$D/sotm<%= year %>.sql
+<% end -%>
+
+ln -s /srv/2007.stateofthemap.org $T/sotm-$D/www2007
+ln -s /srv/2008.stateofthemap.org $T/sotm-$D/www2008
+ln -s /srv/2009.stateofthemap.org $T/sotm-$D/www2009
+ln -s /srv/2010.stateofthemap.org $T/sotm-$D/www2010
+ln -s /srv/2011.stateofthemap.org $T/sotm-$D/www2011
+ln -s /srv/2012.stateofthemap.org $T/sotm-$D/www2012
+
+export GZIP="--rsyncable -9"
+
+nice tar --create --gzip --dereference --directory=$T --file=$T/$B sotm-$D
+nice nice $T/$B backup::backup
+
+rm -rf $T