Commit d4cc660e authored by Efthymia Bika's avatar Efthymia Bika

Change default duplicity archive directory

parent db6394b8
......@@ -28,9 +28,11 @@ var TEMPLATES_FILE = 'templates.rc';
var BAAS_LOG_DIR = path.join(get_user_home(), BAAS_HOME_DIR, 'log');
var BAAS_CACHE_DIR = path.join(get_user_home(), BAAS_HOME_DIR, 'cache');
var BAAS_ARCHIVE_DIR = path.join(BAAS_CACHE_DIR, 'duplicity');
var RESTORE_DEFAULT_DIR = path.join(get_user_home(), "Downloads");
var running_processes = [];
var SHA256 = require("crypto-js/sha256");
var exec_path = path.dirname(process.execPath);
if(process.platform == 'darwin') {
......@@ -96,6 +98,9 @@ function create_conf_files() {
mkdirp(BAAS_CACHE_DIR, function(err) {
if(err) console.error(err);
});
mkdirp(BAAS_ARCHIVE_DIR, function(err) {
if(err) console.error(err);
});
}
function create_baas_dir() {
......
......@@ -230,12 +230,17 @@ function call_duplicity(mode, backup_set, force) {
log_file = get_unix_path(log_file);
}
args.push("--log-file", log_file);
if(backup_set) {
args.push("--ssl-cacert-file", clouds[backup_set.cloud].cert);
} else {
var res_cloud = $("#res-cloud").val();
args.push("--ssl-cacert-file", clouds[res_cloud].cert);
}
args.push("--archive-dir", BAAS_ARCHIVE_DIR);
var backup_name = (backup_set) ?
backup_set.cloud + "/" + backup_set.name :
$("#res-cloud").val() + "/" + $("#res-backup-name");
args.push("--name", SHA256(backup_name));
var cert = (backup_set) ? clouds[backup_set.cloud].cert :
clouds[$("#res-cloud").val()].cert;
args.push("--ssl-cacert-file", cert);
if(force) args.push("--force");
// call duplicity
......
......@@ -13,6 +13,7 @@
"license": "GPLv3",
"dependencies": {
"mkdirp": ""
"mkdirp": "",
"crypto-js": ""
}
}
......@@ -157,11 +157,15 @@ function get_contents_by_date(value) {
init_path = time_path;
}
var datapath = path.join(BAAS_CACHE_DIR, 'timeviews');
var cacert_file = " " + clouds[$("#cloud").val()].cert + " ";
var cacert_file = " " +
escape_quote_str(clouds[$("#cloud").val()].cert) + " ";
var archive_dir = " " + escape_quote_str(BAAS_ARCHIVE_DIR);
var backup_name = " " +
SHA256($("#backup_name").val() + "/" + $("#cloud").val());
var time_cmd = "python " + TIMEVIEW_PATH + " " + datapath + " swift://" +
container + cacert_file + " get " + value + " " +
escape_quote_str(time_path);
container + cacert_file + archive_dir + backup_name + " get "
+ value + " " + escape_quote_str(time_path);
if(process.platform == 'win32') {
var cmd = build_win_commands();
......
......@@ -19,6 +19,7 @@ import os
from subprocess import Popen, PIPE
import json
import errno
import hashlib
path_types = {'reg', 'dir', 'sym', 'fifo', 'sock', 'chr', 'blk'}
......@@ -79,11 +80,14 @@ def put_timepoint(config, timepoint, data):
f.write(json.dumps(root, indent=2))
def fetch_timepoint(config, timepoint, cacert_file):
def fetch_timepoint(config, timepoint):
curpath = os.path.dirname(os.path.realpath(__file__))
duplicity = os.path.join(curpath, 'duplicity')
args = [duplicity, 'list-current-files', '-t', timepoint,
'--ssl-cacert-file', cacert_file, config['target_url']]
'--ssl-cacert-file', config['cacert_file'],
'--archive-dir', config['archive_dir'],
'--name', config['backup_name'],
config['target_url']]
proc = Popen(args, stdout=PIPE, stderr=PIPE)
procout, procerr = proc.communicate()
......@@ -94,7 +98,7 @@ def fetch_timepoint(config, timepoint, cacert_file):
put_timepoint(config, timepoint, procout)
def get_timepoint(config, timepoint, path, cacert_file):
def get_timepoint(config, timepoint, path):
datafile = path_join(config['datapath'], timepoint)
retries = 1
while True:
......@@ -106,7 +110,7 @@ def get_timepoint(config, timepoint, path, cacert_file):
if e.errno != errno.ENOENT or retries == 0:
raise
fetch_timepoint(config, timepoint, cacert_file)
fetch_timepoint(config, timepoint)
if retries <= 0:
raise e
retries -= 1
......@@ -151,33 +155,37 @@ def get_config():
def main():
from sys import argv, stdin, stdout
def help():
print "Usage: %s <datapath> <target_url> <cacert_file> [get <absolute_timepoint> <path> | list]" % argv[0]
print "Usage: %s <datapath> <target_url> <cacert_file> <archive_dir> <backup_name> [get <absolute_timepoint> <path> | list]" % argv[0]
raise SystemExit(1)
if len(argv) < 5:
if len(argv) < 7:
help()
datapath = argv[1]
ensure_datapath(datapath)
target_url = argv[2]
cmd = argv[4]
cmd = argv[6]
if cmd not in ['get', 'list']:
help()
cacert_file = argv[3]
archive_dir = argv[4]
backup_name = hashlib.sha256(argv[5]).hexdigest()
#config = get_config()
config = {'datapath': datapath,
'target_url': target_url,
'cacert_file': cacert_file}
'cacert_file': cacert_file,
'archive_dir': archive_dir,
'backup_name': backup_name}
if cmd == 'get':
if len(argv) < 7:
if len(argv) < 9:
help()
timepoint = argv[5]
path = unicode(argv[6], encoding='UTF-8')
r = get_timepoint(config, timepoint, path, cacert_file)
timepoint = argv[7]
path = unicode(argv[8], encoding='UTF-8')
r = get_timepoint(config, timepoint, path)
print json.dumps(r, indent=2)
elif cmd == 'list':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment