308 |
308 |
}
|
309 |
309 |
|
310 |
310 |
/**
|
|
311 |
* Gets the stored backup location. This location is held in a file at
|
|
312 |
* <user_home>/.<application_context>/backup-location
|
|
313 |
*
|
|
314 |
* @return a string holding the backup location. Null if none could be found.
|
|
315 |
*/
|
|
316 |
public static String getStoredBackupDir() throws UtilException {
|
|
317 |
String applicationContext = null;
|
|
318 |
try {
|
|
319 |
applicationContext = ServiceService.getRealApplicationContext();
|
|
320 |
// Check if there is a file at
|
|
321 |
// <user_home>/<application_context>/backup-location. If so, it
|
|
322 |
// should contain one line that is a file that points to a writable
|
|
323 |
// directory. If that is true, use that value as the backup dir.
|
|
324 |
String storedBackupFileLoc = getUserHomeDir() + FileUtil.getFS() + "."
|
|
325 |
+ applicationContext + FileUtil.getFS() + "backup-location";
|
|
326 |
if (FileUtil.getFileStatus(storedBackupFileLoc) >= FileUtil.EXISTS_READABLE) {
|
|
327 |
String storedBackupDirLoc = FileUtil
|
|
328 |
.readFileToString(storedBackupFileLoc);
|
|
329 |
if (FileUtil.isDirectory(storedBackupDirLoc)
|
|
330 |
&& FileUtil.getFileStatus(storedBackupDirLoc) > FileUtil.EXISTS_READABLE) {
|
|
331 |
return storedBackupDirLoc;
|
|
332 |
}
|
|
333 |
}
|
|
334 |
} catch (IOException ioe) {
|
|
335 |
logMetacat.warn("I/O problem finding backup location: " + ioe.getMessage());
|
|
336 |
} catch (ServiceException se) {
|
|
337 |
logMetacat.warn("Could not get real application context: " + se.getMessage());
|
|
338 |
}
|
|
339 |
return null;
|
|
340 |
}
|
|
341 |
|
|
342 |
public static void writeStoredBackupFile(String backupPath) throws UtilException {
|
|
343 |
String applicationContext = null;
|
|
344 |
try {
|
|
345 |
applicationContext = ServiceService.getRealApplicationContext();
|
|
346 |
// Write the backup path to
|
|
347 |
// <user_home>/.<application_context>/backup-location.
|
|
348 |
String storedBackupFileDir = getUserHomeDir() + FileUtil.getFS() + "." + applicationContext;
|
|
349 |
String storedBackupFileLoc = storedBackupFileDir + FileUtil.getFS() + "backup-location";
|
|
350 |
if (!FileUtil.isDirectory(storedBackupFileDir)) {
|
|
351 |
FileUtil.createDirectory(storedBackupFileDir);
|
|
352 |
}
|
|
353 |
if (FileUtil.getFileStatus(storedBackupFileLoc) == FileUtil.DOES_NOT_EXIST) {
|
|
354 |
FileUtil.createFile(storedBackupFileLoc);
|
|
355 |
}
|
|
356 |
if (FileUtil.getFileStatus(storedBackupFileLoc) < FileUtil.EXISTS_READ_WRITABLE) {
|
|
357 |
throw new UtilException("Stored backup location file is not writable: " + storedBackupFileLoc);
|
|
358 |
}
|
|
359 |
|
|
360 |
FileUtil.writeFile(storedBackupFileLoc, backupPath);
|
|
361 |
|
|
362 |
} catch (IOException ioe) {
|
|
363 |
logMetacat.warn("I/O proplem finding backup location: " + ioe.getMessage());
|
|
364 |
} catch (ServiceException se) {
|
|
365 |
logMetacat.warn("Could not get real application context: " + se.getMessage());
|
|
366 |
}
|
|
367 |
}
|
|
368 |
|
|
369 |
/**
|
311 |
370 |
* Attempt to discover the external (to the metacat installation)
|
312 |
371 |
* directory where metacat will hold backup files. This functionality
|
313 |
372 |
* is used to populate the configuration utility initially. The user
|
... | ... | |
315 |
374 |
* to give you the actual directory. Here are the steps taken to discover
|
316 |
375 |
* the directory:
|
317 |
376 |
*
|
318 |
|
* -- 1) Look for a saved backup location file in the user home dir - Is there a file named
|
319 |
|
* <user_home>/metacat/.<application_context>/backup-location for the user that started
|
320 |
|
* tomcat? if so, does it contain a single line which is a readable directory? This
|
321 |
|
* directory was the backup directory used during a previous install. Return that directory.
|
322 |
|
* -- 2) Otherwise, look for an existing hidden (.<application_context>) directory in a default system directory. Get
|
|
377 |
* -- 1) Look for an existing hidden (.<application_context>) directory in a default system directory. Get
|
323 |
378 |
* the default base directory for the OS. (See application.windowsBackupBaseDir and
|
324 |
379 |
* application.linuxBackupBaseDir in metacat.properties.) If a directory called
|
325 |
380 |
* <base_dir>/metacat/.<application_context> exists, return <base_dir>/metacat.
|
326 |
|
* -- 3) Otherwise, look for an existing hidden (.metacat) directory in the user directory. If a directory
|
|
381 |
* -- 2) Otherwise, look for an existing hidden (.metacat) directory in the user directory. If a directory
|
327 |
382 |
* called <user_dir>/metacat/.<application_context> exists for the user that started tomcat,
|
328 |
383 |
* return <user_dir>/metacat.
|
329 |
|
* -- 4) Otherwise, look for an existing metacat directory in a default system directory. Get
|
|
384 |
* -- 3) Otherwise, look for an existing metacat directory in a default system directory. Get
|
330 |
385 |
* the default base directory for the OS. (See application.windowsBackupBaseDir and
|
331 |
386 |
* application.linuxBackupBaseDir in metacat.properties.) If a directory called
|
332 |
387 |
* <base_dir>/metacat exists, return <base_dir>/metacat.
|
333 |
|
* -- 5) Otherwise, look for an existing metacat directory in the user directory. If a directory
|
|
388 |
* -- 4) Otherwise, look for an existing metacat directory in the user directory. If a directory
|
334 |
389 |
* called <user_dir>/metacat/ exists for the user that started tomcat, return <user_dir>/metacat.
|
335 |
|
* -- 6) Otherwise, is the <base_dir> writable by the user that started tomcat? If so, return
|
|
390 |
* -- 5) Otherwise, is the <base_dir> writable by the user that started tomcat? If so, return
|
336 |
391 |
* <base_dir>/metacat
|
337 |
|
* -- 7) Does the <user_home> exist? If so, return <user_home>/metacat
|
338 |
|
* -- 8) Otherwise, return null
|
|
392 |
* -- 6) Does the <user_home> exist? If so, return <user_home>/metacat
|
|
393 |
* -- 7) Otherwise, return null
|
339 |
394 |
*
|
340 |
395 |
* @return a string holding the backup directory path
|
341 |
396 |
*/
|
... | ... | |
344 |
399 |
|
345 |
400 |
try {
|
346 |
401 |
applicationContext = ServiceService.getRealApplicationContext();
|
347 |
|
// Check if there is a file at <user_home>/<application_context>/backup-location. If so, it
|
348 |
|
// should contain one line that is a file that points to a writable directory.
|
349 |
|
// If that is true, use that value as the external dir.
|
350 |
|
String storedBackupFileLoc = getUserHomeDir() + FileUtil.getFS() + "." + applicationContext
|
351 |
|
+ FileUtil.getFS() + "backup-location";
|
352 |
|
if (FileUtil.getFileStatus(storedBackupFileLoc) >= FileUtil.EXISTS_READABLE) {
|
353 |
|
String storedBackupDirLoc = FileUtil.readFileToString(storedBackupFileLoc);
|
354 |
|
if (FileUtil.isDirectory(storedBackupDirLoc)
|
355 |
|
&& FileUtil.getFileStatus(storedBackupDirLoc) > FileUtil.EXISTS_READABLE) {
|
356 |
|
return storedBackupDirLoc;
|
357 |
|
}
|
358 |
|
}
|
359 |
402 |
|
360 |
403 |
// Set the default location using the os
|
361 |
404 |
String systemDir = "";
|
Separate the concept of a backup file location and a metacat external directory location. These can be totally different.