The Problem This Tool Solves
Manual snapshot management is inefficient. Logging into storage appliances, navigating web interfaces, and performing repetitive snapshot operations wastes valuable time, especially when managing multiple filesystems.
Backup verification requires coordination. Teams often need to verify whether specific snapshots exist before running migration or backup tools. Without automation, this becomes a manual checklist item prone to human error.
Audit trails need standardization. Export controls and compliance requirements often demand documented proof of snapshot inventories, but manually compiling this data is tedious.
Key Benefits
- Control ZFS snapshots from any machine with network access
- Automatically generates CSV and JSON reports of snapshot inventories
- Enables automation for backup and verification tasks
- Integrates seamlessly into larger maintenance scripts or cron jobs
Real-World Use Cases
🤖 Automated backup scheduling
🔍 Pre-migration snapshot verification
Before running data migration tools like NetApp XCP, verify that required snapshots exist or automatically create them if missing.
📈 Storage capacity reporting
⚙️ Development environment management
Developers can quickly create snapshots before risky code deployments, then roll back if needed without involving storage admins.
Key Components Explained
Snapshot Creation Logic
def newsnap(storage, pool, project, filesys, snap_name):
response_data = {}
headers = get_headers()
base_url = f'https://{storage}:215'
payload = {
"name": snap_name,
"retention": "unlocked"
}
json_dump = json.dumps(payload)
url = f'{base_url}/api/storage/v1/pools/{pool}/projects/{project}/filesystems/{filesys}/snapshots'
resp = requests.post(url=url, data=json_dump, verify=False, headers=headers, timeout=30)
The function constructs a JSON payload with the snapshot name and retention policy, then sends a POST request to the appliance. If the API returns HTTP 201 (created) or 409 (already exists), the tool prints True and exports the current snapshot inventory. This design ensures idempotency—running the same create command multiple times won’t fail or corrupt data.
XCP Snapshot Discovery
One specialized feature is XCP snapshot detection. NetApp’s XCP migration tool creates snapshots with specific naming conventions. The find_xcp() function checks whether a particular XCP snapshot exists and creates it automatically if missing:
def find_xcp(storage, pool, project, filesys, snap_name):
headers = get_headers()
base_url = f'https://{storage}:215'
url = f'{base_url}/api/storage/v1/pools/{pool}/projects/{project}/filesystems/{filesys}/snapshots'
resp = requests.get(url=url, verify=False, headers=headers, timeout=30)
snapshots = resp.json().get("snapshots", [])
for snapshot in snapshots:
if snapshot.get('name') == snap_name:
print(bool(1))
break
else:
print("Creating Snapshot ....")
newsnap(storage, pool, project, filesys, snap_name)
This function searches the snapshot list for an exact name match. If found, it returns True. If not found, it automatically triggers snapshot creation—a convenient workflow for pre-migration checks.
Get the Script: Access the GitHub Repository
- Full source code with extensive comments
- Detailed installation instructions
- Advanced usage scenarios
- Documentation on extending the script for your specific needs
Getting Started
1. Prerequisites
# Required Python packages
pip install requests docopt
2. Installation
Clone or download the project directory structure:
snapshotool/
├── tool.py
└── utils/
├── parser.py
└── utils.py
Before running commands, update the authentication credentials in parser.py:
headers = {
"X-Auth-User": 'root',
"X-Auth-Key": 'your_password_here'
}
Usage Examples
Create a snapshot:
python tool.py -s storage01.company.com -fs production_data -sp backup_20241117 --create
List all snapshots for a filesystem:
python tool.py -s storage01.company.com -fs production_data --list
Remove a specific snapshot:
python tool.py -s storage01.company.com -fs production_data -sp old_snapshot --remove
Check for any XCP-prefixed snapshots:
python tool.py -s storage01.company.com -fs migration_data --xcpfind
Verify or create a specific XCP snapshot:
python tool.py -s storage01.company.com -fs migration_data -sp xcp_baseline --xcp
Output Files
After each operation, the tool generates two files in your current directory:
- datafile.csv – A comma-separated table of snapshot details (name, creation time, space used)
- datafile.json – The complete JSON response from the storage API for programmatic parsing
These exports serve as audit trails and can be imported into spreadsheets or monitoring dashboards.
Extending the Tool
The modular design makes it straightforward to add new features. You could extend it to:
- Accept configuration files for commonly used storage appliances
- Add retention policy management beyond the default “unlocked” setting
- Implement bulk operations across multiple filesystems
- Schedule snapshot creation using Python’s
schedulelibrary - Send notifications to Slack or email after operations complete
Wrapping Up
This ZFS snapshot manager transforms manual storage administration into programmable infrastructure. By wrapping the ZFS REST API in a clean CLI, it enables storage engineers to automate backup workflows, integrate with migration tools, and generate compliance reports—all without ever opening a browser console.
The tool showcases practical Python development skills including REST API integration, command-line interface design, data serialization, and error handling. It solves a real operational pain point while remaining simple enough to modify and extend for specific organizational needs.
Whether you’re managing a handful of development filesystems or coordinating enterprise backup strategies across dozens of appliances, having snapshot management as code rather than clickops makes your infrastructure more reliable and your workday more productive.
