1 6 7 package com.sun.enterprise.config.backup.appserver; 8 9 import com.sun.enterprise.config.backup.status.StatusConstants; 10 import com.sun.enterprise.config.backup.*; 11 import com.sun.enterprise.config.backup.status.*; 12 import com.sun.enterprise.config.backup.EnvironmentConstants; 13 import com.sun.enterprise.config.backup.BackupRequest; 14 import com.sun.enterprise.config.backup.utils.SystemPropsHelper; 15 16 22 public class Main { 23 private static final int HISTORY_NUMBER = 6; 24 25 26 public Main() { 27 } 28 29 public static void main(String [] args) 30 { 31 entry(args); 32 } 33 34 public static void entry(BackupRequest br) 36 { 37 br.verify(); 38 String [] dirs = br.getDirsToBackup(); 39 String allDirs = dirs[0]; 40 41 for(int i = 1; i < dirs.length; i++) 42 allDirs += ',' + dirs[i]; 43 44 SystemPropsHelper.setProperty(EnvironmentConstants.DIRS_TO_BACKUP, allDirs); 45 SystemPropsHelper.setProperty(EnvironmentConstants.DIR_TO_STORE_BACKUP_FILES, br.getDirToStoreBackupFiles()); 46 SystemPropsHelper.setProperty(EnvironmentConstants.BACKUP_STORAGE_TYPE, br.getBackupStorageType()); 47 48 try 49 { 50 BackupRestore bri = Util.getBackupRestore(); 51 Status s = bri.backup(null); 52 System.out.println("=================="); 53 printStatus(s); 54 System.out.println("=================="); 55 System.out.println(s.getExtraInfo()); 56 System.out.println("=================="); 57 } 58 catch(Exception e) 59 { 60 e.printStackTrace(); 61 } 62 } 63 64 67 private static void entry(String [] args) { 68 try { 69 if(args == null || args.length <1 || args[0] == null || "".equals(args[0])) { 70 usage(); 71 return; 72 } 73 74 System.setProperty(EnvironmentConstants.DIRS_TO_BACKUP, "C:/tmp/tmp/tmp"); 75 System.setProperty(EnvironmentConstants.DIR_TO_STORE_BACKUP_FILES, "C:/temp/backup"); 76 System.setProperty(EnvironmentConstants.BACKUP_STORAGE_TYPE, "directory"); 77 BackupRestore bri = Util.getBackupRestore(); 79 Status s = null; 80 if("backup".equals(args[0])) { 81 String userInfo = null; 82 if(args.length == 1) { s = bri.backup(null); 84 } else if(args.length == 2) { System.out.println("info=" + args[1]); 86 s = bri.backup(args[1]); 87 } else if(args.length == 3) { 88 s = bri.backup(args[1], args[2]); 89 } else { 90 usage(); 91 return; 92 } 93 } else if ("restore".equals(args[0])) { 94 s = bri.restore(); 95 } else if("undorestore".equals(args[0])) { 96 s = bri.undoRestore(); 97 } else if("listbackups".equals(args[0])) { 98 BackupStatus[] bs = bri.listBackups(); 99 System.out.println("=================="); 100 101 printBackupStatus(bs); 102 System.out.println("=================="); 103 104 return; 105 } else if("listhistory".equals(args[0])) { 106 int n=HISTORY_NUMBER; 107 if(args.length==2) { n = getHistoryNumber(args[1]); 109 } 110 BackupHistory bh = bri.getBackupHistory(n); 111 System.out.println("=================="); 112 113 System.out.println(bh); 115 System.out.println("=================="); 116 117 return; 118 } else { 119 System.out.println("sub-command invalid"); 120 usage(); 121 return; 122 } 123 System.out.println("=================="); 124 printStatus(s); 125 System.out.println("=================="); 126 System.out.println(s.getExtraInfo()); 127 System.out.println("=================="); 128 129 131 133 135 } catch(Exception e){ 136 e.printStackTrace(); 137 } 138 139 } 140 141 private static void printBackupStatus(BackupStatus[] bs) { 142 if (bs == null || bs.length == 0) { 143 System.out.println("There are no Backups"); 144 } 145 System.out.println("Available Backups are:"); 146 for (int i = 0 ; i < bs.length; i ++) { 147 System.out.println(bs[i]); 148 } 149 } 150 private static void printStatus(Status s) { 151 System.out.println(s); 152 } 153 154 private static void usage() { 155 System.out.println("Usage: \n" + 156 "asbackup backup <userInfo>\n" + 157 "asbackup backup absoluteFileName userInfo\n" + 158 "asbackup restore \n" + 159 "asbackup undorestore \n" + 160 "asbackup listbackups \n" + 161 "asbackup listhistory <numberOfHistories>"); 162 } 163 164 private static int getHistoryNumber(String arg) { 165 try { 166 return new Integer (arg).intValue(); 167 } catch(Exception e) { 168 return HISTORY_NUMBER; 169 } 170 } 171 } 172 | Popular Tags |