Bring thinkup backup script under chef control
authorTom Hughes <tom@compton.nu>
Sun, 23 Jun 2013 18:38:42 +0000 (19:38 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 23 Jun 2013 18:39:53 +0000 (19:39 +0100)
cookbooks/thinkup/recipes/default.rb
cookbooks/thinkup/templates/default/backup.cron.erb [new file with mode: 0644]

index ab85e64..09b49db 100644 (file)
@@ -114,3 +114,11 @@ template "/etc/cron.d/thinkup" do
   group "root"
   mode "0644"
 end
+
+template "/etc/cron.daily/thinkup-backup" do
+  source "backup.cron.erb"
+  owner "root"
+  group "root"
+  mode 0750
+  variable :passwords => passwords
+end
diff --git a/cookbooks/thinkup/templates/default/backup.cron.erb b/cookbooks/thinkup/templates/default/backup.cron.erb
new file mode 100644 (file)
index 0000000..b5b6c75
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# DO NOT EDIT - This file is being maintained by Chef
+
+T=$(mktemp -d -t -p /var/tmp thinkup.XXXXXXXXXX)
+D=$(date +%Y-%m-%d)
+B=thinkup-$D.tar.gz
+
+mkdir $T/thinkup-$D
+mysqldump --user=thinkup --password=<% @passwords["database"] %> --opt thinkup > $T/thinkup-$D/thinkup.sql
+ln -s /srv/thinkup.openstreetmap.org $T/thinkup-$D/www
+
+export GZIP="--rsyncable -9"
+
+nice tar --create --gzip --dereference --directory=$T --file=$T/$B thinkup-$D
+nice rsync $T/$B backup::backup
+
+rm -rf $T