|
8 | 8 | ###################### |
9 | 9 | # SCRIPT VARIABLES # |
10 | 10 | ###################### |
11 | | -SNAPSCRIPTVERSION="3.4" #DEV |
| 11 | +SNAPSCRIPTVERSION="3.4" #DEV2 |
12 | 12 |
|
13 | 13 | # Read SnapRAID version |
14 | 14 | SNAPRAIDVERSION="$(snapraid -V | sed -e 's/snapraid v\(.*\)by.*/\1/')" |
@@ -147,6 +147,34 @@ function main(){ |
147 | 147 | # sanity check first to make sure we can access the content and parity files |
148 | 148 | mklog "INFO: Checking SnapRAID disks" |
149 | 149 | sanity_check |
| 150 | + |
| 151 | +# Check if previous sync was completed before running a new sync |
| 152 | +# If the status is ok (exit code 0) the script will proceed, otherwise will stop |
| 153 | + |
| 154 | + mklog "INFO: Checking SnapRAID Status" |
| 155 | + check_snapraid_status |
| 156 | + if [ $SNAPRAID_STATUS -eq 1 ]; then |
| 157 | + # Stop the script due to warning |
| 158 | + echo "Stopping the script because the previous SnapRAID sync did not complete correctly." |
| 159 | + SUBJECT="[WARNING] - Previous SnapRAID sync did not complete correctly." |
| 160 | + NOTIFY_OUTPUT="$SUBJECT" |
| 161 | + notify_warning |
| 162 | + if [ "$EMAIL_ADDRESS" ]; then |
| 163 | + trim_log < "$TMP_OUTPUT" | send_mail |
| 164 | + fi |
| 165 | + exit 1; |
| 166 | + |
| 167 | + elif [ $SNAPRAID_STATUS -eq 2 ]; then |
| 168 | + # Handle unknown status |
| 169 | + echo "Stopping the script due to unknown SnapRAID status. Please run 'snapraid status' on your host for more information." |
| 170 | + SUBJECT="[WARNING] - SnapRAID unknown status" |
| 171 | + NOTIFY_OUTPUT="$SUBJECT" |
| 172 | + notify_warning |
| 173 | + if [ "$EMAIL_ADDRESS" ]; then |
| 174 | + trim_log < "$TMP_OUTPUT" | send_mail |
| 175 | + fi |
| 176 | + exit 1; |
| 177 | + fi |
150 | 178 |
|
151 | 179 | # pause configured containers |
152 | 180 | if [ "$MANAGE_SERVICES" -eq 1 ]; then |
@@ -1101,6 +1129,28 @@ search_conf_files() { |
1101 | 1129 | fi |
1102 | 1130 | } |
1103 | 1131 |
|
| 1132 | +# Run SnapRAID status to check for the previous sync |
| 1133 | +check_snapraid_status() { |
| 1134 | + # Run snapraid status command and capture the output |
| 1135 | + local snapraid_status_output=$($SNAPRAID_BIN status) |
| 1136 | + |
| 1137 | + # Check for the "No sync is in progress" message |
| 1138 | + if echo "$snapraid_status_output" | grep -q "No sync is in progress"; then |
| 1139 | + echo "Previous sync completed successfully, proceeding." |
| 1140 | + mklog "Previous sync completed successfully, proceeding." |
| 1141 | + SNAPRAID_STATUS=0 |
| 1142 | + |
| 1143 | + # Check for the "NOT fully synced" warning message |
| 1144 | + elif echo "$snapraid_status_output" | grep -q "WARNING! The array is NOT fully synced."; then |
| 1145 | + mklog "Warning: The array is NOT fully synced. Stopping the script." |
| 1146 | + SNAPRAID_STATUS=1 |
| 1147 | + else |
| 1148 | + # If neither message is found, handle the unknown state |
| 1149 | + mklog "Warning: The array status is unknown. Stopping the script." |
| 1150 | + SNAPRAID_STATUS=2 |
| 1151 | + fi |
| 1152 | +} |
| 1153 | + |
1104 | 1154 | # Set TRAP |
1105 | 1155 | trap final_cleanup INT EXIT |
1106 | 1156 |
|
|
0 commit comments