-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup_sqlite.py
More file actions
executable file
·37 lines (28 loc) · 1.18 KB
/
backup_sqlite.py
File metadata and controls
executable file
·37 lines (28 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/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))