Permalink
Browse files

add backup_sqlite and README

  • Loading branch information...
1 parent e50ec34 commit f5fa4805fddf5df95fad6f0b776d6f2358a11279 @saigon committed Dec 3, 2010
Showing with 37 additions and 0 deletions.
  1. +37 −0 backup_sqlite.py
View
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+import sys
+import os
+
+if len(sys.argv) < 3:
+ sys.exit('Usage: backup_sqlite.py [bucket name with path]' +
+ ' [destination path] \n')
+
+def backup(sqlite_path, srcdir, destdir, fn):
+ os.system(sqlite_path + ' ' + os.path.join(srcdir, fn) +
+ " '.backup " + os.path.join(destdir, fn) + " ' ")
+ print "Backup of %s done" % fn
+ os.system(sqlite_path + ' ' + os.path.join(destdir, fn) + ' vacuum')
+ print "Vacuum of %s done" % fn
+
+def find_sqlite():
+ candidates = ['/opt/membase/bin/ep_engine/management/sqlite3',
+ r'c:\Program Files\Membase\Server\bin\ep_engine\management\sqlite3']
+ for c in candidates:
+ if os.path.exists(c):
+ return c
+ sys.exit("ERROR: Cannot find sqlite3 command.")
+
+src_path, dest_path = sys.argv[1:]
+sqlite_path = find_sqlite()
+
+for n,p in [('src', src_path), ('dest', dest_path)]:
+ if not os.path.exists(p):
+ sys.exit("ERROR: %s does not exist at %s" % (n, p))
+
+dirname, bucket_name = os.path.split(src_path)
+
+backup(sqlite_path, dirname, dest_path, bucket_name)
+for i in range(4):
+ backup(sqlite_path, dirname, dest_path, '%s-%d.sqlite' % (bucket_name, i))
+

0 comments on commit f5fa480

Please sign in to comment.