How do I prevent tar from overwriting an existing archive?

linux, shell, tar

Solution

I created the file `~/scripts/tar.sh`:

#!/bin/bash

if [ -f $1 ]; then
    echo "Oops! backup file was already here."
    exit
fi
tar -cpvzf $1 $2 $3 $4 $5

Now I just have to type:

~/scripts/tar.sh ~/Backup/backup_file_name_`date +"%Y-%m-%d"`_a.tar.gz directory_to_backup/

And the backup file is created if the file doesn't exist.

Problem

I backup files a few times a day on Ubuntu/Linux with the command `tar -cpvzf ~/Backup/backup_file_name.tar.gz directory_to_backup/`, (the file name contains the date in YYYY-MM-DD format and a letter from a to z - a is the first backup for this date etc.) but I want to create a new archive, not overwrite the archive if it already exists. How do I prevent tar from overwriting an existing archive? If the archive exists, I want tar to exit without doing anything (and if possible, display an error message).

Original source