Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Backup Template

The backup template provides automated file archiving and restoration capabilities, helping you protect important data with scheduled backups and easy recovery options.

Topic: File Backup & Recovery

This template is perfect for:

  • Automated data protection
  • Scheduled file archiving
  • Disaster recovery preparation
  • Compliance with data retention policies

The Code

ADD TOOL "backup-to-server"
ADD TOOL "restore-file"
ADD TOOL "list-archived"
ADD TOOL "cleanup-old"

CLEAR SUGGESTIONS

ADD SUGGESTION "backup" AS "Run backup now"
ADD SUGGESTION "list" AS "View archived files"
ADD SUGGESTION "restore" AS "Restore a file"
ADD SUGGESTION "status" AS "Backup status"

SET CONTEXT "backup" AS "You are a backup management assistant. Help users archive files to server storage, restore archived files, and manage backup schedules."

BEGIN TALK
**Backup Manager**

I can help you with:
• Archive files to server storage
• Restore archived files
• View backup history
• Manage backup schedules

Select an option or tell me what you need.
END TALK

BEGIN SYSTEM PROMPT
You are a backup management assistant.

Archive files older than specified days to server storage.
Track all backup operations in log.xlsx.
Support restore operations from archived files.
Maintain MD5 checksums for integrity verification.
END SYSTEM PROMPT

Sample Dialogs

These conversations show how the backup template works in real-world scenarios.

Dialog 1: Running a Backup

Dialog 2: Viewing Archived Files

Dialog 3: Restoring a File

Keywords Used

KeywordPurpose
ADD TOOLRegister backup tools for AI to use
ADD SUGGESTIONCreate quick action buttons
SET CONTEXTDefine the bot’s role and capabilities
BEGIN TALKWelcome message block
BEGIN SYSTEM PROMPTAI behavior instructions

Backup Tool: backup-to-server.bas

PARAM folder AS STRING LIKE "documents" DESCRIPTION "Folder to backup"
PARAM days AS INTEGER LIKE 30 DESCRIPTION "Archive files older than X days"

DESCRIPTION "Archive files older than specified days to server storage"

IF NOT folder THEN
    folder = "documents"
END IF

IF NOT days THEN
    days = 30
END IF

' Calculate cutoff date
cutoff = DATEADD(NOW(), -days, "days")

' Find files to archive
files = FIND folder, "modified < '" + FORMAT(cutoff, "YYYY-MM-DD") + "'"

IF UBOUND(files) = 0 THEN
    TALK "No files found older than " + days + " days."
    RETURN 0
END IF

' Create archive name
archiveName = "backup-" + FORMAT(NOW(), "YYYY-MM-DD") + ".zip"

' Compress files
COMPRESS files, archiveName

' Calculate checksums
FOR EACH file IN files
    checksum = MD5(file)
    
    WITH logEntry
        timestamp = NOW()
        filename = file.name
        size = file.size
        md5 = checksum
        archive = archiveName
        status = "archived"
    END WITH
    
    SAVE "log.xlsx", logEntry
NEXT

' Move to server storage
MOVE archiveName, "server://backups/" + archiveName

TALK "✅ Backup completed: " + UBOUND(files) + " files archived to " + archiveName

RETURN UBOUND(files)

Restore Tool: restore-file.bas

PARAM filename AS STRING LIKE "report.xlsx" DESCRIPTION "Name of file to restore"
PARAM date AS STRING LIKE "2025-01-15" DESCRIPTION "Backup date to restore from" OPTIONAL

DESCRIPTION "Restore a file from archived backups"

' Search for file in backup logs
IF date THEN
    results = FIND "log.xlsx", "filename LIKE '%" + filename + "%' AND archive LIKE '%" + date + "%'"
ELSE
    results = FIND "log.xlsx", "filename LIKE '%" + filename + "%'"
END IF

IF UBOUND(results) = 0 THEN
    TALK "No archived files found matching '" + filename + "'"
    RETURN NULL
END IF

IF UBOUND(results) > 1 AND NOT date THEN
    TALK "Found " + UBOUND(results) + " versions. Please specify which date:"
    FOR EACH result IN results
        TALK "• " + result.archive + " (" + FORMAT(result.timestamp, "MMM DD, YYYY") + ")"
    NEXT
    RETURN results
END IF

' Get the archive
archive = results[1].archive
originalChecksum = results[1].md5

' Download from server
DOWNLOAD "server://backups/" + archive, archive

' Extract the specific file
EXTRACT archive, filename, "restored/"

' Verify checksum
restoredChecksum = MD5("restored/" + filename)

IF restoredChecksum = originalChecksum THEN
    TALK "✅ File restored and verified: restored/" + filename
ELSE
    TALK "⚠️ Warning: Checksum mismatch. File may be corrupted."
END IF

' Log restoration
WITH logEntry
    timestamp = NOW()
    action = "restore"
    filename = filename
    archive = archive
    verified = (restoredChecksum = originalChecksum)
END WITH

SAVE "log.xlsx", logEntry

RETURN "restored/" + filename

How It Works

  1. Tool Registration: ADD TOOL makes backup functions available to the AI
  2. Quick Actions: ADD SUGGESTION creates one-tap backup options
  3. Context Setting: Defines the bot as a backup management assistant
  4. File Scanning: Finds files matching age criteria
  5. Compression: Creates ZIP archives with checksums
  6. Logging: Tracks all operations in log.xlsx
  7. Restoration: Extracts files and verifies integrity

Scheduling Backups

Set up automated backups with scheduled jobs:

PARAM jobname AS STRING DESCRIPTION "Name of the backup job"

IF jobname = "daily backup" THEN
    SET SCHEDULE "0 2 * * *"  ' Run at 2 AM daily
    
    ' Backup documents folder
    CALL backup-to-server("documents", 7)
    
    ' Backup reports folder
    CALL backup-to-server("reports", 30)
    
    ' Send confirmation
    SEND MAIL "admin@company.com", "Daily Backup Complete", "Backup completed at " + NOW()
END IF

IF jobname = "weekly cleanup" THEN
    SET SCHEDULE "0 3 * * 0"  ' Run at 3 AM on Sundays
    
    ' Remove backups older than 90 days
    CALL cleanup-old(90)
    
    SEND MAIL "admin@company.com", "Weekly Cleanup Complete", "Old backups removed"
END IF

Customization Ideas

Add Email Notifications

' After backup completes
SEND MAIL "admin@company.com", "Backup Report", 
    "Files archived: " + fileCount + "\n" +
    "Total size: " + totalSize + " MB\n" +
    "Archive: " + archiveName

Add Backup Verification

' Verify backup integrity
FOR EACH entry IN FIND("log.xlsx", "archive = '" + archiveName + "'")
    originalFile = GET entry.filename
    archivedChecksum = entry.md5
    
    IF MD5(originalFile) <> archivedChecksum THEN
        TALK "⚠️ Warning: " + entry.filename + " has changed since backup"
    END IF
NEXT

Add Storage Monitoring

' Check available storage
storageUsed = FOLDER_SIZE("server://backups/")
storageLimit = 10000  ' 10 GB in MB

IF storageUsed > storageLimit * 0.9 THEN
    TALK "⚠️ Storage is 90% full. Consider cleaning old backups."
    SEND MAIL "admin@company.com", "Storage Warning", "Backup storage is almost full"
END IF