Giter Site home page Giter Site logo

farahat612 / automatic-backup-script Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 133 KB

A shell script ensures that recent updates to sensitive files are regularly backed up, enhancing data security and reducing manual effort.

License: MIT License

Shell 100.00%
data-engineering etl-pipeline python shell-scripting

automatic-backup-script's Introduction

Automatic Backup Script (backup.sh)

Table of Contents

Introduction

Welcome to the Automatic Backup Script (backup.sh) project! This script is designed to automate the backup process for encrypted password files that have been updated in the past 24 hours. By eliminating manual intervention, it enhances security, reduces human error, and improves efficiency.

Project Overview

ABC currently suffers from a huge bottleneck: each day, interns must painstakingly access encrypted password files on core servers and back up any files that were updated within the last 24 hours. This process introduces human error, lowers security, and takes an unreasonable amount of work. As a lead Linux developer at ABC International Inc., you have been tasked with creating a script called backup.sh which runs every day and automatically backs up any encrypted password files that have been updated in the past 24 hours

This script performs the following tasks:

  1. Accepts two command-line arguments: target_directory_name and destination_directory_name.
  2. Captures the current timestamp in seconds.
  3. Defines the name of the backup file with a timestamp.
  4. Identifies files in the target directory modified within the last 24 hours.
  5. Archives and compresses these files into the backup file.
  6. Moves the backup file to the destination directory.

The script ensures that recent updates to sensitive files are regularly backed up, enhancing data security and reducing manual effort.

Tasks

Task 1: Set Target and Destination Directories

targetDirectory=$1
destinationDirectory=$2

Task 2: Display Command Line Arguments

echo "Target Directory: $targetDirectory"
echo "Destination Directory: $destinationDirectory"

Task 3: Define Current Timestamp

currentTS=$(date +%s)

Task 4: Define Backup File Name

backupFileName="backup-$currentTS.tar.gz"

Task 5: Define Original Absolute Path

origAbsPath=$(pwd)

Task 6: Define Destination Absolute Path

cd $destinationDirectory
destAbsPath=$(pwd)

Task 7: Change to Target Directory

cd $origAbsPath
cd $targetDirectory

Task 8: Define Yesterday Timestamp

yesterdayTS=$((currentTS - 24 * 60 * 60))

Task 9: Get Files In Current Directory

for file in $(ls)

Task 10: Check File Modification Date

file_last_modified_date=$(date -r "$file" +%s)
if ((file_last_modified_date > yesterdayTS)); then

Task 11: Add File to Backup List

toBackup+=("$file")

Task 12: Archive Files

tar -czvf "$backupFileName" "${toBackup[@]}"

Task 13: Move Backup File

mv "$backupFileName" "$destAbsPath"

Task 14: Make Script Executable

chmod +x backup.sh

Task 15: Schedule Backup Using Cron

sudo cp /path/to/backup.sh /usr/local/bin/
crontab -e
*/1 * * * * /usr/local/bin/backup.sh /home/project/important-documents /home/project
sudo service cron start
sudo service cron stop
crontab -e
0 0 * * * /usr/local/bin/backup.sh /home/project/important-documents /home/project

Usage

  1. Clone this repository to your local machine.
  2. Navigate to the project directory.
  3. Open the backup.sh script.
  4. Modify the script as needed for your specific use case.
  5. Save the script and make it executable using the chmod command.
  6. Copy the script to /usr/local/bin/ for system-wide access.
  7. Set up a cron job to schedule backups according to your requirements.

Technologies

This project leverages the following technologies:

  • Bash: The scripting language used to create backup.sh.
  • Linux: The target environment for running the backup script.
  • Cron: The cron job scheduler for automating backups.

Contributing

Contributions to this project are welcome! If you have suggestions or would like to report issues, please open an issue or create a pull request.

Acknowledgments

This project was completed as part of an educational assignment and is based on the provided datasets from the Chicago Data Portal. It serves as an assignment for Introduction to Linux Commands and Shell Scripting course which is part of IBM Data Engineer Professional Certificate on Coursera.

License

This project is licensed under the MIT License.

automatic-backup-script's People

Contributors

farahat612 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.