|
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/')" |
@@ -137,26 +137,54 @@ function main(){ |
137 | 137 | if [ ! -f "$SNAPRAID_CONF" ]; then |
138 | 138 | # if running on OMV7, try to find the SnapRAID conf file automatically |
139 | 139 | check_omv_version |
140 | | - if [ "$OMV_VERSION" -ge 7 ]; then |
141 | | - pick_snapraid_conf_file |
142 | | - else |
143 | | - echo "SnapRAID configuration file not found. The script cannot be run! Please check your settings, because the specified file "$SNAPRAID_CONF" does not exist." |
144 | | - mklog "WARN: SnapRAID configuration file not found. The script cannot be run! Please check your settings, because the specified file "$SNAPRAID_CONF" does not exist." |
145 | | - SUBJECT="[WARNING] - SnapRAID configuration file not found!" |
146 | | - FORMATTED_CONF="\`$SNAPRAID_CONF\`" |
147 | | - NOTIFY_OUTPUT="$SUBJECT The script cannot be run! Please check your settings, because the specified file $FORMATTED_CONF does not exist." |
148 | | - notify_warning |
149 | | - if [ "$EMAIL_ADDRESS" ]; then |
150 | | - trim_log < "$TMP_OUTPUT" | send_mail |
151 | | - fi |
152 | | - exit 1; |
153 | | - fi |
| 140 | + if [ "$OMV_VERSION" -ge 7 ]; then |
| 141 | + pick_snapraid_conf_file |
| 142 | + else |
| 143 | + echo "SnapRAID configuration file not found. The script cannot be run! Please check your settings, because the specified file "$SNAPRAID_CONF" does not exist." |
| 144 | + mklog "WARN: SnapRAID configuration file not found. The script cannot be run! Please check your settings, because the specified file "$SNAPRAID_CONF" does not exist." |
| 145 | + SUBJECT="[WARNING] - SnapRAID configuration file not found!" |
| 146 | + FORMATTED_CONF="\`$SNAPRAID_CONF\`" |
| 147 | + NOTIFY_OUTPUT="$SUBJECT The script cannot be run! Please check your settings, because the specified file $FORMATTED_CONF does not exist." |
| 148 | + notify_warning |
| 149 | + if [ "$EMAIL_ADDRESS" ]; then |
| 150 | + trim_log < "$TMP_OUTPUT" | send_mail |
| 151 | + fi |
| 152 | + exit 1; |
| 153 | + fi |
154 | 154 | fi |
155 | 155 |
|
156 | 156 |
|
157 | 157 | # sanity check first to make sure we can access the content and parity files |
158 | 158 | mklog "INFO: Checking SnapRAID disks" |
159 | 159 | sanity_check |
| 160 | + |
| 161 | +# Check if previous sync was completed before running a new sync |
| 162 | +# If the status is ok (exit code 0) the script will proceed, otherwise will stop |
| 163 | + |
| 164 | + mklog "INFO: Checking SnapRAID Status" |
| 165 | + check_snapraid_status |
| 166 | + if [ $SNAPRAID_STATUS -eq 1 ]; then |
| 167 | + # Stop the script due to warning |
| 168 | + echo "Stopping the script because the previous SnapRAID sync did not complete correctly." |
| 169 | + SUBJECT="[WARNING] - Previous SnapRAID sync did not complete correctly." |
| 170 | + NOTIFY_OUTPUT="$SUBJECT" |
| 171 | + notify_warning |
| 172 | + if [ "$EMAIL_ADDRESS" ]; then |
| 173 | + trim_log < "$TMP_OUTPUT" | send_mail |
| 174 | + fi |
| 175 | + exit 1; |
| 176 | + |
| 177 | + elif [ $SNAPRAID_STATUS -eq 2 ]; then |
| 178 | + # Handle unknown status |
| 179 | + echo "Stopping the script due to unknown SnapRAID status. Please run 'snapraid status' on your host for more information." |
| 180 | + SUBJECT="[WARNING] - SnapRAID unknown status" |
| 181 | + NOTIFY_OUTPUT="$SUBJECT" |
| 182 | + notify_warning |
| 183 | + if [ "$EMAIL_ADDRESS" ]; then |
| 184 | + trim_log < "$TMP_OUTPUT" | send_mail |
| 185 | + fi |
| 186 | + exit 1; |
| 187 | + fi |
160 | 188 |
|
161 | 189 | # pause configured containers |
162 | 190 | if [ "$MANAGE_SERVICES" -eq 1 ]; then |
@@ -1106,6 +1134,28 @@ search_conf_files() { |
1106 | 1134 | fi |
1107 | 1135 | } |
1108 | 1136 |
|
| 1137 | +# Run SnapRAID status to check for the previous sync |
| 1138 | +check_snapraid_status() { |
| 1139 | + # Run snapraid status command and capture the output |
| 1140 | + local snapraid_status_output=$($SNAPRAID_BIN status) |
| 1141 | + |
| 1142 | + # Check for the "No sync is in progress" message |
| 1143 | + if echo "$snapraid_status_output" | grep -q "No sync is in progress"; then |
| 1144 | + echo "Previous sync completed successfully, proceeding." |
| 1145 | + mklog "Previous sync completed successfully, proceeding." |
| 1146 | + SNAPRAID_STATUS=0 |
| 1147 | + |
| 1148 | + # Check for the "NOT fully synced" warning message |
| 1149 | + elif echo "$snapraid_status_output" | grep -q "WARNING! The array is NOT fully synced."; then |
| 1150 | + mklog "Warning: The array is NOT fully synced. Stopping the script." |
| 1151 | + SNAPRAID_STATUS=1 |
| 1152 | + else |
| 1153 | + # If neither message is found, handle the unknown state |
| 1154 | + mklog "Warning: The array status is unknown. Stopping the script." |
| 1155 | + SNAPRAID_STATUS=2 |
| 1156 | + fi |
| 1157 | +} |
| 1158 | + |
1109 | 1159 | # Set TRAP |
1110 | 1160 | trap final_cleanup INT EXIT |
1111 | 1161 |
|
|
0 commit comments