Skip to main content

A tool for restoring EC2 instances from AMIs

Project description

EC2 Restore Tool

A powerful command-line tool for restoring EC2 instances from AMIs with advanced features and detailed reporting.

Features

  • Full Instance Restore: Create a new instance from an AMI while preserving network configuration
  • Volume-Level Restore: Restore specific volumes from an AMI to an existing instance
  • Detailed Progress Tracking: Real-time progress updates with rich console output
  • Comprehensive Reporting: Generate detailed restoration reports
  • Network Configuration Preservation: Maintain private IP addresses and network settings
  • Systems Manager Integration: Execute post-restore commands using AWS Systems Manager
  • Instance Metadata Backup: Automatic backup of instance metadata before restoration
  • Volume Change Visualization: Clear display of volume changes before and after restoration
  • Instance Change Tracking: Detailed comparison of instance configurations
  • Error Handling & Rollback: Robust error handling with automatic rollback capabilities

Installation

pip install ec2-restore

Version Information

To check the installed version of the tool:

ec2-restore --version

This will display the version in the format: ec2-restore, version X.X.X

Configuration

Create a config.yaml file in your working directory:

aws:
  profile: default  # AWS profile to use. If not specified, will use default profile
  region: us-east-1  # Default region, can be overridden by environment variable

restore:
  max_amis: 5  # Number of AMIs to show in selection
  backup_metadata: true  # Whether to backup instance metadata before restoration
  log_level: INFO  # Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  log_file: ec2_restore.log  # Log file path

systems_manager:
  enabled: true  # Whether to run Systems Manager commands after restore
  commands:  # List of commands to run after instance restore
    - name: "check os version"  # Friendly name for the command
      command: "cat /etc/os-release"  # The actual command to run
      timeout: 300  # Command timeout in seconds
      wait_for_completion: true  # Whether to wait for command completion
    - name: "check disk size"
      command: "df -kh"
      timeout: 300
      wait_for_completion: true
  document_name: "AWS-RunShellScript"  # Default SSM document to use
  output_s3_bucket: ""  # Optional S3 bucket for command output
  output_s3_prefix: ""  # Optional S3 prefix for command output

Usage Examples

Full Instance Restore

# Restore by instance ID
ec2-restore restore --instance-id i-1234567890abcdef0

# Restore by instance name
ec2-restore restore --instance-name my-instance

# Restore multiple instances
ec2-restore restore --instance-ids i-1234567890abcdef0,i-0987654321fedcba0

Example output for full instance restore:

✓ Getting details for instance i-1234567890abcdef0...
✓ Backing up instance metadata...
✓ Fetching available AMIs...

Available AMIs:
┌───────┬────────────────────┬───────────────────────┬────────────────────────────┐
│ Index │ AMI ID            │ Creation Date        │ Description                │
├───────┼────────────────────┼───────────────────────┼────────────────────────────┤
│ 1     │ ami-1234567890    │ 2024-03-15T10:30:00Z │ Production backup          │
│ 2     │ ami-0987654321    │ 2024-03-14T15:45:00Z │ Daily backup              │
└───────┴────────────────────┴───────────────────────┴────────────────────────────┘

Instance Changes Before Restore:
┌────────────────────┬────────────────────┬────────────────────┬──────────┐
│ Property           │ Previous Value     │ New Value          │ Status   │
├────────────────────┼────────────────────┼────────────────────┼──────────┤
│ Instance ID        │ i-1234567890abcdef0│ Pending            │ Pending  │
│ Instance Name      │ prod-server-1      │ prod-server-1      │ Preserved │
│ Instance Type      │ t2.micro           │ t2.micro           │ Preserved │
│ Private IP         │ 10.0.1.100         │ Pending            │ Pending  │
└────────────────────┴────────────────────┴────────────────────┴──────────┘

✓ Performing full instance restore...
✓ New instance created with ID: i-0987654321fedcba0
✓ Waiting for instance to be fully available...
✓ Getting new instance details...
✓ Getting AMI volumes for report...

