Skip to main content
edited title
Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

Why does this script work sparringlysparingly?

Source Link

Why does this script work sparringly?

I have the following bash script that is running as a cronjob on OpenMediaVault:

BACKUP_DIR='/srv/dev-disk-by-uuid-9EE055CFE055ADF1/Backup dir/' BACKUP_FILE_PATH="/srv/dev-disk-by-uuid-9EE055CFE055ADF1/Backup dir/Backup [ashen] ($(date +%d-%m-%Y)).tar.gz" SERVER_DIR=/var/lib/docker/volumes/49c9e5c53ea5b9c893c0a80117860da9b493484395c0$ MAX_BACKUPS_COUNT=4 tar -zcf "$BACKUP_FILE_PATH" $SERVER_DIR cd "$BACKUP_DIR" [[ $( ls | wc -l ) -gt $MAX_BACKUPS_COUNT ]] && rm "$(ls -t | tail -1)" 

The point of the script is to create a .tar.gz backup in the given location and, if there are more than 4 files in the backup directory, delete the oldest (the point being to keep only 4 recent backups). The last line/command doesn't always work. Running it manually in a terminal works as expected and sometimes the script will execute it but then sometimes it will stop until I manually try to run the script/line and then it seems to magically fix itself for some period of time.

Does anyone know why it sporadically stops executing the last line? Even when I see that backups are being created.