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 all 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
8 changes: 8 additions & 0 deletions home/src/main/assembly/home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory>.</outputDirectory>
<excludes>
<exclude>scripts/**</exclude>
<exclude>scripts</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/resources/scripts</directory>
<outputDirectory>bin</outputDirectory>
</fileSet>
<!-- fileSet>
<directory>${project.build.directory}</directory>
Expand Down
11 changes: 11 additions & 0 deletions home/src/main/resources/scripts/example.setenv.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off

set models=CONTENT
set [email protected]
set password=password

set host=http://example:port
set purge=true
set restoration_files_path=.
set dumped_files_path=%restoration_files_path%
set app_name=vivo
11 changes: 11 additions & 0 deletions home/src/main/resources/scripts/example.setenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

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
49 changes: 49 additions & 0 deletions home/src/main/resources/scripts/vivo-admin.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
@echo off

call ./setenv.bat

set action=%1%

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...

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

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

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

source ./setenv.sh

action="$1"

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"