Linux Bash Shell Realtime Project of Daily Backup Script // Project 1

Linux Bash Shell Realtime Project of Daily Backup Script

Realtime Project Flow Diagram

In the above Flow diagram

[root@engrabhishekroshan scripts]# cat daily_backup_prd.sh
#!/bin/bash

# Define paths and filenames
backup_config_file=”/archive/backup_config.txt”
backup_destination=”/member”
#hourly_dir=”$backup_destination/$(date +’%Y-%m-%d_%H-%M’)”
backup_filename=”backup_$(date +’%Y%m%d_%H%M%S’).tar.gz”
source_directory=”/archive”
# Check if the backup configuration file exists

if [ -f “$backup_config_file” ]; then
echo “Backup configuration file found. Proceeding with the backup.”
else
echo “Backup configuration file not found. Exiting.”
exit 1
fi
#
#
#mkdir -p “$hourly_dir”
# Read backup configuration from the file (modify as per your config file format)
source “$backup_config_file”

# Perform the backup
tar -czf “$backup_destination/$backup_filename” “$source_directory” 2>/dev/null

# Check if the backup was successful
if [ $? -eq 0 ]; then
echo “Backup completed successfully: $backup_destination/$backup_filename”
else
echo “Backup failed. Please check for errors.”
exit 1
fi

###########END OF SCRIPT####################

[root@engrabhishekroshan scripts]# chmod 755 daily_backup_prd.sh
[root@engrabhishekroshan scripts]# ll daily_backup_prd.sh
-rwxr-xr-x. 1 root root 950 Jan 19 02:27 daily_backup_prd.sh

Output After Execution

[root@engrabhishekroshan scripts]# sh daily_backup_prd.sh
Backup configuration file found. Proceeding with the backup.
Backup completed successfully: /member/backup_20240217_010045.tar.gz

error: Content is protected !!