Skip to content

GitHub Copilot CLI — Backup Setup Procedure

What This Guide Covers

This guide explains how to set up automated dual backups for your GitHub Copilot CLI configuration — keeping copies in both Corp OneDrive and Personal Google Drive.

Why two backups?

Cloud Café analogy: Imagine you keep all your café recipes, training manuals, and staff records in the office safe (Corp OneDrive). But what if you move to a new kitchen (new device)? By keeping a second copy in your personal safe (Google Drive), you can set up a new device in minutes — no rebuilding from scratch.


What Gets Backed Up

Item Description Location
Custom instructions Your personalised Copilot CLI behaviour rules ~\.copilot\ config files
Session history Past session states and context ~\.copilot\session-state\
Learning progress Your learning tracker file ~\.copilot\ subfolder
Learning docs source MkDocs Markdown files (your learning portal content) C:\ssClawy\learning-docs\docs\

What is NOT backed up (on purpose)

  • mcp-servers/ — These are installed packages, not config (can be reinstalled)
  • logs/ — Temporary session logs (not needed for restore)
  • site/ — The built website (regenerated from source with mkdocs build)

Architecture Overview

┌─────────────────────────────┐
│  Your PC (~\.copilot\)      │
│  + learning-docs\           │
└─────────┬───────────────────┘
          │  Daily at 9 AM (Scheduled Task)
┌─────────────────────────────┐
│  Corp OneDrive              │
│  ~/OneDrive - Microsoft/    │
│    CopilotCLI_Backups/      │
│    ├── backup_2026-03-27_*  │  ← timestamped snapshots (last 30 kept)
│    ├── backup_2026-03-28_*  │
│    └── learning-docs-backup │  ← latest copy of learning docs
└─────────┬───────────────────┘
          │  Automatic mirror (robocopy /MIR)
┌─────────────────────────────┐
│  Google Drive               │
│  G:\My Drive\               │
│    CopilotCLI_Backups\      │  ← exact mirror of Corp OneDrive backup
└─────────────────────────────┘

Setup Steps

Step 1 — Create the Backup Script

This PowerShell script does three things:

  1. Copies your .copilot config to Corp OneDrive (timestamped folder)
  2. Copies your learning-docs source to Corp OneDrive
  3. Mirrors everything to Google Drive

Create the file at ~\.copilot\backup-instructions.ps1:

# === COPILOT CLI BACKUP SCRIPT ===
# Runs daily via Windows Scheduled Task
# Backs up config to Corp OneDrive, then mirrors to Google Drive

$copilotDir = "$env:USERPROFILE\.copilot"
$backupDir = "$env:USERPROFILE\OneDrive - Microsoft\CopilotCLI_Backups"
$timestamp = Get-Date -Format 'yyyy-MM-dd_HHmmss'
$backupFolder = "$backupDir\backup_$timestamp"

if (Test-Path $copilotDir) {
    if (!(Test-Path $backupDir)) {
        New-Item -ItemType Directory -Path $backupDir -Force | Out-Null
    }

    # Keep only last 30 backups (cleanup old ones)
    $existing = Get-ChildItem "$backupDir\backup_*" -Directory -ErrorAction SilentlyContinue |
        Sort-Object LastWriteTime -Descending | Select-Object -Skip 30
    $existing | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue

    # Folders to exclude (large or temporary)
    $excludeDirs = @('mcp-servers', 'logs', 'backups', 'restart')

    # Create timestamped backup folder
    New-Item -ItemType Directory -Path $backupFolder -Force | Out-Null

    # Copy config files (top-level files)
    Get-ChildItem "$copilotDir\*" -File | ForEach-Object {
        Copy-Item $_.FullName "$backupFolder\" -Force
    }

    # Copy config folders (excluding large/temporary ones)
    Get-ChildItem "$copilotDir" -Directory | Where-Object {
        $_.Name -notin $excludeDirs
    } | ForEach-Object {
        Copy-Item $_.FullName "$backupFolder\$($_.Name)" -Recurse -Force
    }
}

# Backup learning-docs (Markdown source only, not the built site/)
$learningDocsDir = "C:\ssClawy\learning-docs"
if (Test-Path $learningDocsDir) {
    $docsBackup = "$backupDir\learning-docs-backup"

    # Replace with latest copy each time
    if (Test-Path $docsBackup) { Remove-Item $docsBackup -Recurse -Force }
    New-Item -ItemType Directory -Path $docsBackup -Force | Out-Null

    # Copy mkdocs.yml config
    Copy-Item "$learningDocsDir\mkdocs.yml" "$docsBackup\" -Force -ErrorAction SilentlyContinue

    # Copy docs/ folder (all Markdown content)
    if (Test-Path "$learningDocsDir\docs") {
        Copy-Item "$learningDocsDir\docs" "$docsBackup\docs" -Recurse -Force
    }
}

# --- Google Drive Mirror ---
# Mirrors the entire Corp OneDrive backup to personal Google Drive
$googleDriveBackup = "G:\My Drive\CopilotCLI_Backups"
if (Test-Path "G:\My Drive") {
    if (!(Test-Path $googleDriveBackup)) {
        New-Item -ItemType Directory -Path $googleDriveBackup -Force | Out-Null
    }
    # /MIR = exact mirror, /R:2 /W:1 = retry settings
    robocopy $backupDir $googleDriveBackup /MIR /R:2 /W:1 /NJH /NJS /NP /NFL /NDL /XF "Sync-ToGoogleDrive.ps1" | Out-Null
}

