Class BackupRestoreFilesystemManager


  • public class BackupRestoreFilesystemManager
    extends Object
    • Constructor Detail

      • BackupRestoreFilesystemManager

        public BackupRestoreFilesystemManager​(com.atlassian.dc.filestore.api.compat.FilesystemPath confluenceHome,
                                              com.atlassian.dc.filestore.api.compat.FilesystemPath localHome)
    • Method Detail

      • getFiles

        public List<FileInfo> getFiles​(JobScope jobScope)
        Gets list of FileInfo objects containing the information of files present in the site or space restore folder
        Parameters:
        jobScope - JobScope.SITE or JobScope.SPACE, the scope to get a FileInfo List from
        Returns:
        List of FileInfo objects
      • writeFileLocally

        public com.atlassian.dc.filestore.api.compat.FilesystemPath writeFileLocally​(JobScope jobScope,
                                                                                     String fileName,
                                                                                     Supplier<InputStream> inputStreamSupplier)
                                                                              throws IOException
        Writes a local file with a given name and given InputStream based on the JobScope. If the file is already present in the restore working directory, it is written with a file with new name that is original filename with timestamp suffix (format : yyyy-MM-dd-HH-mm-ss-SSS). New file name is [Original File Name w/o extension]_copy_[Timestamp].[Original File extension]
        Parameters:
        jobScope - JobScope
        fileName - Name of the file
        inputStreamSupplier - Supplier of the InputStream ( File contents)
        Throws:
        IOException
      • getRestoreWorkingDir

        public String getRestoreWorkingDir​(JobScope jobScope)
        Returns restore working directory based on the JobScope
        Parameters:
        jobScope - JobScope
        Returns:
        String Working directory based on JobScope
        Throws:
        IllegalStateException - If JobScope is not either SITE/SPACE
      • isValidFilename

        public boolean isValidFilename​(String filename)
        Returns if a file name is a valid file name for restore
        Parameters:
        filename - Name of the file
        Returns:
        true if the file name is valid.
      • validateZipFile

        public void validateZipFile​(File file)
        Validates if a file is a zip file
        Parameters:
        file - The file
        Throws:
        IllegalArgumentException - if the file is not a zip file.
      • getFileSize

        public Long getFileSize​(String fileName,
                                JobScope jobScope)
        Returns the size (in bytes) of a file in the restore directory if it exists.
        Parameters:
        fileName - file name
        jobScope - JobScope
        Returns:
        fileSize size of file in bytes (null if file not found)
      • moveExistingLocalFileToRestoreDir

        public String moveExistingLocalFileToRestoreDir​(File fileToMove,
                                                        JobScope jobScope)
                                                 throws BackupRestoreException
        Moves the provided file to the restore directory
        Parameters:
        fileToMove - the file to be moved to the restore directory
        jobScope - JobScope
        Returns:
        the filename of the new file
        Throws:
        BackupRestoreException - if there was an issue with the move
      • deleteZipFile

        public void deleteZipFile​(String filePath,
                                  JobScope jobScope)
                           throws IOException
        Deletes a zip file from the restore folder
        Parameters:
        filePath - file to delete
        jobScope - if the file is a site or space backup
        Throws:
        IOException
      • generateSpaceBackupFileName

        public String generateSpaceBackupFileName​(String prefix,
                                                  Set<String> spaceKeys,
                                                  Supplier<LocalDateTime> localDateTimeSupplier)
        Generates a backup file name for space backup.

        For a single space backup, the format would be [Prefix]-[Space Key]-[YYYY-MM-DD-HH-mm-ss-SSS].xml.zip

        For a single space backup, if the space key length is more than 10 then the format would be [Prefix]-1-spaces-[YYYY-MM-DD-HH-mm-ss-SSS].xml.zip

        For multi space backup, the format would be [Prefix]-[Number of spaces]-spaces-[YYYY-MM-DD-HH-mm-ss-SSS].xml.zip

        If the file already exists, a file with a suffix (Incrementing counter) is tried until it succeeds [Generated File Name]-1.xml.zip

        Parameters:
        prefix - File name prefix
        spaceKeys - Set of space keys
        Returns:
        String name of the space backup file
      • generateSiteBackupFileName

        public String generateSiteBackupFileName​(String prefix,
                                                 Supplier<LocalDateTime> localDateTimeSupplier)
        Generates a backup file name for site backup. Format : [Prefix]-[YYYY-MM-DD-HH-mm-ss-SSS].xml.zip

        If the file already exists, a file with a suffix (Incrementing counter) is tried until it succeeds [Generated File Name]-1.xml.zip

        Parameters:
        prefix - File name prefix
        Returns:
        String name of the site backup file