Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving backup_and_restore.sh script before new-coming features #6030

Open
wants to merge 31 commits into
base: staging
Choose a base branch
from

Conversation

h3ssan
Copy link
Member

@h3ssan h3ssan commented Aug 19, 2024

Contribution Guidelines

What does this PR include?

Short Description

This PR is not finished yet, I'll include many re-write code for the backup_and_restore.sh script. Enhancement, refactor and improved code, before starting to implement a new features.

Affected Containers

None

Did you run tests?

Tested manually

What did you tested?

  • backup_and_restore.sh script

What were the final results? (Awaited, got)

All good

h3ssan added 7 commits August 19, 2024 22:59
Since it might have spaces, it must be double quoted.
Previous code was not checking if the path is a `symbolic` to a filesystem, if user is root and the given path is a `symbolic` of filesystem then it will overwrite it!
Implement `check_required_tools` function in `backup_and_restore.sh` script, as well call it in the beginning of the script instead of at the end
@h3ssan
Copy link
Member Author

h3ssan commented Aug 20, 2024

Hey @DerLinkman, you can now resolve this PR, since I will need a few time to refactor and fully test the backup and restore functionality, since then you can resolve this PR now to avoid conflicts.

@DerLinkman
Copy link
Member

Hey @DerLinkman, you can now resolve this PR, since I will need a few time to refactor and fully test the backup and restore functionality, since then you can resolve this PR now to avoid conflicts.

Hello @h3ssan! Is this pr now ready to merge or not? If not, we can convert it to a draft.

@h3ssan
Copy link
Member Author

h3ssan commented Aug 20, 2024

Hey there @DerLinkman , yes it’s ready to be merged.

still there’s 2 functions I need to look into but might take some time so yes, resolve it

Copy link
Member

@DerLinkman DerLinkman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine!

@h3ssan
Copy link
Member Author

h3ssan commented Aug 20, 2024

Clarification

Commit Fix Bug: backup_and_restore.sh script, increment i only if needed, why?

Original Code

  i=1 # Starts at 1, even before finding any folder
  declare -A FOLDER_SELECTION
  if [[ $(find "${BACKUP_LOCATION}"/mailcow-* -maxdepth 1 -type d 2> /dev/null| wc -l) -lt 1 ]]; then
    echo -e "\e[31mSelected backup location has no subfolders\e[0m"
    exit 1
  fi
  for folder in $(ls -d "${BACKUP_LOCATION}"/mailcow-*/); do
    echo "[ ${i} ] - ${folder}"
    FOLDER_SELECTION[${i}]="${folder}"
    ((i++)) 
  done

If i is initial to 1, this will cause:

  • i = 1 - Initial
  • Checking if there's a folder, then increment i, therefore 1 = 2

Here we have i equals to 2 but we only found one folder !
Then, when the user choose which folder to restore, the user can simply choose 2 not 1 and the script will continue working, check the following image:

`backup_and_restore.sh` script, with `restore` flag, crashes when entering a non-numeric value as backup choice
@h3ssan
Copy link
Member Author

h3ssan commented Aug 20, 2024

Clarification

Commit: Fix: Crash on entering non-numeric value, fixes the following issue:

Enter , (non-numeric value, actually) will case a crash:

h3ssan added 2 commits August 20, 2024 20:55
Fix the crash on entering non-numeric value, as well as make the code more readable
@h3ssan
Copy link
Member Author

h3ssan commented Aug 20, 2024

Till this point, what I have tested is below:

Tested Command Expected Status
./backup_and_restore.sh backup vmail Backed up1 Good ✓
./backup_and_restore.sh backup all Backed up1 Good ✓
./backup_and_restore.sh backup anythingelse Throw Unknown argument: anythingelse Good ✓
./backup_and_restore.sh anythingelse print the usage Good ✓
./backup_and_restore.sh restore with correct folder Restored1 Good ✓
./backup_and_restore.sh restore with non-existence folder Throw location not found Good ✓
./backup_and_restore.sh restore with location with no data Throw no subfolders Good ✓
./backup_and_restore.sh restore with location to /dev/sda Throw invalid path Good ✓
./backup_and_restore.sh backup vmail with location to /dev/sda Throw invalid path Good ✓

1 I DID NOT check the actual process, just trusted what the script said! Therefore it might need extensive/dedicated testing.

@h3ssan h3ssan force-pushed the Implement/backup-and-restore-script branch 2 times, most recently from cc8c889 to ea24505 Compare August 21, 2024 00:31
Refactor `backup_and_restore.sh` script, implement `declare_restore_point` function.
@h3ssan
Copy link
Member Author

h3ssan commented Aug 21, 2024

Sorry about the last commit, there was an issue with the committer and author details. I soft reset, fixed it and push again.

@h3ssan
Copy link
Member Author

h3ssan commented Aug 21, 2024

Please note that this commit Implement declare_restore_point function still need testing. I'll do the test in a few hours.

