Step 1. Connect to SynetoOS appliance via SSH as admin
ssh admin@<your_ip_address_or_hostname>
Step 2. Become Super User
sudo su
Step 3. Create snapdestroy file
vi /tmp/snapdestroy
IMPORTANT
Make sure to copy and paste the exact lines below.#!/usr/bin/env python3 import subprocess def list_snapshots(pool, date): command = f"zfs list -H -t snapshot -o name -r {pool}/syn-volumes | grep {date}" result = subprocess.run(command, shell=True, capture_output=True, text=True) if result.returncode == 0: snapshots = result.stdout.strip().split('\n') return snapshots else: print(f"Error listing snapshots for pool '{pool}' and date '{date}': {result.stderr}") return [] def delete_snapshots(pool, snapshots): for snapshot in snapshots: delete_command = f"zfs destroy {snapshot}" result = subprocess.run(delete_command, shell=True) if result.returncode == 0: print(f"Snapshot '{snapshot}' deleted successfully.") else: print(f"Error deleting snapshot '{snapshot}': {result.stderr}") if __name__ == "__main__": import sys if len(sys.argv) != 3: print("Usage: python script.py <pool> <date>") sys.exit(1) pool = sys.argv[1] date = sys.argv[2] snapshots = list_snapshots(pool, date) if not snapshots: print(f"No snapshots found for date '{date}' in pool '{pool}'.") sys.exit(0) print("Snapshots found for deletion:") for snapshot in snapshots: print(snapshot) confirmation = input(f"Delete these {len(snapshots)} snapshots? (yes/no): ") if confirmation.lower() == "yes": delete_snapshots(pool, snapshots) else: print("Snapshots not deleted.")
Save and EXIT
:wq
Step 4. Give permissions to snapdestroy file
chmod +x /tmp/snapdestroy
Step 5. Delete the snapshots
Delete all snapshots for a specific year (replace <pool_name> and <year> with the correct pool name)
/tmp/snapdestroy <pool_name> <year>
EXAMPLE
/tmp/snapdestroy mypoolname 2023
NOTE
The system will ask for confirmation to delete snapshots before proceeding.
Delete all snapshots for a specific month (replace <pool_name> and <year-month> with the correct pool name)
/tmp/snapdestroy <pool_name> <year-month>
EXAMPLE
/tmp/snapdestroy mypoolname 2024-01
NOTE
The system will ask for confirmation to delete snapshots before proceeding.
Step 6. Delete the snapdestroy file after removing the snapshots
rm /tmp/snapdestroy