Backing Up Files With a Custom Policy


A backup policy can be configured to back up files. By default a NullBackupPolicy is configured, which does nothing. It can be replaced by a DeleteBackupPolicy to keep a backup of files for a specified period of time. The BackupPolicy interface allows custom implementations to be plugged-in.

Null Backup Policy

A null backup policy acts as a placeholder for a ‘do-nothing’ behavior. Used when an exception occurs trying to instantiate a customized backup policy, or if no policy is desired.

Delete Backup Policy

A backup policy that deletes any file that is older than the specified backup period, but keeps at least as many of the specified backup files.

By default, a file is kept for a 30-day period. After 30 days, the file is deleted, unless there are less than 10 backup files available. In other words, maintain a history of 10 files, even if there was nothing logged for more than 30 days.

These properties can be configured by modifying the logging configuration file:

com.gigaspaces.logger.RollingFileHandler.backup-policy = com.gigaspaces.logger.DeleteBackupPolicy
com.gigaspaces.logger.DeleteBackupPolicy.period = 30
com.gigaspaces.logger.DeleteBackupPolicy.backup = 10

The backup properties can also be configured using a system property override:

-Dcom.gigaspaces.logger.DeleteBackupPolicy.[property-name]=[property-value]

For example:
-Dcom.gigaspaces.logger.DeleteBackupPolicy.period=30

Customized Backup Policy

The com.gigaspaces.logger.BackupPolicy is an interface for a pluggable backup policy. For example, you may wish to write an implementation to zip files if a certain threshold is reached. The interface has a single method, which is used to track newly created log files. A file is either created upon rollover or at initialization time. Implementation can keep track of files and decide whether to trigger the backup policy.

    public void track(File file);