Exemplo n.º 1
0
def restoreFileOrDir(repoRoot, dirPath, filename, restoreDate, useZip):
    """ returns a file path to the file.  User is responsible for deleting file, as well as containing dir, after use. """
    filePath = joinPaths(dirPath, filename)
    filePath = rdiffQuotedPath(repoRoot).getQuotedPath(filePath)
    checkRepoPath(repoRoot, filePath)

    restoredFilename = filename
    if restoredFilename == "/":
        restoredFilename = "(root)"

    fileToRestore = joinPaths(repoRoot, dirPath, filename)
    dateString = str(restoreDate.getSeconds())
    rdiffOutputFile = joinPaths(
        tempfile.mkdtemp(),
        restoredFilename)  # TODO: make so this includes the username
    results = rdw_helpers.execute("rdiff-backup",
                                  "--restore-as-of=" + dateString,
                                  fileToRestore, rdiffOutputFile)
    if results['exitCode'] != 0 or not os.access(rdiffOutputFile, os.F_OK):
        error = results['stderr']
        if not error:
            error = 'rdiff-backup claimed success, but did not restore anything. This indicates a bug in rdiffWeb. Please report this to a developer.'
        raise UnknownError('Unable to restore! rdiff-backup output:\n' + error)
    if os.path.isdir(rdiffOutputFile):
        if useZip:
            rdw_helpers.recursiveZipDir(rdiffOutputFile,
                                        rdiffOutputFile + ".zip")
            rdw_helpers.removeDir(rdiffOutputFile)
            rdiffOutputFile = rdiffOutputFile + ".zip"
        else:
            rdw_helpers.recursiveTarDir(rdiffOutputFile,
                                        rdiffOutputFile + ".tar.gz")
            rdw_helpers.removeDir(rdiffOutputFile)
            rdiffOutputFile = rdiffOutputFile + ".tar.gz"
    return rdiffOutputFile
Exemplo n.º 2
0
def restoreFileOrDir(repoRoot, dirPath, filename, restoreDate):
    """ returns a file path to the file.  User is responsible for deleting file, as well as containing dir, after use. """
    checkRepoPath(repoRoot, joinPaths(dirPath, filename))

    restoredFilename = filename
    if restoredFilename == "/":
        restoredFilename = "(root)"

    fileToRestore = joinPaths(repoRoot, dirPath, filename)
    dateString = str(restoreDate.getSeconds())
    rdiffOutputFile = joinPaths(
        tempfile.mkdtemp(),
        restoredFilename)  # TODO: make so this includes the username
    args = [
        "rdiff-backup", "--restore-as-of=" + dateString, fileToRestore,
        rdiffOutputFile
    ]
    os.spawnvp(os.P_WAIT, args[0], args)
    if not os.access(rdiffOutputFile, os.F_OK):
        raise UnknownError()
    if os.path.isdir(rdiffOutputFile):
        rdw_helpers.recursiveZipDir(rdiffOutputFile, rdiffOutputFile + ".zip")
        rdw_helpers.removeDir(rdiffOutputFile)
        rdiffOutputFile = rdiffOutputFile + ".zip"
    return rdiffOutputFile
Exemplo n.º 3
0
def restoreFileOrDir(repoRoot, dirPath, filename, restoreDate, useZip):
   """ returns a file path to the file.  User is responsible for deleting file, as well as containing dir, after use. """
   filePath = joinPaths(dirPath, filename)
   filePath = rdiffQuotedPath(repoRoot).getQuotedPath(filePath)
   checkRepoPath(repoRoot, filePath)

   restoredFilename = filename
   if restoredFilename == "/":
      restoredFilename = "(root)"

   fileToRestore = joinPaths(repoRoot, dirPath, filename)
   dateString = str(restoreDate.getSeconds())
   rdiffOutputFile = joinPaths(tempfile.mkdtemp(), restoredFilename) # TODO: make so this includes the username
   results = rdw_helpers.execute("rdiff-backup", "--restore-as-of="+dateString, fileToRestore, rdiffOutputFile)
   if results['exitCode'] != 0 or not os.access(rdiffOutputFile, os.F_OK):
      error = results['stderr']
      if not error:
         error = 'rdiff-backup claimed success, but did not restore anything. This indicates a bug in rdiffWeb. Please report this to a developer.'
      raise UnknownError('Unable to restore! rdiff-backup output:\n'+error)
   if os.path.isdir(rdiffOutputFile):
      if useZip:
         rdw_helpers.recursiveZipDir(rdiffOutputFile, rdiffOutputFile+".zip")
         rdw_helpers.removeDir(rdiffOutputFile)
         rdiffOutputFile = rdiffOutputFile+".zip"
      else:
         rdw_helpers.recursiveTarDir(rdiffOutputFile, rdiffOutputFile+".tar.gz")
         rdw_helpers.removeDir(rdiffOutputFile)
         rdiffOutputFile = rdiffOutputFile+".tar.gz"
   return rdiffOutputFile
Exemplo n.º 4
0
def restoreFileOrDir(repoRoot, dirPath, filename, restoreDate):
   """ returns a file path to the file.  User is responsible for deleting file, as well as containing dir, after use. """
   checkRepoPath(repoRoot, joinPaths(dirPath, filename))

   restoredFilename = filename
   if restoredFilename == "/":
      restoredFilename = "(root)"

   fileToRestore = joinPaths(repoRoot, dirPath, filename)
   dateString = str(restoreDate.getSeconds())
   rdiffOutputFile = joinPaths(tempfile.mkdtemp(), restoredFilename) # TODO: make so this includes the username
   args = [ "rdiff-backup", "--restore-as-of="+dateString, fileToRestore, rdiffOutputFile ]
   os.spawnvp(os.P_WAIT, args[0], args)
   if not os.access(rdiffOutputFile, os.F_OK):
      raise UnknownError()
   if os.path.isdir(rdiffOutputFile):
      rdw_helpers.recursiveZipDir(rdiffOutputFile, rdiffOutputFile+".zip")
      rdw_helpers.removeDir(rdiffOutputFile)
      rdiffOutputFile = rdiffOutputFile+".zip"
   return rdiffOutputFile