h3ssan added 6 commits August 21, 2024 14:34
Refactor `backup_and_restore.sh` script, implement `declare_file_selection` function
Implement `restore_docker_component` function to restore `vmail`, `redis`, `crypt`, `rspamd` and `postfix`, all from one function
@h3ssan
Copy link
Member Author

h3ssan commented Aug 27, 2024

Thank you @DerLinkman for the testing process.
I have fixed the issues, please do the testing process again!

sorry I know it's noisy but necessary.

@h3ssan h3ssan requested a review from DerLinkman August 27, 2024 08:02
Copy link
Member

@DerLinkman DerLinkman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment

helper-scripts/backup_and_restore.sh Outdated Show resolved Hide resolved
@DerLinkman
Copy link
Member

How does this script behave when it is automated? E.g runned via cron?

Especially the part with -d (delete backups) you have to enter YES to confirm deletion?

@h3ssan
Copy link
Member Author

h3ssan commented Aug 27, 2024

How does this script behave when it is automated? E.g runned via cron?

Especially the part with -d (delete backups) you have to enter YES to confirm deletion?

For now, it won't. In the next feat PR, I'll make it automated.

@h3ssan h3ssan requested a review from DerLinkman August 27, 2024 09:20
@DerLinkman
Copy link
Member

DerLinkman commented Aug 27, 2024

For now, it won't. In the next feat PR, I'll make it automated.

That makes it hard for us to track... as we always take all staging commits into the next update and we await the full functionality of that. If you say that the automation is not implemented yet inside this pr, then we won't merge it... i'm sorry. As this is heavily used by other users.

In general: Why did you want to make multiple prs instead of one which includes all of your changes, even the new additions? I did not get it.

@h3ssan
Copy link
Member Author

h3ssan commented Aug 27, 2024

For now, it won't. In the next feat PR, I'll make it automated.

That makes it hard for us to track... as we always take all staging commits into the next update and we await the full functionality of that. If you say that the automation is not implemented yet inside this pr, then we won't merge it... i'm sorry. As this is heavily used by other users.

In general: Why did you want to make multiple prs instead of one which includes all of your changes, even the new additions? I did not get it.

Then, If something happened unexpected, we will revert everything instead of the PR that has the problem. Please correct me if I am wrong.

As well, many features inside one PR will make the testing harder.

If you resist, then it's ok for me. Please confirm that you need the full implementation inside this PR and I'll start make the script fully automated.

@DerLinkman
Copy link
Member

I definitely unterstand your doing. I prefer this. But currently your backup script is removing a automated part. So yes: Please readd the automation into your scripts remake PR.

@h3ssan
Copy link
Member Author

h3ssan commented Aug 27, 2024

The script now can be automated using --yes flag.

Example:

./helper-scripts/backup_and_restore.sh --delete /opt/backup 7 --yes

Please note that since --yes flag is critical and won't ask for any confirmation, therefore there will not be any short flag for it. Only --yes.

Copy link
Member

@DerLinkman DerLinkman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment (only one :D) rest looks fine to me.

However, we need to adjust the mailcow docs too. Do you want to do it by yourself or should we adapt it?

Just asking, that we don't do the same work parallel :D

helper-scripts/backup_and_restore.sh Show resolved Hide resolved
@h3ssan
Copy link
Member Author

h3ssan commented Aug 29, 2024

See comment (only one :D) rest looks fine to me.

However, we need to adjust the mailcow docs too. Do you want to do it by yourself or should we adapt it?

Just asking, that we don't do the same work parallel :D

Sure, I’ll do adjust the docs!

h3ssan added 2 commits August 29, 2024 15:16
Full error message:
```
Error: auth-master: userdb list: connect(/run/dovecot/auth-userdb) failed: Connection refused
Panic: file auth-master.c: line 436 (auth_master_unset_io): assertion failed: (conn->to == NULL)
```
@DerLinkman
Copy link
Member

@MAGICCC could you try to test this too? It works and looks good for me but if a seperate user can take a look at this i would be happy

@MAGICCC
Copy link
Member

MAGICCC commented Sep 10, 2024

Yes I will check on the weekend!

@h3ssan
Copy link
Member Author

h3ssan commented Sep 10, 2024

Yes I will check on the weekend!

Thank you!

@mrclschstr
Copy link
Contributor

Would be awesome to include this as well: #4833

@DerLinkman
Copy link
Member

Would be awesome to include this as well: #4833

@h3ssan could you adapt this in your next step (adding new features)?

@h3ssan
Copy link
Member Author

h3ssan commented Oct 15, 2024

Would be awesome to include this as well: #4833

@h3ssan could you adapt this in your next step (adding new features)?

I went through the PR, interesting. I will implement it later (after completing this step).

@DerLinkman DerLinkman force-pushed the staging branch 2 times, most recently from aaee040 to 4d688c5 Compare November 15, 2024 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants