summaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
authorMathieu Bornoz <mathieu.bornoz@camptocamp.com>2010-11-12 16:04:49 +0100
committerMathieu Bornoz <mathieu.bornoz@camptocamp.com>2010-11-12 16:06:42 +0100
commitffab59de517086a3dc6372e5ec01fc789539030e (patch)
tree0a73e4962221f11178b95516f100d3187047c166 /templates
initial import of couchdb module
Diffstat (limited to 'templates')
-rw-r--r--templates/couchdb-backup.py.erb32
1 files changed, 32 insertions, 0 deletions
diff --git a/templates/couchdb-backup.py.erb b/templates/couchdb-backup.py.erb
new file mode 100644
index 0000000..4fa311f
--- /dev/null
+++ b/templates/couchdb-backup.py.erb
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+# file manage by puppet
+
+import os
+import gzip
+import tarfile
+import datetime
+import urllib2
+import simplejson
+import couchdb.tools.dump
+from os.path import join
+
+DB_URL="http://<%= bind_address %>:<%= port %>"
+DUMP_DIR="<%= backupdir %>"
+TODAY=datetime.datetime.today().strftime("%A").lower()
+
+ftar = os.path.join(DUMP_DIR,"%s.tar" % TODAY)
+tmp_ftar = os.path.join(DUMP_DIR,"_%s.tar" % TODAY)
+tar = tarfile.open(tmp_ftar, "w")
+
+databases = simplejson.load(urllib2.urlopen("%s/_all_dbs" % DB_URL))
+
+for db in databases:
+ db_file = os.path.join(DUMP_DIR,"%s.gz" % db)
+ f = gzip.open(db_file, 'wb')
+ couchdb.tools.dump.dump_db(os.path.join(DB_URL,db), output=f)
+ f.close()
+ tar.add(db_file,"%s.gz" % db)
+ os.remove(db_file)
+
+tar.close()
+os.rename(tmp_ftar,ftar)