Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 28b958598857831fb2833a03e60a175e9f58a382 1 parent d6b33aa
@liudong authored
View
80 pom.xml
@@ -0,0 +1,80 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>uk.ac.open.kmi</groupId>
+ <artifactId>sesame-backup</artifactId>
+ <version>0.0.1</version>
+ <packaging>jar</packaging>
+
+ <name>Sesame Auto-backup</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>1.6</maven.compiler.source>
+ <maven.compiler.target>1.6</maven.compiler.target>
+ </properties>
+
+ <developers>
+ <developer>
+ <id>dong</id>
+ <name>Dong Liu</name>
+ <email>d.liu-{AT}-open.ac.uk</email>
+ <organization>Knowledge Media Institute - The Open University</organization>
+ <organizationUrl>http://kmi.open.ac.uk</organizationUrl>
+ </developer>
+ </developers>
+
+ <organization>
+ <name>Knowledge Media Institute - The Open University</name>
+ <url>http://kmi.open.ac.uk</url>
+ </organization>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.semweb4j</groupId>
+ <artifactId>rdf2go.api</artifactId>
+ <version>4.7.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.semweb4j</groupId>
+ <artifactId>rdf2go.impl.sesame23</artifactId>
+ <version>4.7.3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>semweb4j-repo</id>
+ <name>Semweb4j.org maven repo</name>
+ <url>http://semweb4j.org/repo/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </repository>
+ <repository>
+ <id>semweb4j-snapshots</id>
+ <name>Semweb4j.org maven snapshot repo</name>
+ <url>http://semweb4j.org/snapshots/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>always</updatePolicy>
+ <checksumPolicy>fail</checksumPolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+</project>
View
57 src/main/java/uk/ac/open/kmi/util/backup/RDFRepositoryConnector.java
@@ -0,0 +1,57 @@
+/*
+ Copyright ${year} Knowledge Media Institute - The Open University
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+package uk.ac.open.kmi.util.backup;
+
+import org.openrdf.rdf2go.RepositoryModel;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.http.HTTPRepository;
+
+public class RDFRepositoryConnector {
+
+ private Repository sesameRepository;
+
+ public RDFRepositoryConnector(String serverUri, String repositoryName) throws RepositoryException {
+ if ( null == serverUri || null == serverUri.toString() || "" == serverUri.toString() ||
+ null == repositoryName || "" == repositoryName ) {
+ return;
+ }
+ sesameRepository = new HTTPRepository(serverUri.toString(), repositoryName);
+ sesameRepository.initialize();
+ }
+
+ public RepositoryModel openRepositoryModel() {
+ if ( null == sesameRepository ) {
+ return null;
+ }
+ RepositoryModel result = new RepositoryModel(sesameRepository);
+ if ( result != null ) {
+ result.open();
+ }
+ return result;
+ }
+
+ public void closeRepositoryModel(RepositoryModel modelToClose) {
+ if ( modelToClose != null ) {
+ modelToClose.close();
+ }
+ }
+
+ public HTTPRepository getRepository() {
+ return (HTTPRepository) sesameRepository;
+ }
+
+}
View
82 src/main/java/uk/ac/open/kmi/util/backup/SesameBackup.java
@@ -0,0 +1,82 @@
+/*
+ Copyright ${year} Knowledge Media Institute - The Open University
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+package uk.ac.open.kmi.util.backup;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import org.ontoware.rdf2go.exception.ModelRuntimeException;
+import org.ontoware.rdf2go.model.Syntax;
+import org.openrdf.rdf2go.RepositoryModel;
+import org.openrdf.repository.RepositoryException;
+
+import uk.ac.open.kmi.util.backup.config.Configuration;
+
+public class SesameBackup {
+
+ private String sesameServerUri;
+
+ private List<String> repoList;
+
+ private String bakFolderPath;
+
+ public SesameBackup(Configuration config) {
+ sesameServerUri = config.getSesameServerUri();
+ repoList = config.getRepositoryList();
+ bakFolderPath = config.getBackupFolderPath();
+ }
+
+ public void backupNow() throws RepositoryException, ModelRuntimeException, IOException {
+ for ( String repoName : repoList ) {
+ backupOneRepository(repoName);
+ }
+ }
+
+ public static void main(String[] args) {
+ Configuration config = Configuration.getInstance();
+ SesameBackup backup = new SesameBackup(config);
+ try {
+ backup.backupNow();
+ } catch (RepositoryException e) {
+ e.printStackTrace();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (ModelRuntimeException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void backupOneRepository(String repoName) throws RepositoryException, ModelRuntimeException, IOException {
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ String fileName = repoName + "." + dateFormat.format(new Date()) + ".trig";
+ System.out.println(bakFolderPath + fileName);
+ RDFRepositoryConnector connector = new RDFRepositoryConnector(sesameServerUri, repoName);
+ RepositoryModel model = connector.openRepositoryModel();
+ File file = new File(bakFolderPath + fileName);
+ FileOutputStream os = new FileOutputStream(file);
+ model.writeTo(os, Syntax.Trig);
+ os.close();
+ connector.closeRepositoryModel(model);
+ }
+
+}
View
83 src/main/java/uk/ac/open/kmi/util/backup/config/Configuration.java
@@ -0,0 +1,83 @@
+/*
+ Copyright ${year} Knowledge Media Institute - The Open University
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+package uk.ac.open.kmi.util.backup.config;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+public class Configuration {
+
+ private static final Configuration me = new Configuration();
+
+ private static final String PROPERTIES_FILEPATH = "/config.properties";
+
+ private static final String SESAME_SERVER_URI = "sesameServerURL";
+
+ private static final String REPOSITORY_LIST = "repoName";
+
+ private static final String BACKUP_FOLDER_PATH = "bakFolder";
+
+ private String sesameServerUri;
+
+ private String repositoryList;
+
+ private String backupFolderPath;
+
+ public String getSesameServerUri() {
+ return sesameServerUri;
+ }
+
+ public List<String> getRepositoryList() {
+ if (null == repositoryList || "" == repositoryList) {
+ return null;
+ }
+ List<String> result = new ArrayList<String>();
+ String[] strings = repositoryList.split(",");
+ for ( String repo : strings ) {
+ result.add(repo);
+ }
+ return result;
+ }
+
+ public String getBackupFolderPath() {
+ return backupFolderPath;
+ }
+
+ public static Configuration getInstance() {
+ return me;
+ }
+
+ private Configuration() {
+ Properties properties = new Properties();
+ try {
+ properties.load(this.getClass().getResourceAsStream(PROPERTIES_FILEPATH));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ sesameServerUri = properties.getProperty(SESAME_SERVER_URI);
+ repositoryList = properties.getProperty(REPOSITORY_LIST);
+ backupFolderPath = properties.getProperty(BACKUP_FOLDER_PATH);
+ }
+
+ public static void main(String[] args) {
+ Configuration config = Configuration.getInstance();
+ System.out.println(config.getSesameServerUri());
+ System.out.println(config.getBackupFolderPath());
+ config.getRepositoryList();
+ }
+}
View
6 src/main/resources/config.properties
@@ -0,0 +1,6 @@
+# Sesame server
+sesameServerURL = http://localhost:8080/openrdf-sesame
+# A , separated list of RDF stores
+repoName = repo1
+# MUST end with "/"
+bakFolder = data-backup/
Please sign in to comment.
Something went wrong with that request. Please try again.