Step 2 — Create the Windows Scheduled Task

This makes the backup run automatically every day at 9:00 AM.

Open PowerShell as Administrator and run:

# Define the scheduled task
$action = New-ScheduledTaskAction `
    -Execute "pwsh.exe" `
    -Argument '-NoProfile -WindowStyle Hidden -File "C:\Users\ssutheesh\.copilot\backup-instructions.ps1"'

$trigger = New-ScheduledTaskTrigger -Daily -At "09:00"

$settings = New-ScheduledTaskSettingsSet `
    -AllowStartIfOnBatteries `
    -DontStopIfGoingOnBatteries `
    -StartWhenAvailable

# Register the task
Register-ScheduledTask `
    -TaskName "CopilotCLI_BackupInstructions" `
    -Action $action `
    -Trigger $trigger `
    -Settings $settings `
    -Description "Daily backup of Copilot CLI custom instructions to OneDrive"

What each flag means

Flag Plain English
-NoProfile Don't load your PowerShell profile (faster startup)
-WindowStyle Hidden Run silently in the background (no popup window)
-Daily -At "09:00" Run every day at 9 AM
-AllowStartIfOnBatteries Still runs on laptop battery
-StartWhenAvailable If you were offline at 9 AM, runs when you're back

Step 3 — Set Up Google Drive (One-Time)

Prerequisites:

Create the Google Drive backup folder:

New-Item -ItemType Directory -Path "G:\My Drive\CopilotCLI_Backups" -Force

Do an initial sync:

robocopy "$env:USERPROFILE\OneDrive - Microsoft\CopilotCLI_Backups" "G:\My Drive\CopilotCLI_Backups" /MIR /R:2 /W:1

After this, the daily scheduled task handles everything automatically.


Step 4 (Optional) — Manual Sync Script

If you ever want to sync on-demand (between scheduled runs), there's a helper script:

Location: ~\OneDrive - Microsoft\CopilotCLI_Backups\Sync-ToGoogleDrive.ps1

Run it with:

& "$env:USERPROFILE\OneDrive - Microsoft\CopilotCLI_Backups\Sync-ToGoogleDrive.ps1"

How to Verify It's Working

Check the scheduled task is running

Get-ScheduledTask -TaskName "CopilotCLI_BackupInstructions" | Select-Object TaskName, State

Expected output: State = Ready

Check backup folder contents

# Corp OneDrive backups
Get-ChildItem "$env:USERPROFILE\OneDrive - Microsoft\CopilotCLI_Backups\backup_*" -Directory |
    Sort-Object LastWriteTime -Descending | Select-Object Name, LastWriteTime -First 5

# Google Drive mirror
Get-ChildItem "G:\My Drive\CopilotCLI_Backups\backup_*" -Directory |
    Sort-Object LastWriteTime -Descending | Select-Object Name, LastWriteTime -First 5

Compare file counts (should match)

$corp = (Get-ChildItem "$env:USERPROFILE\OneDrive - Microsoft\CopilotCLI_Backups" -Recurse -File).Count
$google = (Get-ChildItem "G:\My Drive\CopilotCLI_Backups" -Recurse -File).Count
Write-Host "Corp OneDrive: $corp files | Google Drive: $google files"

How to Restore on a New Device

If you get a new device (personal or corp), follow these steps to restore everything:

1. Install Google Drive for Desktop

Download from google.com/drive/download and sign in. Your backup will sync to G:\My Drive\CopilotCLI_Backups\.

2. Install GitHub Copilot CLI

# Install GitHub Copilot CLI (requires Node.js)
npm install -g @githubnext/github-copilot-cli

3. Restore your config

# Find the latest backup snapshot
$latestBackup = Get-ChildItem "G:\My Drive\CopilotCLI_Backups\backup_*" -Directory |
    Sort-Object Name -Descending | Select-Object -First 1

# Copy it back to .copilot
Copy-Item "$($latestBackup.FullName)\*" "$env:USERPROFILE\.copilot\" -Recurse -Force

Write-Host "Restored from: $($latestBackup.Name)"

4. Restore learning docs

# Copy learning docs source back
$docsBackup = "G:\My Drive\CopilotCLI_Backups\learning-docs-backup"
Copy-Item "$docsBackup\*" "C:\ssClawy\learning-docs\" -Recurse -Force

5. Rebuild the learning portal site

cd C:\ssClawy\learning-docs
pip install mkdocs-material
mkdocs build

Key Concepts Explained

Term What it means
robocopy /MIR "Mirror" — makes the destination an exact copy of the source. Adds new files, updates changed files, and removes files that no longer exist in the source
Scheduled Task A Windows feature that runs a script automatically at a set time — like an alarm clock for your computer
Timestamped backup Each backup is saved in a folder named with the date/time (e.g., backup_2026-03-28_090002), so you can go back to any point in time
30-backup retention Only the last 30 backups are kept — older ones are automatically deleted to save space

Summary

Your Copilot CLI config is backed up automatically every day to two cloud locations. If you ever switch devices, you can restore everything in under 5 minutes using the steps above.