Instance Changes After Restore:
┌────────────────────┬────────────────────┬────────────────────┬──────────┐
│ Property           │ Previous Value     │ New Value          │ Status   │
├────────────────────┼────────────────────┼────────────────────┼──────────┤
│ Instance ID        │ i-1234567890abcdef0│ i-0987654321fedcba0│ Changed  │
│ Instance Name      │ prod-server-1      │ prod-server-1      │ Preserved │
│ Instance Type      │ t2.micro           │ t2.micro           │ Preserved │
│ Private IP         │ 10.0.1.100         │ 10.0.1.100         │ Preserved │
└────────────────────┴────────────────────┴────────────────────┴──────────┘

Volume Restore

# Restore specific volumes
ec2-restore restore --instance-id i-1234567890abcdef0 --restore-type volume

Example output for volume restore:

✓ Getting details for instance i-1234567890abcdef0...
✓ Backing up instance metadata...
✓ Fetching available AMIs...

Available AMIs:
┌───────┬────────────────────┬───────────────────────┬────────────────────────────┐
│ Index │ AMI ID            │ Creation Date        │ Description                │
├───────┼────────────────────┼───────────────────────┼────────────────────────────┤
│ 1     │ ami-1234567890    │ 2024-03-15T10:30:00Z │ Production backup          │
└───────┴────────────────────┴───────────────────────┴────────────────────────────┘

Current Volume Configuration:
┌───────┬──────────┬───────────┬──────────┬──────────────────────┐
│ Index │ Device   │ Size (GB) │ Type     │ Delete on Termination │
├───────┼──────────┼───────────┼──────────┼──────────────────────┤
│ 1     │ /dev/sda1│ 8         │ gp2      │ True                 │
│ 2     │ /dev/sdb │ 20        │ gp3      │ False                │
└───────┴──────────┴───────────┴──────────┴──────────────────────┘

✓ Performing volume restore...
✓ Volume restore completed successfully

Volume Changes:
┌──────────┬────────────────────┬────────────────────┬──────────┐
│ Device   │ Previous Volume ID │ New Volume ID      │ Status   │
├──────────┼────────────────────┼────────────────────┼──────────┤
│ /dev/sda1│ vol-1234567890    │ vol-0987654321     │ Changed  │
│ /dev/sdb │ vol-2345678901    │ vol-1098765432     │ Changed  │
└──────────┴────────────────────┴────────────────────┴──────────┘

Options

  • --instance-id: EC2 instance ID to restore
  • --instance-name: EC2 instance name (tag) to restore
  • --instance-ids: Comma-separated list of EC2 instance IDs to restore
  • --restore-type: Type of restore (full or volume)
  • --config: Path to configuration file (default: config.yaml)
  • --version or -v: Display version information

Development

  1. Clone the repository:
git clone https://github.com/jyothishkshatri/ec2-restore.git
cd ec2-restore
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install development dependencies:
pip install -e ".[dev]"

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ec2_restore-1.0.6.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ec2_restore-1.0.6-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file ec2_restore-1.0.6.tar.gz.

File metadata

  • Download URL: ec2_restore-1.0.6.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ec2_restore-1.0.6.tar.gz
Algorithm Hash digest
SHA256 a97e2b3ea4c018873de5b351995d7308400c1ee2b8cc65a2dd3abc43ed0323f8
MD5 ad5eb077d460a8dfdf6501569f40439a
BLAKE2b-256 c407c864089f38523826095f5b25c99dec37f475551ff16cbbe1ac2103a9520a

See more details on using hashes here.

File details

Details for the file ec2_restore-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: ec2_restore-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ec2_restore-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 653cb86a1c8e9616c5125f252a40f1de9ee0d8afdb5dca8501a6c2aa7d7c2b4e
MD5 1cc40ccac3de951d62ef843ef8fe8140
BLAKE2b-256 a369be329d681fbe65f7639a66bb0a774e21e767d8c967920607480497a382a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page