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 8 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
58 changes: 58 additions & 0 deletions home/src/main/resources/scripts/dumpRestore.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@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 login_name=%email%
set login_password=%password%
set login_form=Log in

:: Log in and get session cookies
curl --cookie-jar "%session%\cookies.txt" --create-dirs --data-urlencode "loginName=%login_name%" --data-urlencode "loginPassword=%login_password%" -d "loginForm=%login_form%" %url%

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

for /f "tokens=* usebackq" %%F in (`curl --silent -w %%{http_code}%% --cookie "%session%\cookies.txt" "%host%/%app_name%/dumpRestore/dump/%models%.nq?which=%models%" -o "%dumped_files_path%\%models%.nq"`) do (
if "%%F" == "302%%" (
echo "Dump failed, status code is %%F. check login credentials, parameters and try again."
)
)

for %%A in ("%dumped_files_path%\%models%.nq") do (
if %%~zA equ 0 (
echo "Dump file is empty, deleting..."
del "%dumped_files_path%\%models%.nq"
) else (
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%"
59 changes: 59 additions & 0 deletions home/src/main/resources/scripts/dumpRestore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/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" --data-urlencode "loginName=$loginName" --data-urlencode "loginPassword=$loginPassword" -d "loginForm=$loginForm" $url

if [[ "$action" == "dump" ]]; then
echo "Starting dump..."

dump_file_path="$dumped_files_path/$models.nq"

status_code=$(curl --write-out %{http_code} --cookie "$session/cookies.txt" "$host/$app_name/dumpRestore/dump/$models.nq?which=$models" -o "$dump_file_path")

if [[ "$status_code" -ne 200 ]]; then
echo "Dump failed, status code is $status_code, check login credentials, parameters and try again."
fi

if [ -s $dump_file_path ]; then
echo "Completed successfully."
else
echo "Dump file is empty, deleting..."
rm -r "$dump_file_path"
fi

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"