OK, I found a solution. I created the file ~/scripts/backup.sh
:
#!/bin/bash
working_dir=`pwd`
backupname=""
if [ -z "$backupname" ]; then
for l in {a..z} ; do
if [ ! -f ~/Backup/backup_file_name_`date +"%Y-%m-%d"`_${l}.tar.gz ]; then
backupname=~/Backup/backup_file_name_`date +"%Y-%m-%d"`_${l}.tar.gz
break
fi
done
fi
if [ -z "$backupname" ]; then
l="z"
for (( i = 1 ; i <= 1000; i++ )) do
if [ ! -f ~/Backup/backup_file_name_`date +"%Y-%m-%d"`_${l}_${i}.tar.gz ]; then
backupname=~/Backup/backup_file_name_`date +"%Y-%m-%d"`_${l}_${i}.tar.gz
break
fi
done
fi
if [ ! -z "$backupname" ]; then
cd ~/projects/
~/scripts/tar.sh $backupname directory_to_backup/
cd $working_dir
else
echo "Oops! can't create backup file name."
fi
exit
The file ~/scripts/tar.sh
contains this script:
#!/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/backup.sh
and the script backs up my files.