Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 90359 invoked from network); 15 Jul 2006 22:38:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 15 Jul 2006 22:38:10 -0000 Received: (qmail 62587 invoked by uid 500); 15 Jul 2006 22:38:10 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 62560 invoked by uid 500); 15 Jul 2006 22:38:10 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 62548 invoked by uid 99); 15 Jul 2006 22:38:10 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 15 Jul 2006 15:38:10 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 15 Jul 2006 15:38:09 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 266961A981A; Sat, 15 Jul 2006 15:37:43 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r422307 - in /jackrabbit/trunk/contrib/backup/src/main/java/org: ./ apache/ apache/jackrabbit/ apache/jackrabbit/backup/ Date: Sat, 15 Jul 2006 22:37:42 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060715223743.266961A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jukka Date: Sat Jul 15 15:37:41 2006 New Revision: 422307 URL: http://svn.apache.org/viewvc?rev=422307&view=rev Log: JCR-442: Applied Nicolas' patch (patch.txt [12336687]) to add the backup classes to contib/backup. Needed to make a few small changes to make it compile. Added: jackrabbit/trunk/contrib/backup/src/main/java/org/ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java (with props) jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java (with props) jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java (with props) jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java (with props) jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java (with props) jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java (with props) Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java?rev=422307&view=auto ============================================================================== --- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java (added) +++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java Sat Jul 15 15:37:41 2006 @@ -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); + + + +} Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java?rev=422307&view=auto ============================================================================== --- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java (added) +++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java Sat Jul 15 15:37:41 2006 @@ -0,0 +1,141 @@ +/* + * 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, String home) + throws ConfigurationException { + Properties variables = new Properties(); + variables.setProperty( + ConfigurationParser.REPOSITORY_HOME_VARIABLE, home); + ConfigurationParser parser = new ConfigurationParser(variables); + + // TODO: Fix this + // BackupConfig config = parser.parseBackupConfig(xml); + // config.init(); + // return config; + return null; + } + + + 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 + } + +} Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java?rev=422307&view=auto ============================================================================== --- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java (added) +++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java Sat Jul 15 15:37:41 2006 @@ -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? + +} Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java?rev=422307&view=auto ============================================================================== --- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java (added) +++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java Sat Jul 15 15:37:41 2006 @@ -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, home); + 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(); + } + +} Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java?rev=422307&view=auto ============================================================================== --- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java (added) +++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java Sat Jul 15 15:37:41 2006 @@ -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 + + } + +} Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java?rev=422307&view=auto ============================================================================== --- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java (added) +++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java Sat Jul 15 15:37:41 2006 @@ -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; + } + +} Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java ------------------------------------------------------------------------------ svn:eol-style = native