#2742 Database backups with scheduled backups, retention and restore

- Engine-independent backup files (zip with calls, events and metadata as JSON) written from a single read
  transaction on a background thread; restorable into any supported database type.
- Automatic backup interval and number of backups to keep in the database preferences; the oldest backups
  are deleted after each backup.
- Backup list with Back Up Now, Restore and Delete.  A restore runs in one transaction on the database thread
  after making a pre-restore backup; missing recordings are marked deleted and in-progress calls interrupted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
denny
2026-11-22 03:16:23 -05:00
parent d6234600c0
commit bb19547af0
14 changed files with 2119 additions and 2 deletions

View File

@@ -22,6 +22,7 @@ import io.github.dsheirer.database.DatabaseConfiguration;
import io.github.dsheirer.database.DatabaseType;
import io.github.dsheirer.database.ageoff.AgeOffAction;
import io.github.dsheirer.database.ageoff.RetentionPeriod;
import io.github.dsheirer.database.backup.BackupInterval;
import io.github.dsheirer.preference.Preference;
import io.github.dsheirer.preference.PreferenceType;
import io.github.dsheirer.sample.Listener;
@@ -50,11 +51,15 @@ public class DatabasePreference extends Preference
private static final String KEY_SIZE_RULE_ACTION = "ageoff.size.action";
private static final String KEY_DUPLICATE_DNM_RETENTION = "ageoff.duplicate.dnm.retention";
private static final String KEY_EVENT_RULE_ENABLED = "ageoff.events.enabled";
private static final String KEY_BACKUP_INTERVAL = "backup.interval";
private static final String KEY_BACKUP_RETAIN = "backup.retain";
private static final String KEY_EVENT_RULE_DAYS = "ageoff.events.days";
public static final String DEFAULT_POSTGRES_DATABASE = "postgres";
public static final int DEFAULT_AGE_DAYS = 30;
public static final int DEFAULT_EVENT_AGE_DAYS = 30;
public static final int DEFAULT_BACKUP_RETAIN = 7;
public static final int MAX_BACKUP_RETAIN = 365;
public static final int DEFAULT_SIZE_LIMIT_MB = 10 * 1024;
private final Preferences mPreferences = Preferences.userNodeForPackage(DatabasePreference.class);
@@ -134,6 +139,41 @@ public class DatabasePreference extends Preference
mPreferences.get(KEY_USER, ""), mPreferences.get(KEY_PASSWORD, ""));
}
/**
* How often the database is backed up automatically
*/
public BackupInterval getBackupInterval()
{
try
{
return BackupInterval.valueOf(mPreferences.get(KEY_BACKUP_INTERVAL, BackupInterval.DEFAULT.name()));
}
catch(IllegalArgumentException iae)
{
return BackupInterval.DEFAULT;
}
}
public void setBackupInterval(BackupInterval interval)
{
mPreferences.put(KEY_BACKUP_INTERVAL, interval.name());
notifyPreferenceUpdated();
}
/**
* Number of backup files to keep. The oldest backups are deleted after a backup when there are more.
*/
public int getBackupRetain()
{
return Math.clamp(mPreferences.getInt(KEY_BACKUP_RETAIN, DEFAULT_BACKUP_RETAIN), 1, MAX_BACKUP_RETAIN);
}
public void setBackupRetain(int retain)
{
mPreferences.putInt(KEY_BACKUP_RETAIN, Math.clamp(retain, 1, MAX_BACKUP_RETAIN));
notifyPreferenceUpdated();
}
/**
* Indicates if the event age rule (delete decode events older than a number of days) is enabled. Enabled by
* default, because a busy control channel produces many events.