Class BackupRestoreFilesystemManager
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBackupRestoreFilesystemManager
(com.atlassian.dc.filestore.api.compat.FilesystemPath confluenceHome, com.atlassian.dc.filestore.api.compat.FilesystemPath localHome) -
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteZipFile
(String filePath, JobScope jobScope) Deletes a zip file from the restore folderboolean
Checks if a file with the given name exists in the restore working directorygenerateSiteBackupFileName
(String prefix, Supplier<LocalDateTime> localDateTimeSupplier) Generates a backup file name for site backup.generateSpaceBackupFileName
(String prefix, Set<String> spaceKeys, Supplier<LocalDateTime> localDateTimeSupplier) Generates a backup file name for space backup.Returns a file from the restore directory if it exists.Gets list of FileInfo objects containing the information of files present in the site or space restore foldergetFileSize
(String fileName, JobScope jobScope) Returns the size (in bytes) of a file in the restore directory if it exists.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 restoremoveExistingLocalFileToRestoreDir
(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.
-
Field Details
-
RESTORE
- See Also:
-
SITE
- See Also:
-
SPACE
- See Also:
-
-
Constructor Details
-
BackupRestoreFilesystemManager
public BackupRestoreFilesystemManager(com.atlassian.dc.filestore.api.compat.FilesystemPath confluenceHome, com.atlassian.dc.filestore.api.compat.FilesystemPath localHome)
-
-
Method Details
-
getFiles
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
-
exists
Checks if a file with the given name exists in the restore working directory- Parameters:
jobScope
- JobScopefileName
- Name of the file- Returns:
- true if the file exists, false otherwise
-
getRestoreWorkingDir
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
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
Validates if a file is a zip file- Parameters:
file
- The file- Throws:
IllegalArgumentException
- if the file is not a zip file.
-
getFile
Returns a file from the restore directory if it exists.- Parameters:
fileName
- file namejobScope
- JobScope- Throws:
FileNotFoundException
- if the file does not exist
-
getFileSize
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
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
-