From version < 2.1 >
edited by Guido Kracke
on 2019/08/23 10:54
To version < 3.1
edited by Guido Kracke
on 2019/08/23 10:59
<
Change comment: There is no comment for this version

Summary

Details

ExtensionCode.ExtensionClass[0]
Description
... ... @@ -1,4 +1,4 @@
1 -You have to adapt the variables ##exclude##, ##include## and ##backupPath## to your needs
1 +You have to adapt the variables ##exclude##, ##include##, ##backupFile## and ##backupPath## to your needs
2 2  
3 3  {{code}}
4 4  {{groovy}}
... ... @@ -21,7 +21,8 @@
21 21  
22 22  ArrayList<String> exclude = ["Help", "Menu", "XWiki", "Sandbox", "ScriptingDocumentation"]
23 23  ArrayList<String> include = ["XWiki.DefaultSkin"]
24 -String backupPath = "C:/Robo/backups/Robo"
24 +String backupFile = "Robo.${now}.xar"
25 +String backupPath = "C:/Robo/backups/${backupFile}"
25 25  
26 26  ArrayList<String> names = []
27 27  Document home = xwiki.getDocument("Main.WebHome")
... ... @@ -158,9 +158,9 @@
158 158   packageBackupPack: Boolean.TRUE
159 159   ]
160 160   if (request.target == "Server") {
161 - oProps["target"] = new File("${backupPath}.${now}.xar")
162 + oProps["target"] = new File(backupPath)
162 162   } else {
163 - String filename = Util.encodeURI("Robo.${now}.xar", xcontext.getContext())
164 + String filename = Util.encodeURI(backupFile, xcontext.getContext())
164 164   XWikiServletResponse response = xcontext.getResponse()
165 165   response.setContentType("application/zip")
166 166   response.setHeader("Content-disposition", "attachment; filename=${filename}")
cogSave selected top level spaces and user preferences to client or server machine.
Developed by

Guido Kracke

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

You have to adapt the variables exclude, include and backupPath to your needs

You have to adapt the variables exclude, include, backupFile and backupPath to your needs

{{groovy}}
import com.xpn.xwiki.api.Document
import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.web.XWikiServletResponse
import org.xwiki.logging.LogLevel
import org.xwiki.job.Job
import java.text.DateFormat
import java.text.SimpleDateFormat
import org.xwiki.filter.instance.input.DocumentInstanceInputProperties
import org.xwiki.filter.type.FilterStreamType
import org.xwiki.model.reference.DocumentReference
import org.xwiki.model.reference.EntityReferenceSet
import org.xwiki.model.reference.SpaceReference
import org.xwiki.model.reference.WikiReference

DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss")
String now = df.format(new Date())

ArrayList<String> exclude = ["Help", "Menu", "XWiki", "Sandbox", "ScriptingDocumentation"]
ArrayList<String> include = ["XWiki.DefaultSkin"]
String backupPath = "C:/Robo/backups/Robo"

ArrayList<String> names = []
Document home = xwiki.getDocument("Main.WebHome")
for (name in home.getChildren()) {
    name = name.tokenize(".")[0]
   if (!exclude.contains(name)) {
        names << name
    }
}
names.sort().unique()
names += include
ArrayList<String> users = []
Document wiki = xwiki.getDocument("XWiki.XWikiUsers")
for (user in wiki.getChildren()) {
    users << user
}
users.sort()
names += users
String[] selectedNames = request.getParameterValues("pages")

StringBuffer out = new StringBuffer()
out << """
(
% class="row" %)
(((
(
% class="col-md-4" %)
(((
{{html}}

  

    
      
        
          
          
        
        
          
          
        
        
          
          
        
      
    
Pages
            
          
Target
            
          
History
            
          

    
  



{{/html}}

)))
(
% class="col-md-4" %)
(((

"""

String base = xcontext.URLFactory.getServerURL(xcontext.context)
for (name in names) {
    String url = "${base}/xwiki/bin/export/${name}/WebHome/?format=xar&name=${name}.${now}&pages=xwiki%3A${name}%25&history=true&backup=true"
    out << "\n[[Download ${name}>>${url}]]"
}
out << """
)))
)))


"""

if (selectedNames != null) {
    EntityReferenceSet entities = new EntityReferenceSet()
   for (name in selectedNames) {
       int index = name.lastIndexOf(".")
       if (index == -1) {
            entities.includes(new SpaceReference(name, new WikiReference("xwiki")))
        } else {
            String space = name.substring(0, index)
            String page = name.substring(index + 1)
            entities.includes(new DocumentReference("xwiki", space, page))
        }
    }
    DocumentInstanceInputProperties iProps = new DocumentInstanceInputProperties()
    iProps.setEntities(entities)
    iProps.setVerbose(true)
   if (request.history == "Include") {
      iProps.setWithJRCSRevisions(true)
    } else {
      iProps.setWithJRCSRevisions(false)
    }
    iProps.setWithRevisions(false)
    Map oProps = [
            packageBackupPack: Boolean.TRUE
    ]
   if (request.target == "Server") {
        oProps["target"] = new File("${backupPath}.${now}.xar")
    } else {
        String filename = Util.encodeURI("Robo.${now}.xar", xcontext.getContext())
        XWikiServletResponse response = xcontext.getResponse()
        response.setContentType("application/zip")
        response.setHeader("Content-disposition", "attachment; filename=${filename}")
        oProps["target"] = response.getOutputStream()
    }
    Job job = services.filter.instance.startExport(FilterStreamType.XWIKI_XAR_CURRENT, oProps, iProps)
    job.join()
   for (event in job.getStatus().getLog().getLogsFrom(LogLevel.DEBUG)) {
        out << "{{{$event}}}" << "\n"
    }
}

print out.toString()
{{/groovy}}
{{groovy}}
import com.xpn.xwiki.api.Document
import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.web.XWikiServletResponse
import org.xwiki.logging.LogLevel
import org.xwiki.job.Job
import java.text.DateFormat
import java.text.SimpleDateFormat
import org.xwiki.filter.instance.input.DocumentInstanceInputProperties
import org.xwiki.filter.type.FilterStreamType
import org.xwiki.model.reference.DocumentReference
import org.xwiki.model.reference.EntityReferenceSet
import org.xwiki.model.reference.SpaceReference
import org.xwiki.model.reference.WikiReference

DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss")
String now = df.format(new Date())

ArrayList<String> exclude = ["Help", "Menu", "XWiki", "Sandbox", "ScriptingDocumentation"]
ArrayList<String> include = ["XWiki.DefaultSkin"]
String backupFile = "Robo.${now}.xar"
String backupPath = "C:/Robo/backups/${backupFile}"

ArrayList<String> names = []
Document home = xwiki.getDocument("Main.WebHome")
for (name in home.getChildren()) {
    name = name.tokenize(".")[0]
   if (!exclude.contains(name)) {
        names << name
    }
}
names.sort().unique()
names += include
ArrayList<String> users = []
Document wiki = xwiki.getDocument("XWiki.XWikiUsers")
for (user in wiki.getChildren()) {
    users << user
}
users.sort()
names += users
String[] selectedNames = request.getParameterValues("pages")

StringBuffer out = new StringBuffer()
out << """
(
% class="row" %)
(((
(
% class="col-md-4" %)
(((
{{html}}

  

    
      
        
          
          
        
        
          
          
        
        
          
          
        
      
    
Pages
            
          
Target
            
          
History
            
          

    
  



{{/html}}

)))
(
% class="col-md-4" %)
(((

"""

String base = xcontext.URLFactory.getServerURL(xcontext.context)
for (name in names) {
    String url = "${base}/xwiki/bin/export/${name}/WebHome/?format=xar&name=${name}.${now}&pages=xwiki%3A${name}%25&history=true&backup=true"
    out << "\n[[Download ${name}>>${url}]]"
}
out << """
)))
)))


"""

if (selectedNames != null) {
    EntityReferenceSet entities = new EntityReferenceSet()
   for (name in selectedNames) {
       int index = name.lastIndexOf(".")
       if (index == -1) {
            entities.includes(new SpaceReference(name, new WikiReference("xwiki")))
        } else {
            String space = name.substring(0, index)
            String page = name.substring(index + 1)
            entities.includes(new DocumentReference("xwiki", space, page))
        }
    }
    DocumentInstanceInputProperties iProps = new DocumentInstanceInputProperties()
    iProps.setEntities(entities)
    iProps.setVerbose(true)
   if (request.history == "Include") {
      iProps.setWithJRCSRevisions(true)
    } else {
      iProps.setWithJRCSRevisions(false)
    }
    iProps.setWithRevisions(false)
    Map oProps = [
            packageBackupPack: Boolean.TRUE
    ]
   if (request.target == "Server") {
        oProps["target"] = new File(backupPath)
    } else {
        String filename = Util.encodeURI(backupFile, xcontext.getContext())
        XWikiServletResponse response = xcontext.getResponse()
        response.setContentType("application/zip")
        response.setHeader("Content-disposition", "attachment; filename=${filename}")
        oProps["target"] = response.getOutputStream()
    }
    Job job = services.filter.instance.startExport(FilterStreamType.XWIKI_XAR_CURRENT, oProps, iProps)
    job.join()
   for (event in job.getStatus().getLog().getLogsFrom(LogLevel.DEBUG)) {
        out << "{{{$event}}}" << "\n"
    }
}

print out.toString()
{{/groovy}}

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Get Connected