Index: /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java =================================================================== --- /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java (revision 0) +++ /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java (revision 0) @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.jackrabbit.backup; + +import org.apache.jackrabbit.core.RepositoryImpl; + +/** + * This class is the abstract class of all resources to backup. If you need to add a new backuped resource + * extend Backup and implement both the save and restore methods. + * + * The constructor is called when instantiating the specific backup resource class through RepositoryBackup. + */ +public abstract class Backup { + + RepositoryImpl repo; + BackupConfig conf; + String name; + + /** + * + * @param repo The repository to backup + * @param conf The specific BackupConfig object (usually a subset of backup.xml) + * @param name Name of the resource to backup. Unique. Useful? + */ + public Backup(RepositoryImpl repo, BackupConfig conf) { + this.repo = repo; + this.conf = conf; + } + + public void setRepo(RepositoryImpl repo) { + this.repo = repo; + } + + public RepositoryImpl getRepo() { + return this.repo; + } + + public abstract void backup(BackupIOHandler out); + public abstract void restore(BackupIOHandler in); + + + +} Index: /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java =================================================================== --- /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java (revision 0) +++ /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java (revision 0) @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.jackrabbit.backup; + +import java.io.File; +import java.io.InputStream; +import java.net.URI; +import java.util.Properties; + +import org.apache.jackrabbit.core.RepositoryImpl; +import org.apache.jackrabbit.core.config.ConfigurationException; +import org.apache.jackrabbit.core.config.ConfigurationParser; +import org.apache.jackrabbit.core.config.RepositoryConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.InputSource; + + +/** + * Backup configuration. This configuration class is used to + * create configured backup objects. + *

+ * The contained configuration information are: the home directory and name + * of the repository, the access manager, file system and versioning + * configuration, repository index configuration, the workspace directory, + * the default workspace name, and the workspace configuration template. In + * addition the workspace configuration object keeps track of all configured + * workspaces. + */ +public class BackupConfig { + + /** the default logger */ + private static Logger log = LoggerFactory.getLogger(BackupConfig.class); + + /** + * Convenience method that wraps the configuration file name into an + * {@link InputSource} and invokes the + * {@link #create(InputSource, String)} method. + * + * @param file repository configuration file name + * @param home repository home directory + * @return backup configuration + * @throws ConfigurationException on configuration errors + * @see #create(InputSource, String) + */ + public static BackupConfig create(String file, String home) + throws ConfigurationException { + URI uri = new File(file).toURI(); + return create(new InputSource(uri.toString()), home); + } + + /** + * Convenience method that wraps the configuration URI into an + * {@link InputSource} and invokes the + * {@link #create(InputSource, String)} method. + * + * @param uri repository configuration URI + * @param home repository home directory + * @return backup configuration + * @throws ConfigurationException on configuration errors + * @see #create(InputSource, String) + */ + public static BackupConfig create(URI uri, String home) + throws ConfigurationException { + return create(new InputSource(uri.toString()), home); + } + + /** + * Convenience method that wraps the configuration input stream into an + * {@link InputSource} and invokes the + * {@link #create(InputSource, String)} method. + * + * @param input repository configuration input stream + * @param home repository home directory + * @return backup configuration + * @throws ConfigurationException on configuration errors + * @see #create(InputSource, String) + */ + public static BackupConfig create(InputStream input, String home) + throws ConfigurationException { + return create(new InputSource(input), home); + } + + /** + * Parses the given repository configuration document and returns the + * parsed and initialized repository configuration. The given repository + * home directory path will be used as the ${rep.home} parser variable. + *

+ * Note that in addition to parsing the repository configuration, this + * method also initializes the configuration (creates the configured + * directories, etc.). The {@link ConfigurationParser} class should be + * used directly to just parse the configuration. + * + * @param xml repository configuration document + * @param home repository home directory + * @return repository configuration + * @throws ConfigurationException on configuration errors + */ + public static BackupConfig create(InputSource xml) + throws ConfigurationException { + Properties variables = new Properties(); + variables.setProperty( + ConfigurationParser.REPOSITORY_HOME_VARIABLE, home); + ConfigurationParser parser = new ConfigurationParser(variables); + + BackupConfig config = parser.parseBackupConfig(xml); + config.init(); + + return config; + } + + + public BackupConfig() { + // TODO Auto-generated constructor stub + } + + public Backup getBackup() { + // TODO Auto-generated method stub + return null; + } + + public void setRepo(RepositoryImpl impl) { + // TODO Auto-generated method stub + } + +} Index: /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java =================================================================== --- /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java (revision 0) +++ /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java (revision 0) @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.jackrabbit.backup; + +public interface BackupIOHandler { + + void setMaxFileSize(int i); + int getMaxFileSize(); + //Add reference to the file + // How to precise if in or out... Maybe not needed? + +} Index: /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java =================================================================== --- /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java (revision 0) +++ /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java (revision 0) @@ -0,0 +1,205 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.jackrabbit.backup; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +import javax.jcr.AccessDeniedException; +import javax.jcr.RepositoryException; + +import org.apache.jackrabbit.core.RepositoryImpl; +import org.apache.jackrabbit.core.config.RepositoryConfig; +import org.xml.sax.InputSource; + +/** + * LaunchBackup is a command line tool and a demo tool for the backup tool. To + * get all available options please type LaunchBackup --help + * Used to launch a backup while the repository is inactive. + * + * @author Nicolas Toper + * Date: 23-jun-06 + */ +public class LaunchBackup { + + static BackupIOHandler h; + RepositoryImpl repo; + BackupConfig conf; + RepositoryConfig repoConf; + RepositoryBackup backup; + + + + /** + * The command line tool. + * + * LaunchBackup --zip myzip.zip --size 2 --conf backup.xml backup repository.xml repository/ + * LaunchBackup --zip ./myzip.zip --size 2 --conf backup.xml restore repository.xml repository/ + * + * --zip: where is the zip file (only implemented way to backup for now) + * --size in Go + * + * --conf: path to the config file for the backup tool + * + * backup/restore: whether you want a backup or a restore + * + * repository.xml: path to the config file of the repository + * + * repository/ is the name of the repository + * + * + * --help for help option + * @throws RepositoryException + * @throws IOException + * @throws IOException + * + */ + public static void main(String[] args) throws RepositoryException, AccessDeniedException, IOException { + // I have to declare all var here so they are not resetted out of the for. + String zipFile = null; + String confFile = null; + String home = null; + String repoConfFile = null; + + //2 booleans in case the user specified nothing + boolean isBackup = false; + boolean isRestore = false; + + //Parse the command line. + for (int i = 0; i < args.length; i++) { + + if ( args[i].equals("--help") || args.length == 0) { + usage(); + } + + if (args[i].equals("--zip")){ + zipFile = args[i + 1]; + //We put it here because later we might offer other possibilities than only zip + h = new ZipFileBackupIOHandler(zipFile); + } + + + if (args[i].equals("--size") && !(h != null)){ + + Integer max = (new Integer(args[i+ 1])); + h.setMaxFileSize(max.intValue()); + } + + if (args[i].equals("--size") && !(h != null)){ + + Integer max = (new Integer(args[i+ 1])); + h.setMaxFileSize(max.intValue()); + } + + + if (args[i].equals("--conf") && !(h != null)){ + + confFile = args[i + 1]; + + } + + if (args[i].equals("backup") && isRestore == false ){ + isBackup = true; + repoConfFile = args[i + 1]; + home = args[i + 2]; + + } + + if (args[i].equals("restore") && isBackup == false ){ + isRestore = true; + repoConfFile = args[i + 1]; + home = args[i + 2]; + } + } + + LaunchBackup launch = new LaunchBackup(repoConfFile, home, confFile); + + //We need to shutdown properly the repository whatever happens + try { + //Launch backup + if (isBackup) { + launch.backup(h); + } + //Launch restore + else if (isRestore) { + launch.restore(h); + } + //Launch nothing (if nothing specified + else { + usage(); + } + } + finally + { + launch.shutdown(); + } + } + + + + /** + * Auxiliary method for main + * + */ + private static void usage(){ + System.out.println("todo: cut and paste of the comment when the project is over"); + System.exit(0); + } + + /** + * Constructor of LaunchBackup. Initiate the repository. + * + * @param String filename: name of the configuration file + * @throws RepositoryException + * @throws FileNotFoundException + */ + public LaunchBackup(String repoConfFile, String home, String backupConfFile) throws RepositoryException, FileNotFoundException { + //Launch first the repository + this.repoConf = RepositoryConfig.create(repoConfFile, home); + this.repo = RepositoryImpl.create(this.repoConf); + + //Create the backupConfig object + FileReader fr = new FileReader(backupConfFile); + InputSource xml = new InputSource(fr); + this.conf = BackupConfig.create(xml); + this.backup = RepositoryBackup.create(this.conf); + } + + /** + * Backup a repository + * + * @param BackupIOHandler h a reference wher to backup + */ + public void backup(BackupIOHandler h) throws AccessDeniedException, RepositoryException, IOException { + this.backup.backup(h); + } + + /** + *Restore a repository + * + * @param BackupIOHandler h a reference to the backup to restore + */ + public void restore(BackupIOHandler h) { + this.backup.restore(h); + } + + private void shutdown() { + this.repo.shutdown(); + } + +} Index: /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java =================================================================== --- /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java (revision 0) +++ /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java (revision 0) @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.jackrabbit.backup; + + +import org.apache.jackrabbit.core.RepositoryImpl; + +/** + * @author ntoper + * + */ +public class RepositoryBackup extends Backup { + + public RepositoryBackup(RepositoryImpl repo, BackupConfig conf) { + super(repo, conf); + // TODO Auto-generated constructor stub + } + +// @Override + public void backup(BackupIOHandler out, BackupConfig conf) { + // TODO Auto-generated method stub + } + +// @Override + public void restore(BackupIOHandler in) { + // TODO Auto-generated method stub + + } + + public static RepositoryBackup create(BackupConfig conf2) { + // TODO Auto-generated method stub + return null; + } + + public void backup(BackupIOHandler out) { + // TODO Auto-generated method stub + + } + +} Index: /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java =================================================================== --- /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java (revision 0) +++ /home/ntoper/workspace/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java (revision 0) @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.jackrabbit.backup; + +public class ZipFileBackupIOHandler implements BackupIOHandler { + + int maxFileSize; + + public ZipFileBackupIOHandler(String zipFile) { + // TODO Auto-generated constructor stub + } + + public void setMaxFileSize(int i) { + this.maxFileSize = i; + } + + public int getMaxFileSize() { + return this.maxFileSize; + } + +}