1 40 package org.dspace.storage.bitstore; 41 42 import org.apache.commons.cli.CommandLine; 43 import org.apache.commons.cli.CommandLineParser; 44 import org.apache.commons.cli.HelpFormatter; 45 import org.apache.commons.cli.Options; 46 import org.apache.commons.cli.ParseException; 47 import org.apache.commons.cli.PosixParser; 48 49 import org.apache.log4j.Logger; 50 51 57 public class Cleanup 58 { 59 60 private static Logger log = Logger.getLogger(Cleanup.class); 61 62 68 public static void main(String [] argv) 69 { 70 try 71 { 72 log.info("Cleaning up asset store"); 73 74 CommandLineParser parser = new PosixParser(); 76 CommandLine line = null; 77 78 Options options = new Options(); 80 81 options.addOption("l", "leave", false, "Leave database records but delete file from assetstore"); 82 options.addOption("h", "help", false, "Help"); 83 84 try 85 { 86 line = parser.parse(options, argv); 87 } 88 catch (ParseException e) 89 { 90 log.fatal(e); 91 System.exit(1); 92 } 93 94 if (line.hasOption('h')) 96 { 97 printHelp(options); 98 System.exit(0); 99 } 100 101 boolean deleteDbRecords = true; 102 if (line.hasOption('l')) 104 { 105 log.debug("option l used setting flag to leave db records"); 106 deleteDbRecords = false; 107 } 108 log.debug("leave db records = " + deleteDbRecords); 109 BitstreamStorageManager.cleanup(deleteDbRecords); 110 111 System.exit(0); 112 } 113 catch (Exception e) 114 { 115 log.fatal("Caught exception:", e); 116 System.exit(1); 117 } 118 } 119 120 private static void printHelp(Options options) 121 { 122 HelpFormatter myhelp = new HelpFormatter(); 123 myhelp.printHelp("Cleanup\n", options); 124 } 125 126 } 127 | Popular Tags |