Open DhillanC opened 4 months ago
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=$1 destinationDirectory=$2
echo "Target Directory: $targetDirectory" echo "Destination Directory: $destinationDirectory"
currentTS=$(date +%s)
backupFileName="backup-${currentTS}.tar.gz"
origAbsPath=$(pwd)
cd "$destinationDirectory" # I'm adding "" to consider directories with spaces destAbsPath=$(pwd)
cd "$origAbsPath" cd "$targetDirectory"
yesterdayTS=$(($currentTS - (24 60 60)))
declare -a toBackup
for file in $(ls -1t) do
if [[ $(date -r "$file" +%s) -gt $yesterdayTS ]]; then
# [TASK 11]
toBackup+=("$file")
fi done
if tar -czvf "$backupFileName" "${toBackup[@]}"; then echo "Backup archive created successfully: $backupFileName" else echo "Error: Failed to create backup archive." exit 1 # Exit the script with an error message fi
if mv "$backupFileName" "$destAbsPath"; then echo "Backup file moved to destination directory: $destAbsPath" else echo "Error: Failed to move backup file to destination directory." exit 1 # Exit the script with an error status fi
As a [role]
I need [function]
So that [benefit]
Details and Assumptions
[document what you know]
Acceptance Criteria