Skip to content

Commit f45468f

Browse files
committed
Shellcheck fixes
1 parent acb1f9f commit f45468f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

files/puppet_enterprise_database_backup.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ done
2828

2929
# The remaining parameters will be the databases to backup
3030
databases=("$@")
31+
# shellcheck disable=SC2128
32+
# We only care if the array contains any elements
3133
[[ $databases ]] || {
3234
echo "Usage: $0 [-t BACKUP_TARGET] [-l LOG_DIRECTORY] [-r retention] <DATABASE> [DATABASE_N ...]"
3335
exit 1
@@ -39,7 +41,7 @@ log_dir="${log_dir:-/var/log/puppetlabs/pe_databases_backup}"
3941
retention="${retention:-2}"
4042

4143
for db in "${databases[@]}"; do
42-
# For each db, redirect all output the the log inside the backup dir
44+
# For each db, redirect all output to the log inside the backup dir
4345
exec &>"${log_dir}/${db}.log"
4446
echo "Enforcing retention policy of storing only $retention backups for $db"
4547

@@ -48,13 +50,13 @@ for db in "${databases[@]}"; do
4850
# Add the filename to the backups array, giving us a sorted list of filenames
4951
while IFS= read -r -d '' line; do
5052
backups+=("${line#* }")
51-
done < <(stat --printf '%Y %n\0' ${backup_dir}/${db}_* 2>/dev/null | sort -nz)
53+
done < <(stat --printf '%Y %n\0' "${backup_dir}/${db}_"* 2>/dev/null | sort -nz)
5254

5355
# Our array offset will be the number of backups - $retention + 1
5456
# e.g. if we have 2 existing backups and retention=2, offset will be one
5557
# We'll delete from element 0 to 1 of the array, leaving one backup.
5658
# The subsequent backup will leave us with 2 again
57-
offset=$(( ${#backups[@]} - $retention + 1 ))
59+
offset=$(( ${#backups[@]} - retention + 1 ))
5860

5961
if (( offset > 0 )); then
6062
# Continue if we're retaining more copies of the db than currently exist

0 commit comments

Comments
 (0)