public Response backupRepository ( ServletContext context , HttpServletRequest request , String repositoryName , BackupOptions options ) throws RepositoryException { final File backupLocation = resolveBackupLocation ( context ) ; Session session = getSession ( request , repositoryName , null ) ; String repositoryVersion = session . getRepository ( ) . getDescriptorValue ( Repository . REP_VERSION_DESC ) . getString ( ) . replaceAll ( "\\." , "" ) ; final String backupName = "modeshape_" + repositoryVersion + "_" + repositoryName + "_backup_" + DATE_FORMAT . format ( new Date ( ) ) ; final File backup = new File ( backupLocation , backupName ) ; if ( ! backup . mkdirs ( ) ) { throw new RuntimeException ( "Cannot create backup folder: " + backup ) ; } logger . debug ( "Backing up repository '{0}' to '{1}', using '{2}'" , repositoryName , backup , options ) ; RepositoryManager repositoryManager = ( ( org . modeshape . jcr . api . Workspace ) session . getWorkspace ( ) ) . getRepositoryManager ( ) ; repositoryManager . backupRepository ( backup , options ) ; final String backupURL ; try { backupURL = backup . toURI ( ) . toURL ( ) . toString ( ) ; } catch ( MalformedURLException e ) { //should never happen throw new RuntimeException ( e ) ; } JSONAble responseContent = new JSONAble ( ) { @ Override public JSONObject toJSON ( ) throws JSONException { JSONObject object = new JSONObject ( ) ; object . put ( "name" , backupName ) ; object . put ( "url" , backupURL ) ; return object ; } } ; return Response . status ( Response . Status . CREATED ) . entity ( responseContent ) . build ( ) ; }
Performs a repository backup .