File tree Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -170,14 +170,20 @@ if [[ -n "$RESTIC_BACKUP_STATS_DIR" || -n "$RESTIC_BACKUP_NOTIFICATION_FILE" ]];
170
170
| awk ' {print $1}' \
171
171
| tail -2 \
172
172
| tr ' \n' ' ' )
173
- latest_snapshot_diff=$( echo " $latest_snapshots " | xargs restic diff)
174
- added=$( echo " $latest_snapshot_diff " | grep -i ' added:' | awk ' {print $2 " " $3}' )
175
- removed=$( echo " $latest_snapshot_diff " | grep -i ' removed:' | awk ' {print $2 " " $3}' )
176
- snapshot_size=$( restic stats latest --tag " $RESTIC_BACKUP_TAG " | grep -i ' total size:' | cut -d ' :' -f2 | xargs) # xargs acts as trim
177
- snapshotId=$( echo " $latest_snapshots " | cut -d ' ' -f2)
178
- statsMsg=" Added: ${added} . Removed: ${removed} . Snap size: ${snapshot_size} "
179
-
180
- echo " $statsMsg "
181
- test -n " $RESTIC_BACKUP_STATS_DIR " && logBackupStatsCsv " $snapshotId " " $added " " $removed " " $snapshot_size "
182
- test -n " $RESTIC_BACKUP_NOTIFICATION_FILE " && notifyBackupStats " $statsMsg "
173
+
174
+ snapshot_count=$( echo " $latest_snapshots " | wc -l)
175
+ if [[ $snapshot_count -lt 2 ]]; then
176
+ echo " Warning: $snapshot_count snapshot(s) found. Skipping diff stats (need at least 2 snapshots)."
177
+ else
178
+ latest_snapshot_diff=$( echo " $latest_snapshots " | xargs restic diff)
179
+ added=$( echo " $latest_snapshot_diff " | grep -i ' added:' | awk ' {print $2 " " $3}' )
180
+ removed=$( echo " $latest_snapshot_diff " | grep -i ' removed:' | awk ' {print $2 " " $3}' )
181
+ snapshot_size=$( restic stats latest --tag " $RESTIC_BACKUP_TAG " | grep -i ' total size:' | cut -d ' :' -f2 | xargs) # xargs acts as trim
182
+ snapshotId=$( echo " $latest_snapshots " | cut -d ' ' -f2)
183
+ statsMsg=" Added: ${added} . Removed: ${removed} . Snap size: ${snapshot_size} "
184
+
185
+ echo " $statsMsg "
186
+ test -n " $RESTIC_BACKUP_STATS_DIR " && logBackupStatsCsv " $snapshotId " " $added " " $removed " " $snapshot_size "
187
+ test -n " $RESTIC_BACKUP_NOTIFICATION_FILE " && notifyBackupStats " $statsMsg "
188
+ fi
183
189
fi
You can’t perform that action at this time.
0 commit comments