pub struct BackupEngine<'a> { /* private fields */ }Expand description
Engine for backup and restore operations.
Implementations§
Source§impl<'a> BackupEngine<'a>
impl<'a> BackupEngine<'a>
Sourcepub async fn backup_deck(
&self,
deck: &str,
backup_dir: impl AsRef<Path>,
) -> Result<BackupResult>
pub async fn backup_deck( &self, deck: &str, backup_dir: impl AsRef<Path>, ) -> Result<BackupResult>
Backup a deck to an .apkg file.
Creates a backup file in the specified directory with a timestamped filename. The backup includes all notes, cards, scheduling data, and media.
§Arguments
deck- Name of the deck to backupbackup_dir- Directory where the backup file will be created
§Returns
Returns BackupResult with the path to the created backup file.
§Example
use ankit_engine::Engine;
let engine = Engine::new();
let result = engine.backup()
.backup_deck("Japanese::Vocabulary", "/home/user/anki-backups")
.await?;
println!("Backup created: {}", result.path.display());
println!("Size: {} bytes", result.size_bytes);Sourcepub async fn backup_deck_with_options(
&self,
deck: &str,
backup_dir: impl AsRef<Path>,
options: BackupOptions,
) -> Result<BackupResult>
pub async fn backup_deck_with_options( &self, deck: &str, backup_dir: impl AsRef<Path>, options: BackupOptions, ) -> Result<BackupResult>
Backup a deck with custom options.
§Arguments
deck- Name of the deck to backupbackup_dir- Directory where the backup file will be createdoptions- Backup options (scheduling data, filename format)
§Example
use ankit_engine::Engine;
use ankit_engine::backup::BackupOptions;
let engine = Engine::new();
let options = BackupOptions {
include_scheduling: false, // Don't include review history
..Default::default()
};
let result = engine.backup()
.backup_deck_with_options("Japanese", "/tmp/backups", options)
.await?;Sourcepub async fn restore_deck(
&self,
backup_path: impl AsRef<Path>,
) -> Result<RestoreResult>
pub async fn restore_deck( &self, backup_path: impl AsRef<Path>, ) -> Result<RestoreResult>
Restore a deck from an .apkg backup file.
Imports the backup file into Anki. If the deck already exists, Anki’s default duplicate handling will apply.
§Arguments
backup_path- Path to the .apkg file to restore
§Example
use ankit_engine::Engine;
let engine = Engine::new();
let result = engine.backup()
.restore_deck("/home/user/backups/Japanese-2024-01-15.apkg")
.await?;
if result.success {
println!("Restore completed successfully");
}Sourcepub async fn backup_collection(
&self,
backup_dir: impl AsRef<Path>,
) -> Result<CollectionBackupResult>
pub async fn backup_collection( &self, backup_dir: impl AsRef<Path>, ) -> Result<CollectionBackupResult>
Backup all decks to separate .apkg files.
Creates individual backup files for each deck in the collection.
§Arguments
backup_dir- Directory where backup files will be created
§Returns
Returns a CollectionBackupResult with results for each deck.
§Example
use ankit_engine::Engine;
let engine = Engine::new();
let result = engine.backup()
.backup_collection("/home/user/anki-backups")
.await?;
println!("Backed up {} decks", result.successful.len());
if !result.failed.is_empty() {
println!("Failed: {:?}", result.failed);
}Sourcepub async fn list_backups(
&self,
backup_dir: impl AsRef<Path>,
) -> Result<Vec<BackupInfo>>
pub async fn list_backups( &self, backup_dir: impl AsRef<Path>, ) -> Result<Vec<BackupInfo>>
List backup files in a directory.
Scans the directory for .apkg files and returns information about each.
§Arguments
backup_dir- Directory to scan for backup files
§Example
use ankit_engine::Engine;
let engine = Engine::new();
let backups = engine.backup()
.list_backups("/home/user/anki-backups")
.await?;
for backup in backups {
println!("{}: {} bytes", backup.path.display(), backup.size_bytes);
}Sourcepub async fn rotate_backups(
&self,
backup_dir: impl AsRef<Path>,
keep: usize,
) -> Result<Vec<PathBuf>>
pub async fn rotate_backups( &self, backup_dir: impl AsRef<Path>, keep: usize, ) -> Result<Vec<PathBuf>>
Delete old backups, keeping the most recent N.
Useful for implementing backup rotation.
§Arguments
backup_dir- Directory containing backup fileskeep- Number of most recent backups to keep
§Returns
Returns the paths of deleted backup files.
§Example
use ankit_engine::Engine;
let engine = Engine::new();
// Keep only the 5 most recent backups
let deleted = engine.backup()
.rotate_backups("/home/user/anki-backups", 5)
.await?;
println!("Deleted {} old backups", deleted.len());