Validating SSH Certificates with a Local CA Using Python

This Bash script is designed to delete old RBD (RADOS Block Device) volumes in a specified pool (in this case, the backup pool) based on their 'age' which is determined by the modify_timestamp popery derived from rbd info

 1
 2#!/bin/bash
 3
 4# Set the pool name
 5POOL_NAME="backup"
 6
 7# Get the current date in seconds since the epoch
 8CURRENT_DATE=$(date +%s)
 9
10# Set the number of days threshold
11DAYS_THRESHOLD=30
12
13# Convert days to seconds
14SECONDS_THRESHOLD=$((DAYS_THRESHOLD * 86400))
15
16# Function to delete volumes older than the threshold
17delete_old_volumes() {
18    local VOLUMES=("$@")
19    for VOLUME in "${VOLUMES[@]}"; do
20        # Get the modify_timestamp of the volume
21        MODIFY_TIMESTAMP=$(rbd info $POOL_NAME/$VOLUME | grep modify_timestamp | awk '{print $2, $3, $4, $5, $6}')
22
23        # Convert the modify_timestamp to seconds since the epoch
24        MODIFY_DATE=$(date -d "$MODIFY_TIMESTAMP" +%s)
25
26        # Calculate the age of the volume in seconds
27        AGE=$((CURRENT_DATE - MODIFY_DATE))
28        AGE_DAYS=$((AGE / 86400))
29
30        echo "Processing volume: $VOLUME"
31        echo "Modify timestamp: $MODIFY_TIMESTAMP"
32        echo "Volume age: $AGE_DAYS days"
33
34        # Check if the age is greater than the threshold
35        if [ $AGE -gt $SECONDS_THRESHOLD ]; then
36            echo "Volume $VOLUME is older than $DAYS_THRESHOLD days. Deleting..."
37
38            # Purge all snapshots of the volume
39            rbd snap purge $POOL_NAME/$VOLUME
40
41            # Delete the volume
42            rbd rm $POOL_NAME/$VOLUME
43
44            echo "Volume $VOLUME deleted."
45        else
46            echo "Volume $VOLUME is not older than $DAYS_THRESHOLD days. Skipping."
47        fi
48
49        echo "----------------------------------------"
50    done
51}
52
53# Get the list of volumes in the pool
54VOLUMES=($(rbd ls $POOL_NAME))
55
56# Calculate the number of volumes to process per thread
57TOTAL_VOLUMES=${#VOLUMES[@]}
58VOLUMES_PER_THREAD=$((TOTAL_VOLUMES / 5))
59
60# Split the volume list into chunks and process in parallel
61for ((i=0; i<5; i++)); do
62    START_INDEX=$((i * VOLUMES_PER_THREAD))
63    END_INDEX=$((START_INDEX + VOLUMES_PER_THREAD))
64
65    if [ $i -eq 4 ]; then
66        END_INDEX=$TOTAL_VOLUMES
67    fi
68
69    VOLUME_CHUNK=("${VOLUMES[@]:START_INDEX:END_INDEX-START_INDEX}")
70    delete_old_volumes "${VOLUME_CHUNK[@]}" &
71done
72
73# Wait for all background processes to complete
74wait