ch.braincell.stickbackup.process
Class BackupTask

java.lang.Object
  extended by ch.braincell.stickbackup.process.BackupTask

public class BackupTask
extends java.lang.Object

Main class for backup tasks. This one starts the backup and processes it.

Author:
Andreas Studer

Field Summary
protected  java.io.File archivedDir
          archive directory where the obsolete files of the destination goes.
static java.lang.String archiveFileDir
          all archiving files will be stored in a subdirectory "archive".
protected  java.util.AbstractList<java.io.File> archivingDestinationDirs
          All deleted or moved directories.
protected  java.util.Set<java.io.File> archivingDestinationFiles
          All deleted, moved or changed files from the backup directory which needs to be archived.
static java.lang.String backupFileDir
          all backuped files will be copied in the subdirectory "backup".
protected  int backupprogress
          counts up in the progress of the backup.
protected  java.io.File destinationDir
          destination directory where the backup of the source goes.
protected  int destinationDirLength
          Length of the destination directory path (convenience for some methods)
protected  java.util.Map<java.lang.String,java.io.File> destinationDirList
          directory list of the destination directory (all already backed up files).
protected  java.util.Map<java.lang.String,java.io.File> destinationFileList
          Filelist of the destination directory (all already backed up files).
protected  ch.braincell.stickbackup.process.ProcessListenerObservant listener
           
protected  java.util.AbstractList<java.io.File> newSourceDirs
          All new directories from the source who needs to be backed up.
protected  java.util.Set<java.io.File> newSourceFiles
          All new or changed files from the source who needs to be backed up.
protected  boolean processCanceled
          is set to true if the backup process should be canceled.
protected  java.io.File sourceDir
          Source directory which needs to be backed up.
protected  int sourceDirLength
          Length of the source directory path (convenience for some methods)
protected  java.util.Map<java.lang.String,java.io.File> sourceDirList
          directory list of the source directory to be backed up
protected  java.util.Map<java.lang.String,java.io.File> sourceFileList
          Filelist of the source directory to be backed up
 
Constructor Summary
BackupTask()
           
 
Method Summary
 void addListener(ProcessListener listener)
           
protected  void archiveDirectories(java.util.Date date)
          Create all deleted / changed / moved Directories since the last backup in the archive directory.
protected  void archiveFiles(java.util.Date date)
          Copy all deleted / changed / moved files since the last backup from the destination directory to the archive directory.
protected  void backupDirectories()
          Create the new backup: create all new / moved directories from the source to the destination directory.
protected  void backupFiles()
          Create the new backup: copy all new / moved / changed files from the source to the destination directory.
protected  void cleanupArchivedDirectories()
          Deletes all archived Directories from the backup directory (destination directory).
protected  void cleanupArchivedFiles()
          Deletes all archived files from the backup directory (destination directory).
protected  void copyFile(java.io.File source, java.io.File destination)
          Copies a file from the source to the destination.
protected  void findAllChangedAndNewFiles()
          Compares the source directory with the destination directory and finds all changed and new files.
protected  void findAllNewSourceDirectories()
          Compares the source directory with the destination directory and finds all new directories.
protected  void findAllRemovedSourceDirectories()
          Compares the source directory with the destination directory and finds all removed directories.
protected  void findAllRemovedSourceFiles()
          Compares the source directory with the destination directory and finds all deleted and moved files.
 int getBackupprogress()
          Gets the actual progress index of the process.
 boolean isProcessCanceled()
          test if the process is canceled by the user.
protected  void loadDestDir()
          Loads all files from the destination directory (recursive) where the last backup is.
protected  void loadSourceDir()
          Loads all Files from the source directory (recursive) which needs to be backed up.
 void processBackupAndArchive()
          Processes archiving and backup of the files.
 int readFilesToBackupAndArchive()
          Reads the files from the source and the destination.
 void setProcessCanceled(boolean processCanceled)
          Sets the cancelation of the process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

backupFileDir

public static final java.lang.String backupFileDir
all backuped files will be copied in the subdirectory "backup".


archiveFileDir

public static final java.lang.String archiveFileDir
all archiving files will be stored in a subdirectory "archive".


backupprogress

protected volatile int backupprogress
counts up in the progress of the backup.


processCanceled

protected volatile boolean processCanceled
is set to true if the backup process should be canceled.


sourceFileList

protected java.util.Map<java.lang.String,java.io.File> sourceFileList
Filelist of the source directory to be backed up


sourceDirList

protected java.util.Map<java.lang.String,java.io.File> sourceDirList
directory list of the source directory to be backed up


