u/Upstairs-Cup-8666

Snowflake Backup Assistant Agent

A Cortex Agent for managing Snowflake database, schema, and table backups through natural language conversations.

Overview

The Backup Assistant Agent provides an AI-powered interface for managing Snowflake's native backup capabilities. Users can create backup sets, configure automated backup policies, restore from backups, and manage legal holds—all through conversational interactions.

Features

  • Multi-level Backups: Support for table, schema, and database-level backups
  • Automated Scheduling: Configure hourly, daily, or weekly backup policies
  • Flexible Retention: Set custom expiration periods for automatic cleanup
  • Disaster Recovery: Restore objects from any point-in-time backup
  • Legal Holds: Compliance support to prevent backup deletion during litigation
  • Policy Management: Suspend/resume backup creation and expiration independently

Prerequisites

  • Snowflake account with Cortex Agents enabled
  • ACCOUNTADMIN role (or equivalent privileges)
  • Active warehouse (default: COMPUTE_WH)

Installation

Quick Start

-- Run the complete setup script
USE ROLE ACCOUNTADMIN;
-- Execute setup/backup_assistant_agent.sql
┌─────────────────────────────────────────────────────────────┐
│                    BACKUP_ASSISTANT Agent                    │
│                    (claude-4-sonnet)                         │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                      16 Custom Tools                         │
├──────────────────┬──────────────────┬───────────────────────┤
│  Backup Sets     │  Policies        │  Operations           │
├──────────────────┼──────────────────┼───────────────────────┤
│ create_table_    │ create_backup_   │ add_backup            │
│ backup_set       │ policy           │ list_backups          │
│ create_schema_   │ apply_backup_    │ restore_table         │
│ backup_set       │ policy           │ restore_schema        │
│ create_database_ │ suspend_backup_  │ restore_database      │
│ backup_set       │ policy           │ delete_backup         │
│ create_backup_   │ resume_backup_   │ add_legal_hold        │
│ set_with_policy  │ policy           │ remove_legal_hold     │
│ drop_backup_set  │                  │ list_backup_sets      │
└──────────────────┴──────────────────┴───────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│              Snowflake Stored Procedures                     │
│              BACKUP_AGENT_DB.BACKUP_TOOLS.*                  │
└─────────────────────────────────────────────────────────────┘
Usage
Interacting with the Agent
Navigate to Agents in Snowsight and select BACKUP_ASSISTANT, or query programmatically:
SELECT SNOWFLAKE.CORTEX.INVOKE_AGENT(
    'BACKUP_AGENT_DB.BACKUP_TOOLS.BACKUP_ASSISTANT',
    'Create a backup set for my_database.my_schema.customers table'
);

Example Conversations
Creating a Table Backup Set:

"Create a backup set called CUSTOMERS_BACKUPS for the table SALES_DB.PUBLIC.CUSTOMERS"

Setting Up Automated Backups:

"Create a daily backup policy with 30-day retention and apply it to CUSTOMERS_BACKUPS"

Restoring from Backup:

"List the backups in CUSTOMERS_BACKUPS and restore the most recent one to CUSTOMERS_RESTORED"

Managing Legal Holds:

"Add a legal hold to the backup from January 15th in CUSTOMERS_BACKUPS"

Cost Estimation
Backup storage is billed at approximately $23/TB/month. Use this query to monitor costs:
Important Notes
Restore Limitations: Backups can only be restored to new object names—you cannot overwrite existing objects.

Delete Order: Only the oldest backup without a legal hold can be deleted from a backup set.

Retention Lock: Backup sets with retention locks cannot be dropped while containing unexpired backups.

Legal Holds: Backups under legal hold are exempt from automatic expiration.

Dependencies: When backing up tables with dependencies (foreign keys, sequences), ensure referenced objects exist when restoring.

Troubleshooting
"Backup set not found"
Ensure you're using the correct backup set name and have appropriate permissions.

"Cannot delete backup"
Only the oldest backup without legal hold can be deleted. Check is_under_legal_hold column.

"Sequence not found after restore"
Table references external objects. Restore the dependency first or use schema/database-level backups.

File Structure
Contributing
Fork the repository
Create a feature branch
Submit a pull request
License
MIT License

Support
For issues and questions:

Create a GitHub issue
Snowflake Community Forums
Snowflake Support (for account-specific issues)
Changelog
v1.0.0 (2026-03-05)
Initial release
16 backup management tools
Support for table, schema, and database backups
Three pre-configured backup policies
Legal hold support for compliance

this can be found on my Github : wondisha/Backup_Assistance_Agentic_AI
reddit.com
u/Upstairs-Cup-8666 — 12 days ago
▲ 2 r/u_Upstairs-Cup-8666+1 crossposts

Have used COCO to create Session Monitor Dashboard

What It Does

Session Policy Management

  • Creates and applies strict session policies (idle timeout + max lifespan)
  • Separate tighter policy for admin users
  • Policy modification and reference tracking

Session Monitoring Dashboard (Last 7 Days)

  • KPI Cards: Total sessions, open/closed counts, distinct users
  • Daily Trend: Sessions per day with unique user overlay
  • Auth Method Breakdown: Pie chart of authentication methods
  • Client Applications: Top 10 clients generating sessions
  • Close Reasons: Color-coded session termination analysis
  • Hourly Distribution: Session creation by hour of day (UTC)
  • Top Users: Session count per user (total vs. open)

Extended Analysis

  • Long-lived open sessions ranked by age with risk levels (CRITICAL >8h, WARNING >4h, ELEVATED >1h)
  • Warehouse idle cost: Query credits vs. idle credits per warehouse with estimated USD waste
  • Daily idle cost trend: Stacked bar chart with idle % overlay

Automated Email Alerts

  • Notification integration sends alerts to configured email
  • Stored procedure checks for:
    • Sessions open longer than 4 hours
    • Warehouses with >80% idle credits in last 24 hours
  • Includes wasted cost ($) in subject line and body
  • Actionable suggestions for both sessions and warehouses
  • Hourly scheduled task via Snowflake CRON

Alert Email Sample

Subject: [Snowflake Alert] Idle Sessions & Warehouses | Wasted: $123.08

LONG-LIVED SESSIONS (249 sessions open > 4 hours)
- SFANALYST | PythonSnowpark 1.47.0 | Age: 24.5h | Idle: 250 min

SUGGESTIONS:
  - Review session policies
  - Terminate stale sessions: SELECT SYSTEM$ABORT_SESSION(<session_id>)

IDLE WAREHOUSES (1 warehouses > 80% idle | Total wasted: $123.08 in 24h)
- COMPUTE_WH | Compute: 30.77 cr | Idle: 97.8% | Wasted: $123.08

SUGGESTIONS:
  - Reduce auto-suspend: ALTER WAREHOUSE <name> SET AUTO_SUSPEND = 60;
  - Downsize: ALTER WAREHOUSE <name> SET WAREHOUSE_SIZE = XSMALL;             

https://preview.redd.it/61hg1n3qtyxg1.png?width=1667&format=png&auto=webp&s=0066e0d2a58e9e3a0c6a5e6a7465dce6da3b9497

reddit.com
u/Upstairs-Cup-8666 — 25 days ago