Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorwjan <wim.jansen@gmail.com>2018-02-23 00:03:37 +0300
committerwjan <wim.jansen@gmail.com>2018-02-23 00:03:37 +0300
commitb74ee4683a363e1979c287a8a5b6d006bd7796b8 (patch)
tree9303196f3c8baf62a8d9b43e9f660aad65a76948 /Tools
parente5995f43c57e0258328a474a0c9a3069bf91069c (diff)
uses config file and corrects the zip archive creation
Diffstat (limited to 'Tools')
-rw-r--r--Tools/Commandline/ReEncrypt/ReEncrypt.py49
-rw-r--r--Tools/Commandline/ReEncrypt/Readme11
-rw-r--r--Tools/Commandline/ReEncrypt/config.txt (renamed from Tools/Commandline/ReEncrypt/data.txt)8
3 files changed, 54 insertions, 14 deletions
diff --git a/Tools/Commandline/ReEncrypt/ReEncrypt.py b/Tools/Commandline/ReEncrypt/ReEncrypt.py
index f5fb0980c..389abf9a3 100644
--- a/Tools/Commandline/ReEncrypt/ReEncrypt.py
+++ b/Tools/Commandline/ReEncrypt/ReEncrypt.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-## Copyright (C) 2017, The Duplicati Team
+## Copyright (C) 2018, The Duplicati Team
## http://www.duplicati.com, info@duplicati.com
##
## This library is free software; you can redistribute it and/or modify
@@ -17,7 +17,7 @@
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
-import sys
+import sys, getopt
import io
import json
import zipfile
@@ -68,7 +68,7 @@ def mainReEncrypt(options):
actual_volumesize=os.stat(os.path.join(options['orig']['path'],dblock)).st_size
print('dblock: %s expected_hash: %s calc_hash: %s exact: %s' % (dblock,expected_hash.decode('utf8'),actual_hash.decode('utf8'),expected_hash==actual_hash))
- with NamedTemporaryFile(delete=False) as temp_dblock:
+ with NamedTemporaryFile() as temp_dblock:
dblock_enc_fullpath = os.path.join(options['orig']['path'],dblock)
dblock_reenc_fullpath = os.path.join(options['new']['path'],change_ext(dblock,options['orig']['extension'],options['new']['extension']))
decrypt(options['orig'],dblock_enc_fullpath,options['orig']['passwd'],temp_dblock.name)
@@ -115,12 +115,23 @@ def encrypt(options,decrypted, passw, encrypted):
if options['encryption']=='none':
shutil.copy(decrypted,encrypted)
+def emptydir(top):
+ if(top == '/' or top == "\\"): return
+ else:
+ for root, dirs, files in os.walk(top, topdown=False):
+ for name in files:
+ os.remove(os.path.join(root, name))
+ for name in dirs:
+ os.rmdir(os.path.join(root, name))
+
def unzip(archive, path):
+ emptydir(path)
with zipfile.ZipFile(archive.name) as zf:
zf.extractall(path)
def make_zipfile(output_filename, source_dir):
- print('zipping: %s to %s' % (source_dir, output_filename))
+ print('zipping: %s to %s' % (source_dir, output_filename))
+ emptydir(output_filename)
relroot=source_dir
with zipfile.ZipFile(output_filename, "w", zipfile.ZIP_DEFLATED) as zip:
for root, dirs, files in os.walk(source_dir):
@@ -158,12 +169,30 @@ def computeHash(path):
hasher.update(buffer)
return base64.b64encode(hasher.digest())
-def main():
- with open('data.txt') as infile:
+def main(argv):
+ configfile = ''
+ try:
+ opts, args = getopt.getopt(argv,"hc:")
+ except getopt.GetoptError:
+ print('ReEncrypt.py -c <configfile>')
+ sys.exit(2)
+ for opt, arg in opts:
+ if opt == '-h':
+ print('ReEncrypt.py -c <configfile>')
+ sys.exit(2)
+ elif opt == '-c':
+ configfile = arg
+ else:
+ print( "unhandled option")
+ if (configfile == ''):
+ print('ReEncrypt.py -c <configfile>')
+ sys.exit(2)
+
+ with open(configfile) as infile:
options = json.load(infile)
-
- mainReEncrypt(options)
+ mainReEncrypt(options)
print('Complete.')
-if __name__ == '__main__':
- main()
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/Tools/Commandline/ReEncrypt/Readme b/Tools/Commandline/ReEncrypt/Readme
new file mode 100644
index 000000000..a7d9301a0
--- /dev/null
+++ b/Tools/Commandline/ReEncrypt/Readme
@@ -0,0 +1,11 @@
+
+A Python script to change the encryption from Duplicati. You can go from aes to gpg or vice versa. It is also possible to remove encryption.
+
+Usage:
+1) Confirm that your Duplicati data is on disk in .zip or .zip.aes or .zip.gpg format..
+
+2) Install Python 3 if it is not already installed. pyAesCrypt and gnupg packages need to be installed in python as well.
+
+3) Prepare a config file (example config.txt).
+
+3) Run ReEncrypt.py -c config.txt.
diff --git a/Tools/Commandline/ReEncrypt/data.txt b/Tools/Commandline/ReEncrypt/config.txt
index 1987c0f46..b0b2d4679 100644
--- a/Tools/Commandline/ReEncrypt/data.txt
+++ b/Tools/Commandline/ReEncrypt/config.txt
@@ -1,16 +1,16 @@
{
"orig": {
"extension": "zip.aes",
- "path": "/mnt/c/Duplicati/test_aes",
+ "path": "/path/to/backup/orig",
"passwd": "123456",
"encryption": "aes"
},
"new": {
"recipients": ["user@host.com"],
- "extension": "zip.aes",
- "path": "/mnt/c/Duplicati/test_de",
+ "extension": "zip.gpg",
+ "path": "/path/to/backup/new",
"passwd": "654321",
- "encryption": "aes"
+ "encryption": "gpg"
},
"verify_hash": true
} \ No newline at end of file