destinationFileList

protected java.util.Map<java.lang.String,java.io.File> destinationFileList
Filelist of the destination directory (all already backed up files).


destinationDirList

protected java.util.Map<java.lang.String,java.io.File> destinationDirList
directory list of the destination directory (all already backed up files).


newSourceFiles

protected java.util.Set<java.io.File> newSourceFiles
All new or changed files from the source who needs to be backed up.


newSourceDirs

protected java.util.AbstractList<java.io.File> newSourceDirs
All new directories from the source who needs to be backed up.


archivingDestinationFiles

protected java.util.Set<java.io.File> archivingDestinationFiles
All deleted, moved or changed files from the backup directory which needs to be archived.


archivingDestinationDirs

protected java.util.AbstractList<java.io.File> archivingDestinationDirs
All deleted or moved directories.


sourceDir

protected java.io.File sourceDir
Source directory which needs to be backed up.


destinationDir

protected java.io.File destinationDir
destination directory where the backup of the source goes.


archivedDir

protected java.io.File archivedDir
archive directory where the obsolete files of the destination goes.


sourceDirLength

protected int sourceDirLength
Length of the source directory path (convenience for some methods)


destinationDirLength

protected int destinationDirLength
Length of the destination directory path (convenience for some methods)


listener

protected ch.braincell.stickbackup.process.ProcessListenerObservant listener
Constructor Detail

BackupTask

public BackupTask()
Method Detail

addListener

public void addListener(ProcessListener listener)

readFilesToBackupAndArchive

public int readFilesToBackupAndArchive()
Reads the files from the source and the destination. Both directories will be compared to find out which source files need to be backed up and which destination files needs to be archived.

Returns:
maximum index for watching the progress.

processBackupAndArchive

public void processBackupAndArchive()
Processes archiving and backup of the files. First there will be archiving of obsolete or changed backup-files. Then the source files will be archived.


loadSourceDir

protected void loadSourceDir()
Loads all Files from the source directory (recursive) which needs to be backed up.


loadDestDir

protected void loadDestDir()
Loads all files from the destination directory (recursive) where the last backup is.


findAllChangedAndNewFiles

protected void findAllChangedAndNewFiles()
Compares the source directory with the destination directory and finds all changed and new files.


findAllNewSourceDirectories

protected void findAllNewSourceDirectories()
Compares the source directory with the destination directory and finds all new directories. They will be backed up.


findAllRemovedSourceFiles

protected void findAllRemovedSourceFiles()
Compares the source directory with the destination directory and finds all deleted and moved files. They will be archived.


findAllRemovedSourceDirectories

protected void findAllRemovedSourceDirectories()
Compares the source directory with the destination directory and finds all removed directories. They will be archived.


archiveDirectories

protected void archiveDirectories(java.util.Date date)
Create all deleted / changed / moved Directories since the last backup in the archive directory.

Parameters:
date - the date to create the subdirectory in the archive.
Throws:
java.io.IOException

archiveFiles

protected void archiveFiles(java.util.Date date)
                     throws java.io.IOException
Copy all deleted / changed / moved files since the last backup from the destination directory to the archive directory.

Parameters:
date - the date to create the subdirectory in the archive.
Throws:
java.io.IOException

cleanupArchivedFiles

protected void cleanupArchivedFiles()
                             throws java.io.IOException
Deletes all archived files from the backup directory (destination directory).

Throws:
java.io.IOException

cleanupArchivedDirectories

protected void cleanupArchivedDirectories()
Deletes all archived Directories from the backup directory (destination directory).


backupDirectories

protected void backupDirectories()
Create the new backup: create all new / moved directories from the source to the destination directory.


backupFiles

protected void backupFiles()
                    throws java.io.IOException
Create the new backup: copy all new / moved / changed files from the source to the destination directory.

Throws:
java.io.IOException

copyFile

protected void copyFile(java.io.File source,
                        java.io.File destination)
                 throws java.io.IOException
Copies a file from the source to the destination.

Parameters:
source - sourcefile. Will be opened readonly.
destination - destinationfile.
Throws:
java.io.IOException

isProcessCanceled

public boolean isProcessCanceled()
test if the process is canceled by the user.

Returns:
true if it is canceled, false otherwise.

setProcessCanceled

public void setProcessCanceled(boolean processCanceled)
Sets the cancelation of the process.


getBackupprogress

public int getBackupprogress()
Gets the actual progress index of the process.

Returns:
index of progress.


Copyright © 2007. All Rights Reserved.