Skip to content

Commit

Permalink
Merge pull request #5 from redpencilio/feature/backup-script
Browse files Browse the repository at this point in the history
added scripts to generate backups and some general maintenance tasks
  • Loading branch information
nvdk authored Jul 13, 2022
2 parents 8f3cbae + fed52d6 commit ab72efb
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
kind: pipeline
type: docker
name: push-latest
Expand Down Expand Up @@ -46,3 +47,17 @@ steps:
trigger:
event:
- pull_request
---
kind: secret
name: docker_username
data: RIRsbI8DZz2JGGUHsUp4zU5qtnyK/XU3xzTiUkeHIjOzhIH9+/ozwiIFniT3dWBYcQ==
---
kind: secret
name: docker_password
data: 7ocNZAPA+djeVNr4lf8RAANxyiDDmilj/42UILm8h25Umh4kkDVvdLG92cSgX2JdXirLEMlNxjw+iA0yLYh1Ug==

---
kind: signature
hmac: df3b659cb4f53b7b18e128cf365183953239a9523ce20e09faaa3a11941098e5

...
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ COPY virtuoso.sh /virtuoso.sh
RUN ln -s /usr/local/virtuoso-opensource/var/lib/virtuoso/ /var/lib/virtuoso \
&& ln -s /var/lib/virtuoso/db /data

# Add mu scripts
COPY ./scripts/ /app/scripts/

WORKDIR /data
EXPOSE 8890
EXPOSE 1111
Expand Down
34 changes: 34 additions & 0 deletions scripts/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": "0.1",
"scripts": [
{
"documentation": {
"command": "create-backup",
"description": "A virtuoso backup will be created db/backups.\n Parameters:\n prefix: default backup_${DATE}\n hostname: default triplestore\n username: default dba\n password: default dba",
"arguments": ["prefix", "hostname", "username", "password"]
},
"environment": {
"image": "redpencil/virtuoso",
"interactive": false,
"script": "virtuoso/create-backup.sh",
"join_networks": true
},
"mounts": {
"app": "/project/"
}
},
{
"documentation": {
"command": "maintenance",
"description": "Execute basic maintenance commands.\n Parameters:\n command : needs to be one of 'checkpoint', 'vacuum', 'dump_quads'\n hostname: default triplestore\n username: default dba\n password: default dba",
"arguments": ["command", "hostname", "username", "password"]
},
"environment": {
"image": "redpencil/virtuoso",
"interactive": false,
"script": "virtuoso/maintenance.sh",
"join_networks": true
}
}
]
}
28 changes: 28 additions & 0 deletions scripts/virtuoso/create-backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
USERNAME=${3:-"dba"}
PASSWORD=${4:-"dba"}
TRIPLESTORE=${2:-"triplestore"}
DATE=`date +%Y%0m%0d%0H%0M%0S`
PREFIX=${1:-"backup_${DATE}_"}
if [[ "$#" -ge 4 ]]; then
echo "Usage:"
echo " mu script triplestore [prefix] [hostname] [username] [password]"
exit -1;
fi

if [[ -d "/project/data/db" ]];then
mkdir -p /project/data/db/backups
else
echo "WARNING:"
echo " did not find data/db folder in your project, so did not create data/db/backups!"
echo " "
fi

echo "connecting to $TRIPLESTORE with $USERNAME"
isql-v -H $TRIPLESTORE -U $USERNAME -P $PASSWORD <<EOF
exec('checkpoint');
backup_context_clear();
backup_online('${PREFIX}',30000,0,vector('backups'));
exit;
EOF

32 changes: 32 additions & 0 deletions scripts/virtuoso/maintenance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
USERNAME=${3:-"dba"}
PASSWORD=${4:-"dba"}
TRIPLESTORE=${2:-"triplestore"}
COMMAND=$1

if [[ "$#" -lt 1 ]]; then
echo "command is a required parameter"
exit -1
fi

case $COMMAND in
"checkpoint")
isql-v -H $TRIPLESTORE -U $USERNAME -P $PASSWORD <<EOF
exec('checkpoint');
EOF
;;
"vacuum")
isql-v -H $TRIPLESTORE -U $USERNAME -P $PASSWORD <<EOF
DB.DBA.vacuum();
EOF
;;
"dump_quads")
isql-v -H $TRIPLESTORE -U $USERNAME -P $PASSWORD <<EOF
dump_nquads ('dumps', 1, 100000000, 1);
EOF
echo "dumped quads to data/db/dumps"
;;
*)
echo "unrecognized command $COMMAND"
exit -1
esac

0 comments on commit ab72efb

Please # to comment.