db_v1_queries_backup - OmniCloudOrg/OmniOrchestrator GitHub Wiki

backup (src/db/v1/queries)

Path: src/db/v1/queries/backup.rs

Table of Contents

Public Items

async fn list_backups_paginated

Definition

pub async fn list_backups_paginated(
    pool: &State<sqlx::Pool<MySql>>,
    page: i64,
    page_size: i64,
) -> Result<Vec<Backup>, sqlx::Error> {
    tracing::info!(
        page = page,
        page_size = page_size,
        "Fetching paginated backups"
    );
    
    // Add simple plain text logs
    tracing::info!("About to execute SQL query");
    
    // Use match to explicitly handle success vs error
    match sqlx::query_as::<_, Backup>(
        "SELECT * FROM backups LIMIT ? OFFSET ?"
    )
    .bind(page_size)
    .bind((page - 1) * page_size)
    .fetch_all(&**pool)
    // ... function definition continues
    // ... function body
}

Documentation

Paginated backups list

async fn list_backups_by_app_id

Definition

pub async fn list_backups_by_app_id(
    pool: &State<sqlx::Pool<MySql>>,
    app_id: i64,
    page: i64,
    page_size: i64,
) -> Result<Vec<Backup>, sqlx::Error> {
    let backups = sqlx::query_as::<_, Backup>(
        "SELECT * FROM backups WHERE app_id = ? LIMIT ? OFFSET ?",
    )
    .bind(app_id)
    .bind(page_size)
    .bind((page - 1) * page_size)
    .fetch_all(&**pool)
    .await?;
    println!("Found {} backups", backups.len());
    println!("Returning {} backups", backups.len());

    Ok(backups)
}

/// Get a backup by ID
    // ... function definition continues
    // ... function body
}

Documentation

Paginated backups list by app_id

async fn get_backup_by_id

Definition

pub async fn get_backup_by_id(
    pool: &State<sqlx::Pool<MySql>>,
    backup_id: i64,
) -> Result<Option<Backup>, sqlx::Error> {
    let backup = sqlx::query_as::<_, Backup>(
        "SELECT * FROM backups WHERE id = ?",
    )
    .bind(backup_id)
    .fetch_optional(&**pool)
    .await?;
    println!("Found backup: {:?}", backup);

    Ok(backup)
}

/// Create a new backup
/// This function creates a new app backup in the database
pub async fn create_backup(
    pool: &State<sqlx::Pool<MySql>>,
    backup: &Backup,
) -> Result<Backup, sqlx::Error> {
    // ... function body
}

Documentation

Get a backup by ID

async fn create_backup

Definition

pub async fn create_backup(
    pool: &State<sqlx::Pool<MySql>>,
    backup: &Backup,
) -> Result<Backup, sqlx::Error> {
    sqlx::query(
        "INSERT INTO backups (
            name, description, created_at, created_by, backup_type, status, format_version,
            source_environment, encryption_method, encryption_key_id, size_bytes, has_system_core,
            has_directors, has_orchestrators, has_network_config, has_app_definitions, has_volume_data,
            included_apps, included_services, last_validated_at, last_restored_at, restore_target_environment,
            restore_status, storage_location, manifest_path, metadata
        ) VALUES (
            ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
        )",
    )
    .bind(backup.name.clone())
    .bind(backup.description.clone())
    .bind(backup.created_at)
    .bind(backup.created_by.clone())
    .bind(backup.backup_type.clone())
    .bind(backup.status.clone())
    // ... function definition continues
    // ... function body
}

Documentation

Create a new backup This function creates a new app backup in the database

⚠️ **GitHub.com Fallback** ⚠️