B-Backup 1.0.1.0 Help

B-Backup

Introduction

Welcome to B-Backup, a Bash tool that simplifies the process of backing up files and directories. Designed for ease of use and efficiency, B-Backup offers a range of features to ensure seamless backup and recovery of data. This documentation provides an overview of the tool, its features and how to use it effectively.

B-Backup minimum requirements

Permissions

Concretization of the task

We decided to create our script based on Mr [redacted]'s suggestion. We decided to do the advanced version of the task, which is to create a backup script with the required features and our own. The full list of features can be found in the Features section.

User Story

The use case for this script is if user X wants to back up his files on his drives, but at the same time encrypt them and delete them after the backup, then this script is exactly what user X is looking for. B-Backup also has a nice, user-friendly interface and of course well written documentation. B-Backup also logs all actions in a log file, so user X can always see what has been done.

User Story representation

What is B-Backup?

B-Backup is a Bash script that allows you to back up files and directories with ease. There are many features that make B-Backup a powerful tool for backing up data like encryption, compression, logging, and many more that you can explore:

startup.png

Features

B-Backup offers the following features:

  • Backup: Back up files and directories to a hidden location on the user's system.

  • Encryption: Encrypt the backup using PKZIP encryption.

  • Compression: Compress the backup using DEFLATE compression.

  • Deletion: Delete the original files and directories after the backup is complete.

  • Restore: Restore the backup to the original or a custom location.

and many more:

  • Export: Export the backup(s) to a custom location.

  • Logging: Log all actions in a log file for future reference.

  • List backups: List all backups created by B-Backup.

  • Delete individual backups: Delete individual backups created by B-Backup.

  • Search for a specific file in a backup: Search for a specific file in any backup created by B-Backup.

  • Error handling: Handle errors gracefully and provide helpful messages to the user.

  • Help in menu: Get help on how to operate B-Backup.

Layout

We opted for a console layout, because we found that more time efficient than creating an extra GUI. We did however make the console as user-friendly as possible. (see pictures above and below)

Menu

Backup Management

Menu
Manage Backup Menu

Script Overview

The script is divided into several sections, each responsible for a specific task. The main sections are:

  • Startup: Displays the welcome message and checks for dependencies.

  • Menu: Displays the main menu and handles user input.

  • Backup Management: Handles the backup, encryption, compression, and deletion of files and directories but also the restore, export, list, delete, and search functions.

Struktog.png

Startup

The startup section displays the welcome message and checks for dependencies. If any dependencies are missing, the script will create the necessary directories and files. You can see this code in the startup function in the script.

The menu section displays the main menu and handles user input. The user can choose from a range of options, such as backing up files, restoring backups, exporting backups, listing backups, deleting backups, searching for files in backups, and getting help (see features). You can see this code in the menu and backup_menu function in the script.

Backup Management

Here comes the tricky part. The backup management section handles the backup, encryption, compression, and deletion of files and directories. It also handles the restore, export, list, delete, and search functions. You can see this code in the backup, restore, export, list_backups, delete_backup, and search_file functions in the script. For each single one of these functions, we have successfully implemented error handling to catch each possible error that could occur. Let's take a closer look at the core functions of the script. We will not go into every single detail of the functions, but we will give you an overview of the most important parts of them.

Backup function

#code... backup_name="" until [ ${#backup_name} -ne 0 ] do printf "What do you want to call this Backup?: " read -r backup_name done pre_log "LOG: New Backup has this name: $backup_name" curbinh="$homefolder/backup-$backup_name" mkdir -p $curbinh pre_log "LOG: Created new folder: $backup_name" #code...

This part of the function asks the user for a name for the backup. The user has to enter a name, that is longer than 0 characters. If the user enters a name that is shorter than 0 characters (e.g. Enter), the script will ask the user again for a name. The script will then log the name of the backup in the log file. After that, the script will create a new folder with the name of the backup in the home directory of project. The script will then log the creation of the folder in the log file.

Search function

#code... printf "Listing existing backups:\n" ls $homefolder/ | grep -v "0log.dll" printf "\nIn which backup do you want to search a file in?\nEnter the backup name: " read -r backup_name printf "\nWhich file are you searching for?\nEnter the file name: " read -r file_name if [ -f "$homefolder/backup-$backup_name/$backup_name.zip" ]; then report_1="Backup $backup_name existed." pre_log "LOG: Backup $backup_name exists." if unzip -l "$homefolder/backup-$backup_name/$backup_name.zip" | grep -q "$file_name"; then report_2="File $file_name found in backup $backup_name." pre_log "LOG: File $file_name found in backup $backup_name." printf "${GREEN}File $file_name found in backup $backup_name.${NC}\n" #code...

