From 23b2141b6494d88af8ecd6b7a0d8326fe9682251 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sun, 30 Nov 2025 08:18:05 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 15 +++ README.md | 3 + commands/backup.md | 120 ++++++++++++++++++ plugin.lock.json | 61 +++++++++ skills/database-backup-automator/SKILL.md | 54 ++++++++ .../assets/README.md | 7 + .../references/README.md | 10 ++ .../scripts/README.md | 8 ++ 8 files changed, 278 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 commands/backup.md create mode 100644 plugin.lock.json create mode 100644 skills/database-backup-automator/SKILL.md create mode 100644 skills/database-backup-automator/assets/README.md create mode 100644 skills/database-backup-automator/references/README.md create mode 100644 skills/database-backup-automator/scripts/README.md diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..f6779e1 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,15 @@ +{ + "name": "database-backup-automator", + "description": "Automate database backups with scheduling, compression, encryption, and restore procedures", + "version": "1.0.0", + "author": { + "name": "Claude Code Plugins", + "email": "[email protected]" + }, + "skills": [ + "./skills" + ], + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3eec1d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# database-backup-automator + +Automate database backups with scheduling, compression, encryption, and restore procedures diff --git a/commands/backup.md b/commands/backup.md new file mode 100644 index 0000000..6b7f433 --- /dev/null +++ b/commands/backup.md @@ -0,0 +1,120 @@ +--- +description: Create automated database backup scripts and schedules +--- + +# Database Backup Automator + +You are a database backup specialist. Create comprehensive backup solutions with automation, monitoring, and recovery procedures. + +## Backup Strategy Components + +1. **Backup Types** + - Full backups: Complete database dump + - Incremental: Changes since last backup + - Differential: Changes since last full backup + - Point-in-time recovery: Transaction log backups + +2. **Automation Setup** + - Cron jobs for scheduled backups + - Pre-backup validation checks + - Post-backup verification + - Retention policies + - Rotation strategies + +3. **Storage Options** + - Local storage with rotation + - Cloud storage (S3, GCS, Azure) + - Network attached storage + - Offsite replication + +4. **Security Measures** + - Encryption at rest + - Encryption in transit + - Access control + - Audit logging + +## Backup Script Template (PostgreSQL) + +```bash +#!/bin/bash +# PostgreSQL Backup Script + +BACKUP_DIR="/var/backups/postgresql" +DB_NAME="mydb" +DATE=$(date +%Y%m%d_%H%M%S) +BACKUP_FILE="$BACKUP_DIR/${DB_NAME}_${DATE}.sql.gz" +RETENTION_DAYS=7 + +# Create backup +pg_dump $DB_NAME | gzip > $BACKUP_FILE + +# Verify backup +if [ $? -eq 0 ]; then + echo "Backup successful: $BACKUP_FILE" + + # Remove old backups + find $BACKUP_DIR -name "${DB_NAME}_*.sql.gz" -mtime +$RETENTION_DAYS -delete + + # Upload to S3 (optional) + # aws s3 cp $BACKUP_FILE s3://my-backups/postgresql/ +else + echo "Backup failed!" + exit 1 +fi +``` + +## Restore Procedure Template + +```bash +#!/bin/bash +# PostgreSQL Restore Script + +BACKUP_FILE=$1 + +if [ -z "$BACKUP_FILE" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Restore database +gunzip < $BACKUP_FILE | psql $DB_NAME + +if [ $? -eq 0 ]; then + echo "Restore successful" +else + echo "Restore failed!" + exit 1 +fi +``` + +## Cron Schedule Examples + +```cron +# Daily backup at 2 AM +0 2 * * * /path/to/backup.sh + +# Hourly incremental backups +0 * * * * /path/to/incremental_backup.sh + +# Weekly full backup on Sunday at 3 AM +0 3 * * 0 /path/to/full_backup.sh +``` + +## Monitoring Checklist + +- Backup completion status +- Backup file size tracking +- Storage space monitoring +- Failed backup alerts +- Restore testing schedule +- Recovery time objectives (RTO) +- Recovery point objectives (RPO) + +## When Invoked + +1. Identify database system (PostgreSQL, MySQL, MongoDB, etc.) +2. Determine backup frequency and retention +3. Generate backup scripts +4. Create restore procedures +5. Set up monitoring and alerts +6. Provide testing instructions diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..7c4f0b6 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,61 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:jeremylongshore/claude-code-plugins-plus:plugins/database/database-backup-automator", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "da95e65c7cc114f3b563a2007bc59ef87e293588", + "treeHash": "aefd50dce42576aa71b1a3debf3e0f416871e4029feab8ce26efbf0e04cf2b8f", + "generatedAt": "2025-11-28T10:18:18.670428Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "database-backup-automator", + "description": "Automate database backups with scheduling, compression, encryption, and restore procedures", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "c5fdfcaaac59e456204472fcce0bf72512703361ff1f32c6361cce12c469c684" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "7b4ae20ba366a3c4049692d3c3ff4c2deff8624d87d03648e7ffe5b3b274a3ba" + }, + { + "path": "commands/backup.md", + "sha256": "6d30d6c8c08c6df391bca4f6b77c6bf944b6eda80accb6c0826b7075ee753db3" + }, + { + "path": "skills/database-backup-automator/SKILL.md", + "sha256": "ab63d7ea093d1c2ae4074dc0810b11d905de1a9b90ced85cb44a1dffc9abf5db" + }, + { + "path": "skills/database-backup-automator/references/README.md", + "sha256": "5edb7f3867d414d31b2dc36a1f73887a5eef2e030a29e9ba13776638e43890fb" + }, + { + "path": "skills/database-backup-automator/scripts/README.md", + "sha256": "9d686acba9e332b5ff6204ee8ff2238d9e861ba485195ed0dfe60e9314acf0f3" + }, + { + "path": "skills/database-backup-automator/assets/README.md", + "sha256": "7886ad741ee5dd09057b8033954b61d265f8cf85b052c537e80e1cb9ac8bc13c" + } + ], + "dirSha256": "aefd50dce42576aa71b1a3debf3e0f416871e4029feab8ce26efbf0e04cf2b8f" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/database-backup-automator/SKILL.md b/skills/database-backup-automator/SKILL.md new file mode 100644 index 0000000..7f3a502 --- /dev/null +++ b/skills/database-backup-automator/SKILL.md @@ -0,0 +1,54 @@ +--- +name: automating-database-backups +description: | + This skill automates database backups using the database-backup-automator plugin. It creates scripts for scheduled backups, compression, encryption, and restore procedures across PostgreSQL, MySQL, MongoDB, and SQLite. Use this when the user requests database backup automation, disaster recovery planning, setting up backup schedules, or creating restore procedures. The skill is triggered by phrases like "create database backup", "automate database backups", "setup backup schedule", or "generate restore procedure". +allowed-tools: Read, Write, Edit, Grep, Glob, Bash +version: 1.0.0 +--- + +## Overview + +This skill streamlines the creation of database backup solutions. It generates scripts, configures schedules, and provides comprehensive restore procedures, ensuring data safety and efficient recovery. + +## How It Works + +1. **Analyze Requirements**: Determines the database type (PostgreSQL, MySQL, MongoDB, or SQLite) and backup requirements (frequency, retention). +2. **Generate Scripts**: Creates backup scripts with compression and encryption. +3. **Schedule Backups**: Sets up cron jobs for automated, scheduled backups. +4. **Document Restore**: Generates clear, concise restore procedures. + +## When to Use This Skill + +This skill activates when you need to: +- Create a backup schedule for a database. +- Automate the database backup process. +- Generate scripts for database restoration. +- Implement a disaster recovery plan for a database. + +## Examples + +### Example 1: Setting up Daily Backups for PostgreSQL + +User request: "Create daily backups for my PostgreSQL database." + +The skill will: +1. Generate a `pg_dump` script with compression and encryption. +2. Create a cron job to run the backup script daily. + +### Example 2: Automating Weekly Backups for MongoDB + +User request: "Automate weekly backups for my MongoDB database." + +The skill will: +1. Generate a `mongodump` script with compression and encryption. +2. Create a cron job to run the backup script weekly and implement a retention policy. + +## Best Practices + +- **Retention Policies**: Implement clear retention policies to manage storage space. +- **Testing Restores**: Regularly test restore procedures to ensure data integrity. +- **Secure Storage**: Store backups in secure, encrypted locations, preferably offsite. + +## Integration + +This skill can integrate with cloud storage plugins (S3, GCS, Azure) for offsite backup storage and monitoring plugins for backup success/failure alerts. \ No newline at end of file diff --git a/skills/database-backup-automator/assets/README.md b/skills/database-backup-automator/assets/README.md new file mode 100644 index 0000000..9a9f1df --- /dev/null +++ b/skills/database-backup-automator/assets/README.md @@ -0,0 +1,7 @@ +# Assets + +Bundled resources for database-backup-automator skill + +- [ ] backup_template.sh: A template shell script for performing backups. +- [ ] restore_template.sh: A template shell script for performing restores. +- [ ] example_backup_config.json: Example configuration file for defining backup schedules and parameters. diff --git a/skills/database-backup-automator/references/README.md b/skills/database-backup-automator/references/README.md new file mode 100644 index 0000000..671031f --- /dev/null +++ b/skills/database-backup-automator/references/README.md @@ -0,0 +1,10 @@ +# References + +Bundled resources for database-backup-automator skill + +- [ ] postgresql_backup_restore.md: Detailed guide on PostgreSQL backup and restore procedures. +- [ ] mysql_backup_restore.md: Detailed guide on MySQL backup and restore procedures. +- [ ] mongodb_backup_restore.md: Detailed guide on MongoDB backup and restore procedures. +- [ ] sqlite_backup_restore.md: Detailed guide on SQLite backup and restore procedures. +- [ ] backup_best_practices.md: General best practices for database backups, including security and storage considerations. +- [ ] cron_syntax.md: A quick reference guide to cron syntax for scheduling backups. diff --git a/skills/database-backup-automator/scripts/README.md b/skills/database-backup-automator/scripts/README.md new file mode 100644 index 0000000..fddd8cd --- /dev/null +++ b/skills/database-backup-automator/scripts/README.md @@ -0,0 +1,8 @@ +# Scripts + +Bundled resources for database-backup-automator skill + +- [ ] backup_script_generator.py: Generates backup scripts based on database type and user-defined parameters. +- [ ] restore_script_generator.py: Generates restore scripts based on backup location and database type. +- [ ] backup_scheduler.py: Creates and manages cron jobs for automated backups. +- [ ] backup_validator.py: Validates the integrity of the backup files.