Creazione repo e aggiunta script dedicati a Pool ZFS
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Read me: prima di esecuzione fare chmod +x export_pool.sh
|
||||||
|
# Per l'utilizzo: ./export_pool.sh pool_name
|
||||||
|
|
||||||
|
if [ $# -ne 1 ]; then
|
||||||
|
echo "Usage: $0 <pool_name>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
pool_name=$1
|
||||||
|
|
||||||
|
# Function to check if a pool is imported and available
|
||||||
|
check_pool_imported() {
|
||||||
|
local name=$1
|
||||||
|
response=$(midclt call pool.query)
|
||||||
|
echo "$response" | grep -q "\"name\": \"${name}\""
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to get the pool ID by name
|
||||||
|
get_pool_id() {
|
||||||
|
local name=$1
|
||||||
|
midclt call pool.query '[["name", "=", "'"${name}"'"]]' | jq -r '.[0].id'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if the pool is imported and available
|
||||||
|
if ! check_pool_imported "$pool_name"; then
|
||||||
|
echo "Pool '${pool_name}' is not imported and available."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Starting export of pool '${pool_name}'..."
|
||||||
|
|
||||||
|
# Get pool ID for export
|
||||||
|
pool_id=$(get_pool_id "$pool_name")
|
||||||
|
|
||||||
|
# Start the pool export job
|
||||||
|
export_job_id=$(midclt call pool.export "$pool_id")
|
||||||
|
echo "Started pool export job with ID: $export_job_id"
|
||||||
|
|
||||||
|
# Poll until the export job is complete
|
||||||
|
while true; do
|
||||||
|
echo "Checking export job status..."
|
||||||
|
export_job_status=$(midclt call core.get_jobs "[[\"id\", \"=\", ${export_job_id}]]" | jq -r '.[0]')
|
||||||
|
export_state=$(echo $export_job_status | jq -r '.state')
|
||||||
|
echo "Export job state: $export_state"
|
||||||
|
|
||||||
|
if [ "$export_state" == "SUCCESS" ]; then
|
||||||
|
echo "Export job succeeded."
|
||||||
|
break
|
||||||
|
elif [ "$export_state" == "FAILED" ]; then
|
||||||
|
echo "Export job failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
# After export, double-check if the pool is no longer available
|
||||||
|
if check_pool_imported "$pool_name"; then
|
||||||
|
echo "Pool '${pool_name}' still found after export attempt. Error!"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Pool '${pool_name}' successfully exported and no longer available."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Read me: prima di esecuzione fare chmod +x import_pool.sh
|
||||||
|
# Per l'utilizzo: ./import_pool.sh pool_name
|
||||||
|
|
||||||
|
if [ $# -ne 1 ]; then
|
||||||
|
echo "Usage: $0 <pool_name>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
pool_name=$1
|
||||||
|
|
||||||
|
# Function to check if a pool is already imported
|
||||||
|
check_pool_imported() {
|
||||||
|
local name=$1
|
||||||
|
response=$(midclt call pool.query)
|
||||||
|
echo "$response" | grep -q "\"name\": \"${name}\""
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if the pool is already imported
|
||||||
|
if check_pool_imported "$pool_name"; then
|
||||||
|
echo "Pool '${pool_name}' is already imported and available."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start the import_find job and get the job ID
|
||||||
|
job_id=$(midclt call pool.import_find)
|
||||||
|
#echo "Started import_find job with ID: $job_id"
|
||||||
|
|
||||||
|
# Poll until the job is complete
|
||||||
|
while true; do
|
||||||
|
echo "Checking import job status..."
|
||||||
|
job_status=$(midclt call core.get_jobs '[["id", "=", '"$job_id"']]' | jq -r '.[0]')
|
||||||
|
state=$(echo $job_status | jq -r '.state')
|
||||||
|
echo "Import job state: $state"
|
||||||
|
if [ "$state" == "SUCCESS" ]; then
|
||||||
|
echo "Import job succeeded."
|
||||||
|
break
|
||||||
|
elif [ "$state" == "FAILED" ]; then
|
||||||
|
echo "Import job failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
# Extract the job result once it's complete
|
||||||
|
pools=$(echo $job_status | jq -r '.result')
|
||||||
|
|
||||||
|
# Find and import the pool with the specified name
|
||||||
|
found_pool=""
|
||||||
|
imported_pool=""
|
||||||
|
|
||||||
|
# Process each pool result using jq and a while loop
|
||||||
|
echo "$pools" | jq -c '.[]' | while read -r pool; do
|
||||||
|
name=$(echo "$pool" | jq -r '.name')
|
||||||
|
guid=$(echo "$pool" | jq -r '.guid')
|
||||||
|
if [ "$name" == "$pool_name" ]; then
|
||||||
|
found_pool=$name
|
||||||
|
import_job_id=$(midclt call pool.import_pool "{\"guid\": \"$guid\"}")
|
||||||
|
|
||||||
|
# Poll until the import job is complete
|
||||||
|
while true; do
|
||||||
|
import_job_status=$(midclt call core.get_jobs '[["id", "=", '"$import_job_id"']]' | jq -r '.[0]')
|
||||||
|
import_state=$(echo $import_job_status | jq -r '.state')
|
||||||
|
if [ "$import_state" == "SUCCESS" ]; then
|
||||||
|
break
|
||||||
|
elif [ "$import_state" == "FAILED" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Final check if the pool is imported
|
||||||
|
if check_pool_imported "$pool_name"; then
|
||||||
|
echo "Successfully imported pool: $pool_name"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Pool with name $pool_name not found or not imported"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Per refreshare dischi (se dopo collegamento o rimozione il kernel non si aggiorna)
|
||||||
|
echo "- - -" | sudo tee /sys/class/scsi_host/host*/scan
|
||||||
Reference in New Issue
Block a user