This part of the function lists all existing backups found in the hidden directory of the project. The script then asks the user for the name of the backup in which the user wants to search for a file. The script then asks the user for the name of the file the user wants to search for. The script then checks if the backup exists. If the backup exists, the script will log that the backup exists in the log file. The script then checks if the file exists in the backup. This is being done by using the unzip -l command to list all files in the backup and then grepping for the file name. If the file exists in the backup, the script will log that the file exists in the backup in the log file and will display a message to the user that the file exists in the backup. The user has later the option to restore the file from the backup to the original location or to a custom location.

Restore function

#code... printf "\nWhich backup do you want to restore? (if you want to exit to menu, hit enter | after restoring a backup, the backup will still be kept in the hidden folder. To remove the backup from $project_name)\nEnter the backup name: " read -r backup_name if [ -f "$homefolder/backup-$backup_name/$backup_name.zip" ]; then report_1="Backup $backup_name exists." printf "Do you want to restore the backup $backup_name to the original path? (y/n): " read -r choices if [[ $choices == "n" ]]; then report_2="Backup $backup_name was NOT restored to the original path: $original_path" printf "Do you want to extract the backup to a custom path? (y/n): " read -r choices if [[ $choices == "n" ]]; then report_3="Backup $backup_name was not restored at all." printf "Returning to menu\n" pre_log "LOG: Backup extract cancelled; Returning to menu" return fi printf "Enter the path where you want to extract the backup: " read -r custom_path unzip "$homefolder/backup-$backup_name/$backup_name.zip" -d "$custom_path" pre_log "LOG: Backup $backup_name was extracted to custom path: $custom_path" printf "Backup $backup_name was extracted to custom path: $custom_path\n" report_3="Backup $backup_name was restored to a custom path: $custom_path" return fi printf "Restoring backup $backup_name to the original path\n" original_path=$(cat "$homefolder/backup-$backup_name/$project_name.info.dll") unzip "$homefolder/backup-$backup_name/$backup_name.zip" -d "$original_path" pre_log "LOG: Backup $backup_name was restored to the original path" printf "${GREEN}Backup $backup_name was restored to the original path{NC}\n" report_2="Backup $backup_name was restored to the original path: $original_path" #code...

Now this function is also a very clever one. The script asks the user for the name of the backup the user wants to restore. The script then checks if the backup exists. If the backup exists, the script will log that the backup exists in the log file. The script then asks the user if the user wants to restore the backup to the original path. If the user does not want to restore the backup to the original path, the script will ask the user if the user wants to restore the backup to a custom path. If the user does not want to restore the backup at all, the script will log that the backup was not restored at all in the log file and will return to the menu. If the user wants to restore the backup to a custom path, the script will ask the user for the custom path. The script will then extract the backup to the custom path. The script will log that the backup was extracted to the custom path in the log file and will display a message to the user that the backup was extracted to the custom path. If the user wants to restore the backup to the original path, the script will extract the backup to the original path. This is only possible, because we saved the original path in a file in the hidden folder of the backup. This enables us to restore the backup to the original path even if the user has moved the original files or forgot where the original files were. The script will log that the backup was restored to the original path in the log file and will display a message to the user that the backup was restored to the original path. The user has later the option to delete the backup from the hidden folder of the project.

Testing

We have tested the script on a variety of possible problems and even on different linux distributions (Ubuntu and Kali). Below are the results of the tests:

Test Number

Test Type

Test Data

Reason

Expected Outcome

Actual Outcome

Pass?

Notes

1

Valid

