#!/bin/bash
if [[ $# != 2 ]] then echo "backup.sh target_directory_name destination_directory_name" exit fi
if [[ ! -d $1 ]] || [[ ! -d $2 ]] then echo "Invalid directory path provided" exit fi
targetDirectory="$2" destinationDirectory="$1"
echo "Target Directory: $targetDirectory" echo "Target Directory: $destinationDirectory"
currentTS=$(date +%s)
backupFileName="backup-[$currentTS].tar.gz"
origAbsPath=$(pwd)
cd "$destinationDirectory" || exit 1 # <- destDirAbsPath=$(pwd) cd "$origAbsPath" || exit 1
cd "$origAbsPath" || exit 1 # Return to the original directory or exit on failure cd "$targetDirectory" || exit 1
yesterdayTS=$((currentTS - 24 * 60 * 60))
declare -a toBackup
for file in $(ls) # [TASK 9] do
if ((date -r $file +%s
> $yesterdayTS))
then
toBackup+=($file) # [TASK 11]
fi
done
tar -czvf
mv "$backupFileName" "$destinationDirectory/"