Skip to main content

BackupEngine

Struct BackupEngine 

Source
pub struct BackupEngine<'a> { /* private fields */ }
Expand description

Engine for backup and restore operations.

Implementations§

Source§

impl<'a> BackupEngine<'a>

Source

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 backup
  • backup_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);
Source

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 backup
  • backup_dir - Directory where the backup file will be created
  • options - 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?;
Source

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");
}
Source

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);
}
Source

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);
}
Source

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 files
  • keep - 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());

Auto Trait Implementations§

§

impl<'a> Freeze for BackupEngine<'a>

§

impl<'a> !RefUnwindSafe for BackupEngine<'a>

§

impl<'a> Send for BackupEngine<'a>

§

impl<'a> Sync for BackupEngine<'a>

§

impl<'a> Unpin for BackupEngine<'a>

§

impl<'a> !UnwindSafe for BackupEngine<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more