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

Added initial version of dump-restore script. #380

Open
wants to merge 14 commits into
base: jena4-upgrade
Choose a base branch
from

Conversation

ivanmrsulja
Copy link
Member

@ivanmrsulja ivanmrsulja commented Mar 17, 2023

What's new?

This functionality was only available through UI in admin panel, now, it is available through .sh and .bat script so that it can be setup as cron job with minimal configuration.

How should this be tested?

If you are willing to use the script the server has to be running. The CLI arguments are as follows:
bash dumpRestore.sh <action>

Action can be: dump or restore

For script to work, you have to configure parameters in setenv script. Because these parameters rarely change, I figured that someone can just edit few lines of the setenv script so that the command doesn't get cluttered with a lot of arguments:

models="CONTENT"                          # Models to be dumped/restored (CONTENT, CONFIGURATION etc...)
email="[email protected]"                   # Admin account email
password="password"                       # Admin account password

host="http://example:port"                # URL where the VIVO instance is hosted
purge="true"                              # Will the restoration process purge the models before restoring
restoration_files_path="."                # Directory containing the files used for restoration (restore files must be named as their corresponding models >> CONTENT.nq, CONFIGURATION.nq etc...)
dumped_files_path=$restoration_files_path # Directory containing the backed-up files
app_name="vivo"                           # app-name parameter

Interested parties

@chenejac @milospp

@chenejac chenejac requested review from a user, litvinovg and brianjlowe March 20, 2023 12:32
@litvinovg
Copy link
Contributor

I tried to dump data in linux environment, but it didn't work for me.
It prints that dump has been successfully created, but the file CONTENT.nq is empty
I suggest to add error checks and messages in case cookie wasn't returned and check return code of the dump request as well as the file size (not empty).
Also it might be useful to use date in output file name.

curl 7.61.1 (x86_64-redhat-linux-gnu) libcurl/7.61.1 OpenSSL/1.1.1k zlib/1.2.11 brotli/1.0.6 libidn2/2.2.0 libpsl/0.20.2 (+libidn2/2.2.0) libssh/0.9.6/openssl/zlib nghttp2/1.33.0

loginForm="Log in"

# Log in and get session cookies
curl --cookie-jar "$session/cookies.txt" -d "loginName=$loginName" -d "loginPassword=$loginPassword" -d "loginForm=$loginForm" $url
Copy link
Contributor

@litvinovg litvinovg Mar 20, 2023

Choose a reason for hiding this comment

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

I think it should be --data-urlencode for login and password instead of -d as with -d "+" sign is interpreted as a space character

Copy link
Member Author

Choose a reason for hiding this comment

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

I have improved URL encoding as you advised, thank you for debugging the problem for me.

set loginForm=Log in

:: Log in and get session cookies
curl --cookie-jar "%session%\cookies.txt" --create-dirs -d "loginName=%loginName%" -d "loginPassword=%loginPassword%" -d "loginForm=%loginForm%" %url%
Copy link
Contributor

@litvinovg litvinovg Mar 20, 2023

Choose a reason for hiding this comment

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

I think if you try to use login with + sign it wouldn't work here too. See comment below.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is still -d here. I haven't tested it on Windows, but maybe we should also use --data-urlencode here?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, I forgot to add it here for username and password. I will change it right now.

if "%action%" == "dump" (
echo Starting dump...

curl --cookie "%session%\cookies.txt" "%host%/%app_name%/dumpRestore/dump/%models%.nq?which=%models%" -o "%dumped_files_path%\%models%.nq"
Copy link
Contributor

Choose a reason for hiding this comment

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

Check return code (should be 200, not 302)
If return code is 302 then most likely authorization failed.
I would also check size of returned file. It shouldn't be empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added the necessary check, as you advised.


if [[ "$action" == "dump" ]]; then
echo "Starting dump..."
curl --cookie "$session/cookies.txt" "$host/$app_name/dumpRestore/dump/$models.nq?which=$models" -o "$dumped_files_path/$models.nq"
Copy link
Contributor

Choose a reason for hiding this comment

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

Check return code (should be 200, not 302)
If return code is 302 then most likely authorization failed.
I would also check size of returned file. It shouldn't be empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added the necessary check, as you advised.

Copy link
Contributor

@litvinovg litvinovg left a comment

Choose a reason for hiding this comment

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

I think login/password escaping should be fixed.
We should also check if dump failed and print some messages to inform user.

@ivanmrsulja
Copy link
Member Author

I have improved the URL encoding and added necessary checks, as @litvinovg advised.

@ivanmrsulja ivanmrsulja requested review from litvinovg and removed request for brianjlowe and a user March 21, 2023 09:21
@chenejac chenejac requested review from a user and brianjlowe March 21, 2023 09:26
@chenejac chenejac linked an issue Apr 6, 2023 that may be closed by this pull request
3 tasks
@chenejac chenejac self-requested a review April 10, 2023 10:15
Copy link
Contributor

@chenejac chenejac left a comment

Choose a reason for hiding this comment

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

@ivanmrsulja can we apply similar approach as Tomcat is using with setenv.sh (setenv.bat) file, meaning dumpRestore.bat and dumpRestore.sh might be renamed to vivo-admin.bat and vivo-admin.sh, and there might be additional files example.setenv.sh and example.setenv.bat? All scripts parameters might be specified in those setenv.sh/bat files except action. The files might stay at the script directory in the VIVO code base, but can be copied to VIVO_HOME/bin by using this file - https://github.com/vivo-project/Vitro/blob/main/home/src/main/assembly/home.xml

Copy link
Contributor

@chenejac chenejac left a comment

Choose a reason for hiding this comment

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

@ivanmrsulja it works for me (Windows 10). I have tried to create dump of content graph and to restore. Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Making scripts for live backup of TDB
3 participants