Skip to content

Commit

Permalink
make archive
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsai1993 committed Aug 24, 2020
1 parent 9a7902d commit c15469e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dump
*?deploy.sh
j*b/
ga.png
*.tar*
21 changes: 16 additions & 5 deletions aql.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,36 @@ def request(self, method, endp, raise_error=True, **kw):
def __init__(self, dburl, dbname, collections):
self.dburl = dburl
self.dbname = dbname
self.collections = collections
self.prepared = False

# create database if nonexistent
self.request('post','/_api/database', name=dbname, raise_error=False)
def prepare(self):
if not self.prepared:
# create database if nonexistent
self.request('post','/_api/database', name=self.dbname, raise_error=False)

self.prepared = True
# create collections if nonexistent
for c in self.collections:
self.create_collection(c)

# create collections if nonexistent
for c in collections:
self.create_collection(c)

def create_collection(self, name):
self.prepare()
return self.request('POST', '/_db/'+self.dbname+'/_api/collection',
name=name, waitForSync=True, raise_error=False)

def clear_collection(self, name, filter=''):
self.prepare()
return self.aql('for i in {} {} remove i in {}'.format(
name, filter, name))

def create_index(self, collection, **kw):
self.prepare()
return self.request('post', '/_db/'+self.dbname+'/_api/index?collection='+collection, raise_error=False, **kw)

def aql(self, query, silent=False, **kw):
self.prepare()
if not silent: print_up('AQL >>',query,kw)
resp = self.request(
'POST', '/_db/'+self.dbname+'/_api/cursor',
Expand All @@ -57,6 +67,7 @@ def aql(self, query, silent=False, **kw):
return res

def from_filter(self, _from, _filter, **kw):
self.prepare()
return self.aql('for i in {} filter {} return i'.format(_from, _filter), **kw)

if __name__ == '__main__':
Expand Down
26 changes: 26 additions & 0 deletions make_archive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import shutil, os, tarfile
from commons import *

dir = os.path.abspath('./dump/')

basename = '2047backup_'+time_iso_now().replace(':','').replace('-','')
basename_p = basename.replace('backup_', 'backup_publish_')

print('working on', dir)

# https://stackoverflow.com/a/38883728
tar = tarfile.open(basename+'.tar',"w")
tar.add('dump')
tar.close()

def accept(fn):
nope = 'conversations histories messages logs passwords invitations'.split(' ')
# for obvious reasons
for k in nope:
if k in fn:
return False
return True

tar = tarfile.open(basename_p+'.tar',"w")
tar.add('dump', filter=lambda x: x if accept(x.name) else None)
tar.close()

0 comments on commit c15469e

Please sign in to comment.