In this page
Backups
GreyCat includes a built-in backup mechanism that can be triggered manually from GCL.
By default, backup files are stored in the ./backup
directory and use the .gcbkp
extension.
A maximum of three backup files is kept at any given time, but this behavior can be customized through CLI options.
CLI options
GreyCat provides the following backup-related options:
--backup_path=<str>
specifies the directory where backup files are stored and retrieved. Default:./backup
.--max_backup_files=<i64>
defines the maximum number of backup files to keep in thebackup_path
. When the limit is reached, the oldest files are automatically removed. Default:3
.
Example:
greycat serve --backup_path=/path/to/backups --max_backup_files=5
Scheduled backups
You can schedule automated backups to run daily at 2:00 AM (host timezone) with the following GCL code:
fn main() {
Scheduler::add(
runtime::Runtime::backup_full,
DailyPeriodicity { hour: 2 },
null,
)
}
This will automatically trigger a full backup once a day without requiring manual intervention.
The generated backups will respect the configured --backup_path
and --max_backup_files
settings.
Restoring a backup
GreyCat provides a simple CLI command to restore the database from a backup file. Restoration can be done either from a specific backup file or from the most recent one.
Restoring a specific backup
You can restore the database from a specific .gcbkp
file by providing its path:
greycat restore /path/to/backup.gcbkp
This will fully restore the database state from the chosen backup file.
Restoring the latest backup
If no path is provided, GreyCat will automatically restore the most recent backup file found in the configured --backup_path
:
greycat restore
This is useful for quickly recovering the latest state without manually specifying the file.
Note:
- Restoring a backup will overwrite the current database state.
- Ensure GreyCat is stopped or in a safe state before performing a restore in production environments.
- The path used for restoration follows the
--backup_path
setting if no explicit path is provided.