You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
#!/usr/bin/python
|
|
from backup import hashify
|
|
import argparse
|
|
import datetime
|
|
import time
|
|
import shutil
|
|
import os
|
|
import sqlite3
|
|
def create_temp():
|
|
name= 'fsb{}'.format(datetime.datetime.today())
|
|
os.mkdir(name)
|
|
return name
|
|
def lookup(cur,imohash,realhash=None):
|
|
if realhash is not None:
|
|
cur.execute('SELECT path FROM paths where blake=?',[realhash])
|
|
else:
|
|
cur.execute('SELECT path FROM paths where imohash=?',[imohash])
|
|
res = cur.fetchone()
|
|
if len(res) == 1:
|
|
return res[0]
|
|
def restore(database,source,destination):
|
|
con=sqlite3.connect(database)
|
|
cur=con.cursor()
|
|
temp = create_temp()
|
|
hashes = hashify(source)
|
|
for path,imohash,realhash in hashes:
|
|
ppath = os.path.join(source,path)
|
|
qpath=lookup(cur,imohash,realhash)
|
|
qpath=os.path.join(temp,qpth)
|
|
parent = os.path.dirname(qpath)
|
|
if not os.path.exists(parent):
|
|
os.makedirs(parent)
|
|
shutil.move(ppath,qpath)
|
|
shutil.move(temp,dest)
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('database')
|
|
parser.add_argument('src')
|
|
parser.add_argument('dst',default = None,nargs='?')
|
|
args = parser.parse_args()
|
|
if args.dst is None:
|
|
args.dst=args.src
|
|
restore(args.database,args.src,args.dst)
|