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.9.tar.gz (29.6 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.9-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ec2_restore-1.0.9.tar.gz
  • Upload date:
  • Size: 29.6 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.9.tar.gz
Algorithm Hash digest
SHA256 0e1bceced3fc2beaba05fedb4480fe58cfd7f717fabe41f8b5b9725f0ea5816a
MD5 a5766b627c9a99a878e3697b3894590a
BLAKE2b-256 1166ab4db64b41abd064ff2b531cbed87e6703159d9398823324537937a00b3e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ec2_restore-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 30.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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 09c5af3c14f1d9da8579d12de5e0f290818e25a338cf67a88af92a67a729a5cd
MD5 5d3becc6c12e106f17fa2f957ababcfd
BLAKE2b-256 7302079e72b7585c0df757ab738648c50bd2197f6c7477677cc6f88fa72537da

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