Class BackupRestoreFilesystemManager
- java.lang.Object
-
- com.atlassian.confluence.impl.backuprestore.BackupRestoreFilesystemManager
-
public class BackupRestoreFilesystemManager extends Object
-
-
Constructor Summary
Constructors Constructor Description BackupRestoreFilesystemManager(com.atlassian.dc.filestore.api.compat.FilesystemPath confluenceHome, com.atlassian.dc.filestore.api.compat.FilesystemPath localHome)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deleteZipFile(String filePath, JobScope jobScope)
Deletes a zip file from the restore folderString
generateSiteBackupFileName(String prefix, Supplier<LocalDateTime> localDateTimeSupplier)
Generates a backup file name for site backup.String
generateSpaceBackupFileName(String prefix, Set<String> spaceKeys, Supplier<LocalDateTime> localDateTimeSupplier)
Generates a backup file name for space backup.File
getFile(String fileName, JobScope jobScope)
Returns a file from the restore directory if it exists.List<FileInfo>
getFiles(JobScope jobScope)
Gets list of FileInfo objects containing the information of files present in the site or space restore folderLong
getFileSize(String fileName, JobScope jobScope)
Returns the size (in bytes) of a file in the restore directory if it exists.String
getRestoreWorkingDir(JobScope jobScope)
Returns restore working directory based on the JobScopeboolean
isValidFilename(String filename)
Returns if a file name is a valid file name for restoreString
moveExistingLocalFileToRestoreDir(File fileToMove, JobScope jobScope)
Moves the provided file to the restore directoryvoid
validateZipFile(File file)
Validates if a file is a zip filecom.atlassian.dc.filestore.api.compat.FilesystemPath
writeFileLocally(JobScope jobScope, String fileName, Supplier<InputStream> inputStreamSupplier)
Writes a local file with a given name and given InputStream based on the JobScope.
-
-
-
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
- JobScopefileName
- Name of the fileinputStreamSupplier
- 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.
-
getFile
public File getFile(String fileName, JobScope jobScope) throws FileNotFoundException
Returns a file from the restore directory if it exists.- Parameters:
fileName
- file namejobScope
- JobScope- Throws:
FileNotFoundException
- if the file does not exist
-
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 namejobScope
- 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 directoryjobScope
- 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 deletejobScope
- 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 prefixspaceKeys
- 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.zipIf 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
-
-