Day 9 :- Shell Scripting Challenge: ๐Ÿ“‚ Directory Backup with Rotation ๐Ÿ”„

Day 9 :- Shell Scripting Challenge: ๐Ÿ“‚ Directory Backup with Rotation ๐Ÿ”„

ยท

1 min read

Table of contents

Day 9 :- TASK

#!/bin/bash
<<readme
info : This script will create backup
./createBackup.sh <source_dir> <target_dir>
readme

source_dir=$1
target_dir=$2
timestamp=$(date "+%Y-%m-%d-%H-%M-%S")

backup_dir="${target_dir}/backup_${timestamp}"

zip -r "${backup_dir}.zip" "${source_dir}" >  /dev/null

if [ $? -eq 0 ]; then
        echo "backup_${timestamp} created successfully"
else
        echo "Backup was not perfomed backup_${timestamp}"
fi

Thank you for reading!

ยฉ 2024 Anand Raval. All rights reserved.

ย