Esempio n. 1
0
def validate(values, name, errors):

    backup=backups.Backup()
    
    # override persistant config with this one.
    backup.setRunCfg(values)
    
    if values.has_key(backups.PASSWORD_ATTR): 
        pw=values[backups.PASSWORD_ATTR]
    else: 
        pw=""

    rec=False
    if values.has_key(backups.COMMAND_ATTR) and len(values[backups.COMMAND_ATTR]): 
        if values[backups.COMMAND_ATTR]=="recover":
            rec=True
    if not rec: 
        rec=values[backups.RECOVER_ATTR]
        
    if not values[backups.ENABLED_ATTR] and not rec:
        return True;

    msg=backup.transport.validate(pw)
    if len(msg):
         errors[name]=msg
         return False
    return True
Esempio n. 2
0
def set(old, new):

    """ update backup settings
    """
    
    backup=backups.Backup();
    new_values=new[backups.myId]

    # save a cleaned up version of the set
    backup.writeCfg(cleanCfg("{%s}" % schema(), backups.myId, new_values));
        
    enabled     = new_values[backups.ENABLED_ATTR]
    
    if new_values[backups.RECOVER_ATTR]:
        return  backup.recovercmd()
            
    if old[backups.myId][backups.ENABLED_ATTR] != enabled:
        if enabled:
            return backup.startcmd()
        else:
            return backup.stopcmd()
    
    if new_values.has_key(backups.COMMAND_ATTR):
        cmd=new_values[backups.COMMAND_ATTR]
        if new_values.has_key(backups.PASSWORD_ATTR): 
            pw=new_values[backups.PASSWORD_ATTR]
        else: 
            pw=""
        if   cmd == "run" :     runcmd("/sbin/run-backups %s" % pw)
        elif cmd == "stop":     runcmd("/sbin/stop-backups")
        elif cmd == "test":     runcmd("/sbin/testBackups %s" % pw)

    return ""
Esempio n. 3
0
def runcmd(cmd):
    backup=backups.Backup();
    cmd="echo '%s 2>>%s 1>&2' | /usr/bin/at -qb now 1>/dev/null 2>&1" % (cmd, backups.logFile)
    backup.log("cmd=[%s]" % cmd)
    retCode=subprocess.call(cmd, shell=True)
    if retCode != 0:
        backup.log("'%s' failed with exit code %d" % (cmd, retCode))
Esempio n. 4
0
def get():
    """ 
       retrieve Backup settings 
       We simply read from the json back config file. 
    """
    result={}
    backup=backups.Backup();
    result=backup.getCfg()
    return result
Esempio n. 5
0
def get():
    """ 
       retrieve Backup settings 
       We simply read from the json back config file. 
    """
    result = {}
    backups.REC_LIST_ATTR,
    blist = []
    nlist = []
    backup = backups.Backup()
    try:
        blist = backup.getBackups()
    except:
        pass
    for entry in reversed(blist):
        if len(entry[16:]): nlist.append(entry[16:])
    result[backups.REC_LIST_ATTR] = nlist
    result[backups.REC_PREFIX_ATTR] = "backups"
    return result