public class BackupManager extends Object
Automatic backups can scheduled by setting the appropriate environment variables:
EnvironmentConfig.ENV_RUN_BACKUP
EnvironmentConfig.BACKUP_SCHEDULE
EnvironmentConfig.BACKUP_COPY_CLASS
EnvironmentConfig.BACKUP_COPY_CONFIG
EnvironmentConfig.BACKUP_LOCATION_CLASS
EnvironmentConfig.BACKUP_LOCATION_CONFIG
The backups are performed using the DbBackup class. Each backup
creates a snapshot with hard links to log files from DbBackup.
The files are then copied to an archive location. Only new (or newly modified) files are copied for each snapshot. The copy mechanism maintains a manifest for each snapshot that documents its contents and is used to determine which files have already been copied. After a log file is copied, the associated hard link is removed so that the file can be deleted from disk as needed. When a local snapshot is no longer needed, it is deleted.
The backup is performed by two separate threads. SnapshotThread
creates JE snapshots on the configured schedule. It runs as its own thread
so that backups are performed as close as possible to the scheduled time, to
allow backups for different environments to be coordinated. When a snapshot
has been created, the snapshot thread wakes up CopyThread, which
copies the snapshot to archive storage. If the copy thread is still running
when the snapshot thread creates a new snapshot, the snapshot thread
interrupts the copy thread so that it will abandon its work on that snapshot
and start work on the new one.
| Modifier and Type | Field and Description |
|---|---|
static String |
SNAPSHOT_MANIFEST
The name of the manifest file created in a snapshot directory to
represent the copy status of files in the snapshot.
|
static long |
timeMultiplier
If non-zero, a multiplier to speed the passage of time by the specified
factor, for testing only.
|
| Constructor and Description |
|---|
BackupManager(EnvironmentImpl envImpl)
Creates an instance of this class for the specified environment.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
checksumToHex(byte[] checksum)
Converts a checksum to hex format.
|
static CronScheduleParser |
createSnapshotScheduleParser(String cronSchedule)
Processes information in the specified crontab formatted schedule.
|
static long |
currentTimeMs()
Returns the current time in absolute milliseconds, adjusted as needed
for
timeMultiplier. |
static void |
forceFile(Path path)
Force any pending changes to disk for the file with the specified
pathname.
|
static <C> Constructor<? extends C> |
getImplementationClassConstructor(Class<? extends C> type,
String className)
Returns a public no-arguments constructor for a non-abstract class that
implements the specified interface.
|
static <C> C |
getImplementationInstance(Class<C> type,
String className)
Returns an object that implements an interface by creating an instance
of the specified non-abstract class that implements the specified
interface.
|
static void |
sleepMs(long timeMs)
Sleeps for the specified number of milliseconds, adjusted as needed for
timeMultiplier. |
public static volatile long timeMultiplier
Note that the resulting time value needs to be less than Long.MAX_VALUE. With the current time of around 1528719052059 and a max value of 9223372036854775807, that makes the maximum multiplier approximately 6 million. The one week to a second transformation should continue to work as long as we could possibly care about -- until 2453!
Waiting for an amount of time that, because of the multiplier, is less than 1 millisecond will result in a 1 millisecond wait. Tests need to account for the fact that seemingly short operations may take a long time in the dilated time scale.
Code in this file (and in tests) that needs the current time should
call currentTimeMs(), call waitMs(java.lang.Object, long) to wait, and call
sleepMs(long) to sleep. These three methods apply the time multiplier
if specified.
public static final String SNAPSHOT_MANIFEST
public BackupManager(EnvironmentImpl envImpl)
envImpl - the environmentIllegalArgumentException - if there is a problem with a
configuration propertypublic static CronScheduleParser createSnapshotScheduleParser(String cronSchedule)
cronSchedule - the scheduleIllegalArgumentException - if the schedule is illegalpublic static void forceFile(Path path) throws IOException
path - the file pathIOException - if an I/O failure occurs
TODO: Move this method to some je utility package where it would be
available for more general use.public static <C> Constructor<? extends C> getImplementationClassConstructor(Class<? extends C> type, String className)
C - the interface typetype - the interface that the class must implementclassName - the fully qualified class nameIllegalStateException - if type is not an interface, the specified
class is not found, does not implement the specified interface, is
abstract, or does not have a public no-arguments constructorpublic static <C> C getImplementationInstance(Class<C> type, String className)
C - the interface typetype - the interface that the class must implementclassName - the fully qualified class nameIllegalStateException - if type is not an interface, the specified
class is not found, does not implement the specified interface, is
abstract, does not have a public no-arguments constructor, or the call
to the constructor throws an exceptionpublic static long currentTimeMs()
timeMultiplier.public static void sleepMs(long timeMs)
throws InterruptedException
timeMultiplier.timeMs - the number of milliseconds to sleepIllegalArgumentException - if timeMs is less than 1InterruptedException - if the operation is interruptedpublic static String checksumToHex(byte[] checksum)
checksum - the checksum as a byte arrayCopyright © 2024. All rights reserved.