Starting up the script for the first time ever (doesn't matter from which path you start the script from). By checking the following path you can confirm it everything that should exist after the first startup was created: "/home/.B-Backup". Only the folder itself and a 0log.dll within the B-Backup folder should exist.

To see if it'll create all the folders, files and if it'll print out a welcoming message with an explanation of what the script is supposed to be used for.

Valid

Valid

Pass

None

2

Valid

menuinput = 1 (main menu)

Enter a valid input for the menuinput to check if it'll open the "Managing Backups" menu.

Valid

Valid

Pass

None

3

Valid

menuinput = 2 (main menu)

Enter a valid input for the menuinput to check if it'll display a description to the script including one link for the scripts source and another link for the documentation of this script.

Valid

Valid

Pass

None

4

Valid

menuinput = 3 (main menu)

Enter a valid input for the menuinput to check if it'll print out the log file into the terminal.

Valid

Valid

Pass

None

5

Valid

menuinput = 4 (main menu) AND check manually if the folders and files were exported to your designated path or the default path (desktop).

Enter a valid input for the menuinput to check if it'll start the dialogue to export all Backups to a designated or the default path (desktop).

Valid

Valid

Pass

This will only work if you've created at least one backup or else it's not going to export anything.

6

Valid

menuinput = 95 (main menu)

Enter a valid input for the menuinput to check if it'll start the uninstalling dialogue.

Valid

Valid

Pass

None

7

Valid

uninstall_dialogue = uninstall AND check manually if all the folders/files associated with the script, like in the path described in Test Number 5 are completely deleted.

Enter the only valid input (which is "uninstall") for the uninstalling dialogue to check if it'll uninstall the path and the files within that path associated with this script.

Valid

Valid

Pass

None

8

Invalid

uninstall_dialogue = dog

Enter an invalid input for the uninstall dialogue to check if it'll tell the user that the uninstall failed and returning the user to the main menu.

Invalid

Invalid

Pass

None

9

Invalid

menuinput = fish (main menu)

Enter an invalid input for the menuinput to check if it'll tell the user that the input was not validated.

Invalid

Invalid

Pass

None

10

Invalid

Run script with root without the permission check-snipet.

Running the script with root to check if it'll display error message(s).

Invalid

Invalid

Pass

The Script cannot be run with root, it won't function properly!

11

Invalid

Run script with root with the permission check-snipet (checks if you're running with root or not).

Running the script with root with the permission check-snipet to see if it'll inform the user that the script cannot be run with root.

Invalid

Invalid

Pass

None

12

Valid

menuinput = 1 (Backup Management)

Enter a valid input for the menuinput to check if it'll start the backup creation dialogue.

Valid

Valid

Pass

None

13

Valid

create a directory with a file inside called "message.txt" on your desktop and creating a backup with the following configurations: name: testing remove files from original source (y), backup encryption (y), no backup compression (n), path: "/home/[user]/Desktop/[folder name]" confirm (y), password: 123 create report (y) Check the Desktop for the report and manually check the "/home/.B-Backup" path for the Backup that was just made with the configurations stated above.

To check if the created backup was actually made in the previous folder from Test Number 1. Including the report creation that will be found on the users desktop. And to test the correct functioning of the backup creation itself.

Valid

Valid

Pass

None

14

Valid

menuinput = 2 (Backup Management)

Enter a valid input for the menuinput to check if it'll start the backup deleting dialogue.

Valid

Valid

Pass

None

15

Valid

Deleting an already existing backup, in this case the backup that was created in Test Number 13 will be deleted. Therefore the input for the deletion of a backup for this test will be "testing". Check if the backup was deleted by going into the usual default B-Backup path (/home/.B-Backup).

Enter a valid backup name to check if it'll actually delete the entered backup.

Valid

Valid

Pass

None

16

Valid

menuinput = 3 (Backup Management)

Enter a valid input for the menuinput to check if it'll start the backup restoring dialogue.

Valid

Valid

Pass

None

17

Valid

menuinput = 4 (Backup Management)

Enter a valid input for the menuinput to check if it'll display all existing backups.

Valid

Valid

Pass

None

18

Valid

menuinput = 5 (Backup Management)

Enter a valid input for the menuinput to check if it'll start the file searching dialogue

Valid

Valid

Pass

None

19

Valid

Search for the file "message.txt" inside of the backup "testing" that was created in Test Number 13.

Enter a valid backup name and file name to check if it'll find the correct file inside of the entered backup.

Valid

Valid

Pass

None

20

Valid

menuinput = 6 (Backup Management)

Enter a valid input for the menuinput to check if it'll start the backup exporting dialogue.

Valid

Valid

Pass

None

21

Valid

Exporting the "testing" backup from Test Number 13 to the desktop.

Enter a valid input for the Exporting of a backup to the desktop to check if it'll export the backup to the desktop correctly.

Valid

Valid

Pass

None

22

Valid

menuinput = 99 (Backup Management)

Enter a valid input for the menuinput to check if it'll return the user back to the main menu.

Valid

Valid

Pass

None

23

Invalid

menuinput = hungary (Backup Management)

Enter an invalid input for the menuinput to check if it'll tell the user that that the input was not validated.

Invalid

Invalid

Pass

None

Conclusion

We have successfully created a backup script that meets the requirements of the task. The script is user-friendly and efficient, offering a range of features to ensure seamless backup and recovery of data. We have also implemented error handling to catch any possible errors that could occur. The script has been tested on a variety of possible problems and different linux distributions, and has been found to work as expected. We are confident that B-Backup will be a valuable tool for users looking to back up their files and directories with ease.

In conclusion, we are very satisfied with the result of our work and if we had to do it again, we would do it exactly the same way. We are very proud of our work, and we hope that you will enjoy using B-Backup as much as we enjoyed creating it.

Last modified: 15 May 2024