Example #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
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
def removeRepoHistory(repo, afterDate):
   """ Removes all history for repo after afterDate using --remove-older-than. """
   dateString = str(afterDate.getSeconds())
   if backupIsInProgressForRepo(repo):
      raise UnknownError('A backup is currently in progress to this location. '+
                         'Please allow this backup to complete before removing history.')
   results = rdw_helpers.execute('rdiff-backup', '--force', '--remove-older-than', dateString, repo)
   if results['exitCode'] != 0:
      error = results['stderr']
      raise UnknownError('Unable to delete history! rdiff-backup output:\n'+error)
Example #4
0
def removeRepoHistory(repo, afterDate):
    """ Removes all history for repo after afterDate using --remove-older-than. """
    dateString = str(afterDate.getSeconds())
    if backupIsInProgressForRepo(repo):
        raise UnknownError(
            'A backup is currently in progress to this location. ' +
            'Please allow this backup to complete before removing history.')
    results = rdw_helpers.execute('rdiff-backup', '--force',
                                  '--remove-older-than', dateString, repo)
    if results['exitCode'] != 0:
        error = results['stderr']
        raise UnknownError('Unable to delete history! rdiff-backup output:\n' +
                           error)
Example #5
0
def restoreFileOrDir(repoRoot, dirPath, filename, restoreDate, useZip):
    """This function is used to restore a directory tree or a file from the
      given respository. Users may specified the restore date and the
      archive format."""

    # Format the specified file name / repository path for validation
    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

    # Use rdiff-backup executable to restore the data into a specified location
    results = rdw_helpers.execute("rdiff-backup",
                                  "--restore-as-of=" + dateString,
                                  fileToRestore, rdiffOutputFile)

    # Check the result
    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)

    # The path restored is a directory and need to be archived using zip or tar
    if os.path.isdir(rdiffOutputFile):
        rdiffOutputDirectory = rdiffOutputFile
        try:
            if useZip:
                rdiffOutputFile = rdiffOutputFile + ZIP_SUFFIX
                _recursiveZipDir(rdiffOutputDirectory, rdiffOutputFile)
            else:
                rdiffOutputFile = rdiffOutputFile + TARGZ_SUFFIX
                _recursiveTarDir(rdiffOutputDirectory, rdiffOutputFile)
        finally:
            rdw_helpers.removeDir(rdiffOutputDirectory)

    return rdiffOutputFile
Example #6
0
def restoreFileOrDir(repoRoot, dirPath, filename, restoreDate, useZip):
   """This function is used to restore a directory tree or a file from the
      given respository. Users may specified the restore date and the
      archive format."""
   
   # Format the specified file name / repository path for validation
   dirPath = dirPath.encode('utf-8')
   filename = filename.encode('utf-8')
   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
   
   # Use rdiff-backup executable to restore the data into a specified location
   results = rdw_helpers.execute("rdiff-backup", "--restore-as-of=" + dateString, fileToRestore, rdiffOutputFile)
   
   # Check the result
   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)

   
   # The path restored is a directory and need to be archived using zip or tar
   if os.path.isdir(rdiffOutputFile):
      rdiffOutputDirectory = rdiffOutputFile
      try:
         if useZip:
            rdiffOutputFile = rdiffOutputFile + ZIP_SUFFIX
            _recursiveZipDir(rdiffOutputDirectory, rdiffOutputFile)
         else:
            rdiffOutputFile = rdiffOutputFile + TARGZ_SUFFIX
            _recursiveTarDir(rdiffOutputDirectory, rdiffOutputFile)
      finally:
         rdw_helpers.removeDir(rdiffOutputDirectory)
         
   return rdiffOutputFile