From 0f8df3597a3678797950c093b775110c5355459c Mon Sep 17 00:00:00 2001 From: Ivan Mrsulja Date: Fri, 17 Mar 2023 16:38:34 +0100 Subject: [PATCH 01/14] Added initial dump-restore script. --- .../src/main/resources/scripts/dumpRestore.sh | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 home/src/main/resources/scripts/dumpRestore.sh diff --git a/home/src/main/resources/scripts/dumpRestore.sh b/home/src/main/resources/scripts/dumpRestore.sh new file mode 100644 index 0000000000..e637985067 --- /dev/null +++ b/home/src/main/resources/scripts/dumpRestore.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +action="$1" +models="$2" +email="$3" +password="$4" + +host="http://localhost:8080" # URL where the VIVO instance is hosted +purge="true" # Will the restoration process purge the models before restoring +restoration_files="." # Directory containing the files used for restoration +dumped_files="." # Directory containing the backed-up files +app_name="vivo" # app-name parameter + +session=$(mktemp -d) + +url="$host/$app_name/authenticate" + +loginName="email@email.com" +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 + +if [[ "$action" == "dump" ]]; then + echo "Starting dump..." + curl --cookie "$session/cookies.txt" "$host/$app_name/dumpRestore/dump/$models.nq?which=$models" -o "$dumped_files/$models.nq" + echo "Completed successfully." +elif [[ "$action" == "restore" ]]; then + echo "Starting restoration process..." + + url="$host/$app_name/dumpRestore/restore" + files=$(echo -n "$restoration_files/$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" From d6c514d3eb94394185c26f7deca322d89091c3fb Mon Sep 17 00:00:00 2001 From: Ivan Mrsulja Date: Fri, 17 Mar 2023 16:54:47 +0100 Subject: [PATCH 02/14] Changed email and password to get their values from command line arguments. --- home/src/main/resources/scripts/dumpRestore.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/home/src/main/resources/scripts/dumpRestore.sh b/home/src/main/resources/scripts/dumpRestore.sh index e637985067..6b4d344e2c 100644 --- a/home/src/main/resources/scripts/dumpRestore.sh +++ b/home/src/main/resources/scripts/dumpRestore.sh @@ -15,8 +15,8 @@ session=$(mktemp -d) url="$host/$app_name/authenticate" -loginName="email@email.com" -loginPassword="password" +loginName="$email" +loginPassword="$password" loginForm="Log in" # Log in and get session cookies From a9ede4cf908d866585c64ea5deeac81ebba15022 Mon Sep 17 00:00:00 2001 From: Ivan Mrsulja Date: Mon, 20 Mar 2023 10:23:54 +0100 Subject: [PATCH 03/14] Added .bat script for dump-restore functionality. --- .../main/resources/scripts/dumpRestore.bat | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 home/src/main/resources/scripts/dumpRestore.bat diff --git a/home/src/main/resources/scripts/dumpRestore.bat b/home/src/main/resources/scripts/dumpRestore.bat new file mode 100644 index 0000000000..7b03607eca --- /dev/null +++ b/home/src/main/resources/scripts/dumpRestore.bat @@ -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=. +set dumped_files=. +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% + +if "%action%" == "dump" ( + echo Starting dump... + + curl --cookie "%session%\cookies.txt" "%host%/%app_name%/dumpRestore/dump/%models%.nq?which=%models%" -o "%dumped_files%\%models%.nq" + + 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%\%models%.nq" "%url%?which=%models%&purge=%purge%" > nul + + if %errorlevel% equ 0 ( + echo Restored successfully. + ) else ( + echo Something went wrong. + ) +) + +rmdir /s /q "%session%" From 399bd18878ddbc84cb94f710da72cb8b0e0a0181 Mon Sep 17 00:00:00 2001 From: Ivan Mrsulja Date: Mon, 20 Mar 2023 15:30:13 +0100 Subject: [PATCH 04/14] Slight refactor of variable names and initialization. --- home/src/main/resources/scripts/dumpRestore.bat | 8 ++++---- home/src/main/resources/scripts/dumpRestore.sh | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/home/src/main/resources/scripts/dumpRestore.bat b/home/src/main/resources/scripts/dumpRestore.bat index 7b03607eca..23cb3afdd2 100644 --- a/home/src/main/resources/scripts/dumpRestore.bat +++ b/home/src/main/resources/scripts/dumpRestore.bat @@ -7,8 +7,8 @@ set password=%4% set host=http://example:port set purge=true -set restoration_files=. -set dumped_files=. +set restoration_files_path=. +set dumped_files_path=%restoration_files_path% set app_name=vivo set session=%TEMP%\%RANDOM% @@ -26,7 +26,7 @@ curl --cookie-jar "%session%\cookies.txt" --create-dirs -d "loginName=%loginName if "%action%" == "dump" ( echo Starting dump... - curl --cookie "%session%\cookies.txt" "%host%/%app_name%/dumpRestore/dump/%models%.nq?which=%models%" -o "%dumped_files%\%models%.nq" + curl --cookie "%session%\cookies.txt" "%host%/%app_name%/dumpRestore/dump/%models%.nq?which=%models%" -o "%dumped_files_path%\%models%.nq" echo Completed successfully. ) else if "%action%" == "restore" ( @@ -34,7 +34,7 @@ if "%action%" == "dump" ( set url=%host%/%app_name%/dumpRestore/restore - curl --cookie "%session%\cookies.txt" -X POST -F "sourceFile=@%restoration_files%\%models%.nq" "%url%?which=%models%&purge=%purge%" > nul + 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. diff --git a/home/src/main/resources/scripts/dumpRestore.sh b/home/src/main/resources/scripts/dumpRestore.sh index 6b4d344e2c..305f5d4d22 100644 --- a/home/src/main/resources/scripts/dumpRestore.sh +++ b/home/src/main/resources/scripts/dumpRestore.sh @@ -5,11 +5,11 @@ models="$2" email="$3" password="$4" -host="http://localhost:8080" # URL where the VIVO instance is hosted -purge="true" # Will the restoration process purge the models before restoring -restoration_files="." # Directory containing the files used for restoration -dumped_files="." # Directory containing the backed-up files -app_name="vivo" # app-name parameter +host="http://localhost:8080" # 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) @@ -24,13 +24,13 @@ curl --cookie-jar "$session/cookies.txt" -d "loginName=$loginName" -d "loginPass if [[ "$action" == "dump" ]]; then echo "Starting dump..." - curl --cookie "$session/cookies.txt" "$host/$app_name/dumpRestore/dump/$models.nq?which=$models" -o "$dumped_files/$models.nq" + curl --cookie "$session/cookies.txt" "$host/$app_name/dumpRestore/dump/$models.nq?which=$models" -o "$dumped_files_path/$models.nq" echo "Completed successfully." elif [[ "$action" == "restore" ]]; then echo "Starting restoration process..." url="$host/$app_name/dumpRestore/restore" - files=$(echo -n "$restoration_files/$models.nq") + 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 From 06578b4d376beb933471f6b37ca0116deb850217 Mon Sep 17 00:00:00 2001 From: Ivan Mrsulja Date: Mon, 20 Mar 2023 15:33:12 +0100 Subject: [PATCH 05/14] Removed testing value for host variable. --- home/src/main/resources/scripts/dumpRestore.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/home/src/main/resources/scripts/dumpRestore.sh b/home/src/main/resources/scripts/dumpRestore.sh index 305f5d4d22..6bbdc4db9e 100644 --- a/home/src/main/resources/scripts/dumpRestore.sh +++ b/home/src/main/resources/scripts/dumpRestore.sh @@ -5,7 +5,7 @@ models="$2" email="$3" password="$4" -host="http://localhost:8080" # URL where the VIVO instance is hosted +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 From daee7593774a343265415b9a7b23c7b72f80b20a Mon Sep 17 00:00:00 2001 From: Ivan Mrsulja Date: Tue, 21 Mar 2023 10:18:27 +0100 Subject: [PATCH 06/14] Added necessary checks and fixed url encoding. --- .../main/resources/scripts/dumpRestore.bat | 44 ++++++++++++------- .../src/main/resources/scripts/dumpRestore.sh | 20 +++++++-- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/home/src/main/resources/scripts/dumpRestore.bat b/home/src/main/resources/scripts/dumpRestore.bat index 23cb3afdd2..f1246db43e 100644 --- a/home/src/main/resources/scripts/dumpRestore.bat +++ b/home/src/main/resources/scripts/dumpRestore.bat @@ -1,46 +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 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% - + 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" - - echo Completed successfully. + + 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%" + +rmdir /s /q "%session%" \ No newline at end of file diff --git a/home/src/main/resources/scripts/dumpRestore.sh b/home/src/main/resources/scripts/dumpRestore.sh index 6bbdc4db9e..56cb515d41 100644 --- a/home/src/main/resources/scripts/dumpRestore.sh +++ b/home/src/main/resources/scripts/dumpRestore.sh @@ -20,12 +20,26 @@ 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 +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..." - curl --cookie "$session/cookies.txt" "$host/$app_name/dumpRestore/dump/$models.nq?which=$models" -o "$dumped_files_path/$models.nq" - echo "Completed successfully." + + 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..." From 9b498fbd6d50bf44629c5f169d0d0738a6da5900 Mon Sep 17 00:00:00 2001 From: Ivan Mrsulja Date: Tue, 21 Mar 2023 12:43:57 +0100 Subject: [PATCH 07/14] Added --data-urlencode option when logging in via .bat script. --- home/src/main/resources/scripts/dumpRestore.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/home/src/main/resources/scripts/dumpRestore.bat b/home/src/main/resources/scripts/dumpRestore.bat index f1246db43e..2415a41ef9 100644 --- a/home/src/main/resources/scripts/dumpRestore.bat +++ b/home/src/main/resources/scripts/dumpRestore.bat @@ -21,7 +21,7 @@ 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% +curl --cookie-jar "%session%\cookies.txt" --create-dirs --data-urlencode "loginName=%loginName%" --data-urlencode "loginPassword=%loginPassword%" -d "loginForm=%loginForm%" %url% if "%action%" == "dump" ( echo Starting dump... From 6772b472a778c2ebd5935d3352dee01a6c73d727 Mon Sep 17 00:00:00 2001 From: Ivan Mrsulja Date: Tue, 21 Mar 2023 12:50:56 +0100 Subject: [PATCH 08/14] Renamed variables to match snake-case convention. --- home/src/main/resources/scripts/dumpRestore.bat | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/home/src/main/resources/scripts/dumpRestore.bat b/home/src/main/resources/scripts/dumpRestore.bat index 2415a41ef9..c1e3065499 100644 --- a/home/src/main/resources/scripts/dumpRestore.bat +++ b/home/src/main/resources/scripts/dumpRestore.bat @@ -16,12 +16,12 @@ mkdir "%session%" set url=%host%/%app_name%/authenticate -set loginName=%email% -set loginPassword=%password% -set loginForm=Log in +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=%loginName%" --data-urlencode "loginPassword=%loginPassword%" -d "loginForm=%loginForm%" %url% +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... From 6748039f22a5255b22faf2d2b96a706cfc495706 Mon Sep 17 00:00:00 2001 From: Ivan Mrsulja Date: Tue, 11 Apr 2023 14:56:21 +0200 Subject: [PATCH 09/14] Renamed scripts to vivo-admin. Added example.setenv.sh script for configuring functionality on linux. --- home/src/main/resources/scripts/example.setenv.sh | 11 +++++++++++ .../scripts/{dumpRestore.bat => vivo-admin.bat} | 0 .../scripts/{dumpRestore.sh => vivo-admin.sh} | 11 ++--------- 3 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 home/src/main/resources/scripts/example.setenv.sh rename home/src/main/resources/scripts/{dumpRestore.bat => vivo-admin.bat} (100%) rename home/src/main/resources/scripts/{dumpRestore.sh => vivo-admin.sh} (75%) diff --git a/home/src/main/resources/scripts/example.setenv.sh b/home/src/main/resources/scripts/example.setenv.sh new file mode 100644 index 0000000000..4bd60c3847 --- /dev/null +++ b/home/src/main/resources/scripts/example.setenv.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +models="CONTENT" # Models to be dumped/restored (CONTENT, CONFIGURATION etc...) +email="email@email.com" # 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 \ No newline at end of file diff --git a/home/src/main/resources/scripts/dumpRestore.bat b/home/src/main/resources/scripts/vivo-admin.bat similarity index 100% rename from home/src/main/resources/scripts/dumpRestore.bat rename to home/src/main/resources/scripts/vivo-admin.bat diff --git a/home/src/main/resources/scripts/dumpRestore.sh b/home/src/main/resources/scripts/vivo-admin.sh similarity index 75% rename from home/src/main/resources/scripts/dumpRestore.sh rename to home/src/main/resources/scripts/vivo-admin.sh index 56cb515d41..ca900976e5 100644 --- a/home/src/main/resources/scripts/dumpRestore.sh +++ b/home/src/main/resources/scripts/vivo-admin.sh @@ -1,15 +1,8 @@ #!/bin/bash +source ./setenv.sh + 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) From cfe9d4896c82566adf043878d037d07e3698439f Mon Sep 17 00:00:00 2001 From: Ivan Mrsulja Date: Tue, 11 Apr 2023 15:06:26 +0200 Subject: [PATCH 10/14] Added example.setenv.bat configuration script. --- home/src/main/resources/scripts/example.setenv.bat | 11 +++++++++++ home/src/main/resources/scripts/example.setenv.sh | 2 +- home/src/main/resources/scripts/vivo-admin.bat | 11 ++--------- 3 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 home/src/main/resources/scripts/example.setenv.bat diff --git a/home/src/main/resources/scripts/example.setenv.bat b/home/src/main/resources/scripts/example.setenv.bat new file mode 100644 index 0000000000..971e51f7a7 --- /dev/null +++ b/home/src/main/resources/scripts/example.setenv.bat @@ -0,0 +1,11 @@ +@echo off + +set models=CONTENT rem Models to be dumped/restored (CONTENT, CONFIGURATION etc...) +set email=email@email.com rem Admin account email +set password=password rem Admin account password + +set host=http://example:port rem URL where the VIVO instance is hosted +set purge=true rem Will the restoration process purge the models before restoring +set restoration_files_path=. rem Directory containing the files used for restoration (restore files must be named as their corresponding models >> CONTENT.nq, CONFIGURATION.nq etc...) +set dumped_files_path=%restoration_files_path% rem Directory containing the backed-up files +set app_name=vivo rem app-name parameter \ No newline at end of file diff --git a/home/src/main/resources/scripts/example.setenv.sh b/home/src/main/resources/scripts/example.setenv.sh index 4bd60c3847..7aaf79d00c 100644 --- a/home/src/main/resources/scripts/example.setenv.sh +++ b/home/src/main/resources/scripts/example.setenv.sh @@ -8,4 +8,4 @@ host="http://example:port" # URL where the VIVO instance is hoste 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 \ No newline at end of file +app_name="vivo" # app-name parameter diff --git a/home/src/main/resources/scripts/vivo-admin.bat b/home/src/main/resources/scripts/vivo-admin.bat index c1e3065499..8da7d89f25 100644 --- a/home/src/main/resources/scripts/vivo-admin.bat +++ b/home/src/main/resources/scripts/vivo-admin.bat @@ -1,15 +1,8 @@ @echo off +call ./setenv.bat + 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%" From 5581fd30bf5c8521d5a236430acfbbd0950398f4 Mon Sep 17 00:00:00 2001 From: Ivan Mrsulja Date: Thu, 13 Apr 2023 16:41:02 +0200 Subject: [PATCH 11/14] Updated home.xml to copy scripts/ directory into vivo-home/bin/ directory. --- home/src/main/assembly/home.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/home/src/main/assembly/home.xml b/home/src/main/assembly/home.xml index c02d3e3751..462707052f 100644 --- a/home/src/main/assembly/home.xml +++ b/home/src/main/assembly/home.xml @@ -21,6 +21,14 @@ ${project.basedir}/src/main/resources . + + scripts/** + scripts + + + + ${project.basedir}/src/main/resources/scripts + bin