Skip to content

NaseerAkbari/zfs-authomation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

ZFS Snapshot Manager 🚀

A powerful and safe shell script for managing ZFS snapshots on Linux systems. Perfect for system administrators and developers who need reliable backup and recovery capabilities.

🌟 Features

  • Create Snapshots - Timestamped manual snapshots
  • List Snapshots - View all available snapshots with creation dates
  • Safe Revert - Revert to snapshots with automatic backups
  • Destructive Rollback - Clean up snapshot chains when needed
  • Delete Snapshots - Remove individual snapshots safely
  • Cleanup - Keep only the most recent snapshots
  • Auto-completion - Use short snapshot names or full paths
  • Safety First - Multiple confirmation prompts for dangerous operations

🛠️ Requirements

  • Linux system with ZFS support
  • Root privileges
  • ZFS filesystem (tested on ZFS root systems)

📋 Supported ZFS Configurations

This script works with:

  • ZFS Root Systems (like your current setup: rpool/ROOT/zfsroot)
  • Non-root ZFS datasets
  • Any standard ZFS configuration

About Your ZFS Root Setup

Your system uses ZFS as the root filesystem:

sda2 (99.5G) → ZFS Pool 'rpool' → Dataset 'rpool/ROOT/zfsroot' mounted as /

This is an advanced setup that provides excellent snapshot capabilities for your entire system!

🚀 Quick Start

# Make executable
chmod +x zfs-snapshot-manager.sh

# View help
sudo ./zfs-snapshot-manager.sh help

💡 Usage Examples

Basic Operations

# List all snapshots
sudo ./zfs-snapshot-manager.sh list

# Create a snapshot
sudo ./zfs-snapshot-manager.sh create

# Delete a snapshot (auto-completes name)
sudo ./zfs-snapshot-manager.sh delete manual_20251027_132704

Recovery Operations

# Safe revert (recommended) - keeps intermediate snapshots + creates backup
sudo ./zfs-snapshot-manager.sh revert manual_20251027_132704

# Destructive rollback - removes intermediate snapshots, no backup
sudo ./zfs-snapshot-manager.sh rollback manual_20251027_132704

Maintenance

# Keep only 5 most recent snapshots
sudo ./zfs-snapshot-manager.sh cleanup 5

🛡️ Safety Guide

When to Use REVERT (Safe) 🔒

  • System recovery after failed updates
  • Testing configurations - easily go back
  • General use - always creates a backup
  • Preserves all intermediate snapshots

When to Use ROLLBACK (Dangerous) ⚠️

  • Cleaning up snapshot chains
  • When you're absolutely sure you don't need intermediate snapshots
  • Disk space recovery - removes intermediate snapshots
  • No backup created

🎯 Real-World Scenarios

Scenario 1: Safe System Update

# 1. Create snapshot before update
sudo ./zfs-snapshot-manager.sh create

# 2. Perform system update
sudo apt update && sudo apt upgrade

# 3. If something breaks, revert safely
sudo ./zfs-snapshot-manager.sh revert manual_20251027_132704

# 4. Reboot to complete revert
sudo reboot

Scenario 2: Cleanup Old Snapshots

# Keep only last 10 snapshots, delete older ones
sudo ./zfs-snapshot-manager.sh cleanup 10

🔧 Technical Details

Snapshot Naming

  • Format: rpool/ROOT/zfsroot@manual_YYYYMMDD_HHMMSS
  • Auto-completion: Use manual_20251027_132704 instead of full name

Root Filesystem Handling

  • No unmounting required for ZFS operations
  • Reboot recommended after reverting root filesystem
  • Uses native ZFS commands for maximum compatibility

❓ FAQ

Q: Can I use this on non-root ZFS datasets?
A: Yes! The script automatically detects and handles any ZFS dataset.

Q: What's the difference between revert and rollback?
A: Revert is safe (keeps snapshots + creates backup), rollback is destructive (removes intermediate snapshots).

Q: Do I need to reboot after reverting?
A: For root filesystem reverts, yes. For data datasets, usually not.

Q: How much space do snapshots use?
A: Snapshots use minimal space initially, growing only as files change.

🐛 Troubleshooting

Error: "target is busy"

  • This is normal for root filesystem - the script now handles this properly

Error: "Snapshot does not exist"

  • Use list command to see exact snapshot names
  • Or use auto-completion with short names

Error: "Permission denied"

  • Run with sudo - ZFS operations require root privileges

📝 License

MIT License - feel free to use and modify for your needs.

🤝 Contributing

Found a bug? Have a feature request? Open an issue or submit a PR!


💡 Pro Tip: Use snapshots before major system changes - they're like time machines for your system! 🕰️

This README provides:

  • Clear setup instructions for your ZFS root system
  • Practical examples for real-world use cases
  • Safety guidelines for different operations
  • Troubleshooting for common issues
  • Friendly tone with emojis and humor
  • Technical depth when needed

The script is indeed perfect for your ZFS root setup! 🎯

Made with ❤️ by Naseer Akbari

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages