public interface BackupStrategy2 extends BackupStrategy
| Modifier and Type | Field and Description |
|---|---|
static int |
NO_LIMIT
Don't limit the backup index, which means there is no limit to the number of backup files.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getBackupFileName(java.lang.String fileName,
int backupIndex)
Get the backup file name for specific index.
|
int |
getMaxBackupIndex()
Get the max index of backup.
|
shouldBackupstatic final int NO_LIMIT
int getMaxBackupIndex()
Generally, the max index should be greater than 1, and recommended to be less than 10.
Imagine the normal log file name is 'log', and max backup index is 'n', as the log grows,
a log record would go from 'log' to 'log.bak.1', then to 'log.bak.2', 'log.bak.3', and finally
to 'log.bak.n', the greater index, the older log.
After that, the log record will no longer exist in the file system.
If you don't want to limit the max index, then return NO_LIMIT.
With returning NO_LIMIT, When you backing up, the oldest log would be saved to
'log.bak.1', and then 'log.bak.2'...'log.bak.n', the greater index, the newer log.
Don't return Integer.MAX_VALUE or any value less than 0, otherwise an exception will
be thrown.
java.lang.String getBackupFileName(java.lang.String fileName,
int backupIndex)
Generally, a backup file with normal file name 'log' and index 'n' could simply be 'log.bak.n', you can specify your own naming rules, by overriding this method.
Make sure to return different backup file name with different backup index, and same backup file name with same index. Otherwise, it will lead to unexpected behavior.
fileName - the normal file name, generated by
FileNameGenerator.generateFileName(int, long)backupIndex - the backup index, which will increase from 1 to getMaxBackupIndex()