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
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions home/src/main/resources/scripts/dumpRestore.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@echo off

set action=%1%
set models=%2%
set email=%3%
set password=%4%

set host=http://example:port
set purge=true
set restoration_files_path=.
set dumped_files_path=%restoration_files_path%
set app_name=vivo

set session=%TEMP%\%RANDOM%
mkdir "%session%"

set url=%host%/%app_name%/authenticate

set loginName=%email%
set loginPassword=%password%
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.


echo Completed successfully.
) else if "%action%" == "restore" (
echo Starting restoration process...

set url=%host%/%app_name%/dumpRestore/restore

curl --cookie "%session%\cookies.txt" -X POST -F "sourceFile=@%restoration_files_path%\%models%.nq" "%url%?which=%models%&purge=%purge%" > nul

if %errorlevel% equ 0 (
echo Restored successfully.
) else (
echo Something went wrong.
)
)

rmdir /s /q "%session%"
45 changes: 45 additions & 0 deletions home/src/main/resources/scripts/dumpRestore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

action="$1"
models="$2"
email="$3"
password="$4"

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
dumped_files_path=$restoration_files_path # Directory containing the backed-up files
app_name="vivo" # app-name parameter

session=$(mktemp -d)

url="$host/$app_name/authenticate"

loginName="$email"
loginPassword="$password"
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.


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.

echo "Completed successfully."
elif [[ "$action" == "restore" ]]; then
echo "Starting restoration process..."

url="$host/$app_name/dumpRestore/restore"
files=$(echo -n "$restoration_files_path/$models.nq")
params=$(echo -n "which=$models&purge=$purge")

curl --cookie "$session/cookies.txt" -X POST -F "sourceFile=@$files" "$url?$params" > /dev/null

if [[ $? -eq 0 ]]; then
echo "Restored successfully."
else
echo "Something went wrong."
fi
fi

rm -rf "$session"